I was quite impressed with myself the other day that I’d actually managed to write a bash script within ubuntu which served a purpose. I wanted to be able to monitor the size of files within a particular directory, and report back their size when a change was observed.
I found a program called fileschanged, which fulfilled half the problem, namely reporting back a file had changed, but I needed a greater level of detail than that. What it did allow me to do however was pass the filename as an argument (along with some other parameter) to another program. I duely spent an hour or so trying to figure out a script to take that filename and report back its filesize and the current time (which I assume is close enough to that which the file was changed). This is what it looks like:
#!/bin/bash if [ -z "$1" ] && [ -z "$2" ]; then exit fi FN=$2 DATE=$(date +%s) FILESIZE=$(stat -c%s "$FN") echo "$DATE,$FN,$FILESIZE"