Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
script disk space
Name: David Date: June 2, 2003 at 03:40:12 Pacific OS: Solaris CPU/Ram: 1gig
Comment:
Does anyone have a script that will check disk space and if above say 95% will email me the relative disk information using cron?
Name: David Perry Date: June 2, 2003 at 04:24:46 Pacific
Reply:
Flavor to suit.
#!/bin/ksh rm /tmp/dfk.txt echo "df -k output for `date` `uname -a`" > /tmp/dfk.txt i=1 while [ $i -le `df -k | grep -v proc | grep -v Capacity | wc -l` ] ;do if [ `df -k | grep -v proc | grep -v Capacity | head -n $i | tail -1 | awk '{print $5}' | sed -e 's/%//'` -gt 90 ] ; then df -k | grep -v proc | grep -v Capacity | head -n $i | tail -1 >> /tmp/dfk.txt fi ((i=i+1)) done if [ `cat /tmp/dfk.txt | wc -l` -gt 1 ] ; then cat /tmp/dfk.txt | mail user@host.com fi
0
Response Number 2
Name: David Perry Date: June 3, 2003 at 05:08:47 Pacific
Reply:
I like this one better.
#!/bin/ksh cp /dev/null /tmp/df.out case `uname -s` in SunOS ) set -- `df -k | sed -e 's/%//g' | awk '/^\/dev/ { printf("%s %s\n", $5, $6) }'` ;; HP-UX ) set -- `bdf | sed -e 's/%//g' | awk '/^\/dev/ { printf("%s %s\n", $5, $6) }'` ;; esac
while [ $# -ge 2 ] ; do CAPACITY=$1 FS=$2 shift 2
if [ $CAPACITY -gt 90 ] ; then echo "$FS is at $CAPACITY %" >> /tmp/df.out fi done if [ `wc -l /tmp/df.out | awk '{ print $1 }'` -ge 1 ] ; then cat /tmp/df.out | mail user@host.com fi
Summary: Well, I have a fairly complicated sed script which performs necessary reformatting of the file(s) prior to delivery to other parts of the system. We have tried implementing this using awk and PL/SQL (...