A new admin script

I have 24 filesystems (counting external devices with dedicated mount points) that could be mounted at any given time.  Rather than manually checking the /lost+found directory on each one after mounting, I wrote a script that I can call to do it for me:

# checks for files in lost+found directories

ALERT=`find / -type d -name 'lost+found' -not -empty -print 2>/dev/null`
LINES=`echo $ALERT | wc -l`

if [ $LINES > 0 ]
        for dir in $ALERT
                mail -s "$dir not empty!" root <<EOF
* $dir is not empty at `date`          *

`ls -l $dir`

Please take care of these files.



This runs automatically when the system boots after all the filesystems listed as auto in /etc/fstab have been mounted.  I can run it manually (from /root/scripts/) when I mount an external device.  I’ve added it to the backup script so that it checks for files in /media/usb/lost+found before dumping data to the external USB drive.

  1. #1 by aakashmishra on December 26, 2009 - 1:18 PM

    Hi, Can you tell me how i redirect the out of ll | grep ” in to tar command. Actually my objective is that I am in a directory in which lots of reports are generated. I need to tar all the reports of everyday.I am doing following but not working…
    # ll | grep ‘Dec 26’ >> tar -czf Reports.tgz

    Can you help..?

    • #2 by Joshua on December 27, 2009 - 8:38 AM

      Instead of >> use | both times.

  2. #3 by Joshua on December 28, 2009 - 7:18 AM

    I think he’s actually trying to make tarballs out of the reports. The line he’s using, with ll (I think that’s an alias for ls -l) will only make a tarball out of the list of file names – not the files themselves. What he probably wants is tar czf Reports.tgz *Dec\ 26*

  3. #4 by Joshua on December 12, 2010 - 10:20 AM

    Update – added sourcecode tags.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: