Easy to extend one-liner for cron scripts that automate filesystem checking

( di $TOFSCK -h ; /bin/umount $TOFSCK ; time /sbin/e2fsck -y -f -v $FSCKDEV ; /bin/mount $TOFSCK ) |& /bin/mail $MAILTO -s "$MAILSUB"
This one-liner is for cron jobs that need to provide some basic information about a filesystem and the time it takes to complete the operation. You can swap out the di command for df or du if that's your thing. The |& redirections the stderr and stdout to the mail command. How to configure the variables. TOFSCK=/path/to/mount FSCKDEV=/dev/path/device or FSCKDEV=`grep $TOFSCK /proc/mounts | cut -f1 -d" "` MAILSUB="weekly file system check $TOFSCK "
Sample Output
Filesystem         Mount               Size     Used    Avail %Used fs Type
/dev/mapper/Archiv /srv/Music        108.3G    83.2G    21.8G  80%  ext3   
e2fsck 1.41.12 (17-May-2010)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information

   24809 inodes used (0.34%)
    1835 non-contiguous files (7.4%)
      15 non-contiguous directories (0.1%)
         # of inodes with ind/dind/tind blocks: 9273/5718/0
22256269 blocks used (77.18%)
       0 bad blocks
       1 large file

   20110 regular files
    4690 directories
       0 character device files
       0 block device files
       0 fifos
       0 links
       0 symbolic links (0 fast symbolic links)
       0 sockets
--------
   24800 files

real	3m31.842s
user	0m13.897s
sys	0m8.977s

What Others Think

Excellent Command...
programmingzeal · 267 weeks ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: