Script to Limit Number of Files in a Directory

I have some jobs that run and will fill up disk drives if not pruned.

I put together the simple script below that I can call with a directory and the number of files I want to keep. The oldest files will be deleted. I add it to cron jobs with a command in this pattern:

~/DelOverNumberFiles.sh ~/public_html/FrontDoor/Camera\ 01 200
Note: there are 2 params, the \ escapes the space before the 01
Copy into DelOverNumberFiles.sh

#!/bin/bash

limit=$2
dir=$1
Cnt=0
for line in `ls -t "$1"`
do
  if [[ $Cnt -gt $limit ]]
  then
    rm "$dir/$line"
    echo "rm $dir/$line"
  fi
  Cnt=`expr $Cnt + 1`
done

While I know this is not the most professional way to do this, I wanted something very simple I could play with and should have few dependencies so I could use it on shared servers that I do not have control over.

Posted in Uncategorized | Leave a comment

Lessons Running IP Security Cameras Off Grid

On a small off grid hobby ranch, running IP cameras to keep an eye on things proved a bit trickier then planned. Durning the summer the solar panels produce enough power to run a well, a data logger, a camera and a cell modem to send data once an hour.

In the winter however, the shorter days, lower sun angle and rainy, cloudy days dramatically reduce the power produced. The well system is designed to only run when enough power is available, but the data logger and camera run 24/7 and can run down the batteries and cause a system shutdown after a string of cloudy days.

In looking over where power was being consumed, an IP camera running on PoE (Power over Ethernet) from a PoE switch was consuming 10 watts 24/7 and pushing the system over the edge. So I set out to measure the different ways the camera could be powered and see if the consumption could be reduced. Below are my measurements:

Camera: HikVision DS-2CD2032F-I, Switch: TP-Link TL-SF1008P
PoE switch only 2Watts
Switch & 1 camera day (IR LEDs off) 6W
Switch & 2 cameras day 9W
Switch & 2 cameras 1 day, 1 night (IR LEDs on) 11W
Switch & 2 cameras night 13W
1 camera running on 12V power plug day 2W
1 camera running on 12V power plug night 3.3W
Non-PoE Switch TRENDnet TEG-S80g running on 5V DC (not on 120VAC wall wart)
No ports on .85W
1 port active 100Mbps .9W
2 ports active 1-100Mbps, 1-1Gbps 1.2W
3 ports active 2-100Mbps, 1-1Gbps 1.3W

So it looks like like the lowest power operation can be found running without PoE or AC but instead using the DC power plug, staying in day mode if possible and finding the lowest power non-PoE switch you can find. When running on-grid, these type of power differences do not amount to much. But when running on a small off-grid solar system, every watt counts.

Here is a site with lots of info on deep cycle batteries I found useful:
https://www.solar-electric.com/deep-cycle-battery-faq.html

Posted in Uncategorized | Leave a comment