Bash bash

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/bashif [ -z "$1" ] && [ -z "$2" ]; then exitfiFN=$2DATE=$(date +%s)FILESIZE=$(stat -c%s "$FN")echo "$DATE,$FN,$FILESIZE"

This entry was posted in Linux, Ubuntu. Bookmark the permalink.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">