Unix

Checking disk space

Here is a quick and dirty diskspace script:

#!/bin/bash
ALERT=70
#ssh 10.61.37.176 df -H > /tmp/df.out
df -Hl > /tmp/df.out
cat /tmp/df.out | grep -vE 'Filesystem|tmpfs|cdrom' \
   | awk '{ print $5 " " $1 " " $6 }' | \
while read output ;
do
    usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1 )
    partition=$(echo $output | awk '{ print $3 }' )
    if [ $usep -ge $ALERT ]
    then
       printf "Running out of space on partition %s \t %g \t %s %s\n" \
          $partition $usep $(hostname) $(date)
    fi
done

Notice the hard coded ALERT level as well as the commented out ssh command.

It needs work, but should show you how little space one has on all mounted drives.

Shell scripts

A good reference for Bash: http://www.math.ucdavis.edu/~zjohnson/doc/Adv-Bash-Scr-HOWTO/
How can one remember the syntax of the if command?

Getting $PATH line by line

echo $PATH | tr ':' '\n' will list the $PATH nicely.

So will this:
echo $PATH | sed "s/:/\\
> /g"

That is hitting return and getting the ">" that is not typed in.

Syndicate content