Computing.Net > Forums > Unix > Script for diskspace, A challenge

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

Script for diskspace, A challenge

Reply to Message Icon

Name: Peter Jenkins
Date: April 26, 2003 at 12:22:23 Pacific
OS: Solaris 8
CPU/Ram: Sun
Comment:

Here's a challenge.
Write a script in c shell or perl that monitors disk space and displays a message when any filesystem goes over 85%. Exclude mnttab, fd, and proc. Make the script able to be changed from the command line in order to change the monitoring value of 85% on any monitored filesystem. I've gotten about a third of the way there but can't get the script to work right past getting the percentage of each filesystem into a file. I was trying a while do loop with nawk to monitor the system but I am new to unix and haven't had much luck. Anybody with an idea would be much appreciated.




Sponsored Link
Ads by Google

Response Number 1
Name: WilliamRobertson
Date: April 26, 2003 at 12:32:13 Pacific
Reply:

Give df a try.

csh? Good luck with that. Personally I agree with this guy: www.faqs.org/faqs/unix-faq/shell/csh-whynot/


0

Response Number 2
Name: David Perry
Date: April 28, 2003 at 04:22:10 Pacific
Reply:

William is right. Unless you are working under the contraints of homework, no one uses csh for scripting because it works poorly.

#!/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 85 ] ; 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
Reply to Message Icon

Related Posts

See More


RedHat Linux Boot Disk?? dual booting unix/xp



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Script for diskspace, A challenge

A simple script for creating a link www.computing.net/answers/unix/a-simple-script-for-creating-a-link/6981.html

Unix shell script for opening a file and www.computing.net/answers/unix/unix-shell-script-for-opening-a-file-and/3452.html

Utility or script for renaming files on www.computing.net/answers/unix/utility-or-script-for-renaming-files-on-/2538.html