Filesystem alert shell script not working!!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Filesystem alert shell script not working!!
# 1  
Old 05-07-2010
Filesystem alert shell script not working!!

Hi All,

My below shell script is not capturing %used value in the filesystem alert in the subject of the mail alert:

Code:
#!/bin/bash

export DBALIST="abc@xyz.com"

df -k /oradata/xyz/archive > dfk.result
archive_capacity=`awk -F" " '{ print $5 }' dfk.result|grep -i %| cut -c 1-4`
if [[ $archive_capacity > 60% ]]
then
mailx -s "Filesystem /oradata is ${archive_capacity} filled" $DBALIST < dfk.result
fi

Existing output in the subject mail alert is:

Code:
"Filesystem /oradata is Use% filled"

Expected output in the subject mail alert should be:

Code:
"Filesystem /oradata is 61% filled"

Anyone could please suggest what's wrong here!

Thanks for your time!

Regards,

Last edited by Scott; 05-07-2010 at 06:23 PM.. Reason: Please use code tags
# 2  
Old 05-07-2010
Quote:
Originally Posted by a1_win
Code:
archive_capacity=`awk -F" " '{ print $5 }' dfk.result|grep -i %| cut -c 1-4`

Change the line above to:
Code:
archive_capacity=`grep -v File dfk.result | awk -F" " '{ print $5 }' | cut -c 1-4`

HTH
# 3  
Old 05-07-2010
If your 'df -k' command has this header, then when you search for %, it picks out the first one.

Code:
Filesystem           1K-blocks      Used Available Use% Mounted on

archive_capacity=`awk -F" " '{ print $5 }' /tmp/dfk.result`
echo $archive_capacity
archive_capacity=`echo $archive_capacity|grep -i %| cut -c 1-4`
echo $archive_capacity

Output:
Code:
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sdb1            244124256  16086488 228037768   7% /var/local
Use% 7%
Use%

Changing your cut command to this will give you the number (may have to play with this a bit)

Code:
archive_capacity=`awk -F" " '{ print $5 }' dfk.result`
echo $archive_capacity
archive_capacity=`echo $archive_capacity|grep -i %| cut -c 6-8`
echo $archive_capacity

Output:
Code:
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sdb1            244124256  16086792 228037464   7% /var/local
Use% 7%
7%


Last edited by Scott; 05-07-2010 at 06:24 PM.. Reason: Code tags
# 4  
Old 05-07-2010
better yet, skip that intermediate step of outputting to a file and then reading back in:

Code:
#!/bin/bash

export DBALIST="abc@xyz.com"

archive_readout=$(df -k /oradata/xyz/archive |egrep "^Filesystem|\%" )
archive_capacity=$(df -k /oradata/xyz/archive |awk '{ print $5 }' |grep -i % |sed 's/%//g' )
if [[ $archive_capacity > 60 ]]
then
   print ${archive_readout} |mailx -s "Filesystem /oradata is ${archive_capacity}% filled" $DBALIST 
fi

# 5  
Old 05-07-2010
interesting - since I didn't have /oradata/xyz/archive to test with, I changed it to either /var or /home. My /home is at 5% - yet the script still sent an email - the ORIGINAL script has other issues... would have mention this earlier but email was real slow!

Curleb - your changes work as far as getting the numbers right - for some reason I got errors on the print/mailx line (on Linux) - no big deal

Last edited by RTM; 05-07-2010 at 06:23 PM..
# 6  
Old 05-07-2010
Hmmm...works for me on Solaris10, ksh.

...with local filesystems too, of course...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Filesystem alert shell script not working!!

Hi All, My below shell script is not capturing %used value in the filesystem alert in the subject of the mail alert: Code: #!/bin/bash export DBALIST="abc@xyz.com" df -k /oradata/xyz/archive > dfk.result archive_capacity=`awk -F" " '{ print $5 }' dfk.result|grep -i %| cut -c 1-4` if... (6 Replies)
Discussion started by: harveyclayton
6 Replies

2. UNIX for Beginners Questions & Answers

Shell script to send mail alert

Hi I have below shell script to send mail alert , however I want to add more functionality in this script and that is , script should only check that file between 9 am to 5pm , and if there is no activity in this time 9 am to 5 pm for 2hours then it should give me mail alert, please help... (2 Replies)
Discussion started by: scazed
2 Replies

3. Shell Programming and Scripting

Shell script to send mail alert

HI Guys, I am writing one shell script to send the mail alert to some email id's if the file not modified in last 10 mins but its not working, I believe MTIME is null string is wrong . can you please assist me on this. script :- filename="abc.txt" echo "Filename is $filename"... (1 Reply)
Discussion started by: abhigrkist
1 Replies

4. Shell Programming and Scripting

Shell script for alert

Hi Experts, Im new in shell script , please help to achieve the below requirement, We have some replication setup in unix server, in that if there is any exception or error occurs immediately the rep_exception.log will have the exception detail, this log will be updated if any error occurs no... (8 Replies)
Discussion started by: pandiyan
8 Replies

5. Shell Programming and Scripting

shell script to alert if a file has been modified

Hi , I want a script who will send alert the moment someone edit any file in a directory in LINUX. Can some one throw some light on this please.!! (4 Replies)
Discussion started by: d8011
4 Replies

6. Shell Programming and Scripting

Shell script to find filesystem capacity on 50 servers

Hi all, I am new to Unix and I want to write a shell script in a jumpbox for finding the filesystem capacity on 50 unix servers ( by ssh ) and then email the result in HTML format with server name and capacity % to a specific outlook distribution list. any suggestion would be of great help. (17 Replies)
Discussion started by: amitbisht9
17 Replies

7. Shell Programming and Scripting

Unix Shell Script to automate email alert

Hi all, I have a task on my plate which is of high priority. I need an automated email alert that checks FTP notices subdirectory on a daily basis and forwards any word files to a group of people. This word files gets created whenever there is an issue with FTP connectivity. Please help...... (1 Reply)
Discussion started by: stunnerz_84
1 Replies

8. Shell Programming and Scripting

simple script to alert if internet not working?

Hi, I am constantly automaticaly downloading a few things on the internet but since my internet connection is unstable, it sometimes wont work. Thing is the internet will appear to be connected, but no website can be accessed and no program can successfully connect to any location. I can fix... (4 Replies)
Discussion started by: fuzzylogic25
4 Replies

9. Shell Programming and Scripting

shell script to mount filesystem

Hi, Gurus: I need your help to finish a script that will mount two file systems automatically when saver is reboot or start. I am working on a new Sun Sparc machine with Solaris 9 on it. This box got two disk. disk one has been partitioned to hold Solaris OS. disk two has been partitioned as... (6 Replies)
Discussion started by: duke0001
6 Replies

10. AIX

Creating a shell script to check filesystem space

I need to create a simple shell script to check filesystems space in a file system called "/arch_nb" then based on the percentage use either run another script or exit. I was thinking of something simple along the lines of: df -k | then some action to pipe for percentage used ...place... (10 Replies)
Discussion started by: heprox
10 Replies
Login or Register to Ask a Question