LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Scripting for disk usage of filesystems. (https://www.linuxquestions.org/questions/linux-newbie-8/scripting-for-disk-usage-of-filesystems-4175450181/)

theondr 02-14-2013 04:17 PM

Scripting for disk usage of filesystems.
 
Scripting
Could somebody kind of walk me through the following? What areas would one study to get a handle on what the below requirements are?

This is for disk usage.

I have had one course in Linux/Unix. I have had C programming.
Is Bash ok to use?





Create a script that sends an email message to the user specified on the command line if any of the filesystems are at more than 70% of capacity. The script should not process special filesystems as /proc . It should only process filesystems which are either locally mounted or are mounted via NFS.
An individual email should be sent for each filesystem which is at the warning level. There should be a subject on the email with a message "Warning: Filesystem <put filesystem the>here is at <X>% of capacity" If the filesystem is at greater than 90% of capacity, the "Warning" should be changed to "Critical Warning".

suicidaleggroll 02-14-2013 04:24 PM

Bash would be fine. "df" will already report the disk usage for all mounted filesystems, along with % usage. So it should just be a matter of calling df, and then parsing the output and checking for any filesystems that are >xx% usage.

Then you just need to look into how to send emails from the command line.

chrism01 02-14-2013 05:20 PM

What he said :)

If you bookmark/read these and take it slowly, it shouldn't be too hard.
http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/

If you need to automate it, you can use the cron scheduler
http://www.adminschoice.com/crontab-quick-reference

shivaa 02-14-2013 08:24 PM

You can create a script with help of below commands (just for your rederence), and schedule the same in your system's crontab.
Code:

df -h | awk -F" " '{gsub(/\%/,"",$4); if($4>=70) print $0}' > /tmp/fs_status.txt
mailx -s "File system status" abc@example.com < /tmp/fs_status.txt


theondr 02-16-2013 10:02 AM

Thanks all
 
Thanks to everyone for the reply. Now I have an idea how to approach the problem. I will respond with the result.


All times are GMT -5. The time now is 11:44 AM.