Please Help - df script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Please Help - df script
# 1  
Old 07-05-2006
Please Help - df script

I need help with a df script that I pulled from the web. This script is used to monitor disk space and email if it gets over a certain percentage (in this case, 90%). The script works, and it sends me an email, but when I test it I keep getting an output reporting:
dfalert[12]: -: 0403-053 Expression is not complete; more tokens expected.

The name of my script is "dfalert", and it's reporting a problem on line 12 of the script. Here is the code:
+1 ###################################################################
+2 #! /bin/ksh
+3 #
+4 ########################################################################################
+5 # This scripts monitors the disk space utilization and sends an email to the Admins if #
+6 # the amount of disk space for any file system reaches 90% or more. This script will #
+7 # run as an hourly cron job. #
+8 ########################################################################################
+9 #
+10 df -k |grep -iv filesystem |awk '{print $1 "\t" $4 "\t" $7}' |while read LINE; do
+11 PERC=`echo $LINE |cut -d"%" -f1 |awk '{print $2}'`
+12 if [ $PERC -gt 90 ]; then
+13 echo "The Filesystem ${LINE} on `hostname`" |mail -s "Disk Space Alert" user@host.com
+14 fi
+15 done


Any ideas as to what "tokens" I'm missing on line #12 would be greatly appreciated. Thank you in advance.

outta
# 2  
Old 07-05-2006
There are a number of errors in that script, not least of which are

1. Line 2 should be line 1, line 1 should not be there.
2. It uses sh syntax, in ksh the [ ] should really be [[ ]]
# 3  
Old 07-05-2006
Hi,
There is one more correction when you awk the output of df -k | grep -iv filesystem the $5 should extracted and not $4 as $4 will give avaliable space and not the capatcity in terms of percentage. Then this script would work fine.
Thanks
# 4  
Old 07-06-2006
Thank you for your help. . .

I have made the corrections as advised by reborg and amitkhiare. Except now I'm catching errors on the following line:
PERC=`echo $LINE |cut -d"%" -f1 | awk '{print $2}'`

The error is saying:

dfalert[10]: -: 0403-053 Expression is not complete; more tokens expected.

What am I missing?
# 5  
Old 07-06-2006
I'm not sure about the error, but you can do something like this to get your work done:
Code:
df -k | grep -iv filesystem | while read LINE; do
PERC=`echo $LINE | awk '{print $5}' | sed -e 's/%//'`

Regards,
Tayyab
# 6  
Old 07-06-2006
Thank you for your assistance. . .it's now working.
# 7  
Old 07-07-2006
Quote:
Originally Posted by reborg
2. It uses sh syntax, in ksh the [ ] should really be [[ ]]
Negatory. Modern ksh honors both - in ksh93, it is stated sometimes that "[[expr]]" is preferred, but it really makes no difference. In ksh88 and older versions of pdksh, you may run into problems. It really depends on what shell you're using.
Login or Register to Ask a Question

Previous Thread | Next Thread

5 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to block first bash script until second bash script script launches web server/site?

I'm new to utilities like socat and netcat and I'm not clear if they will do what I need. I have a "compileDeployStartWebServer.sh" script and a "StartBrowser.sh" script that are started by emacs/elisp at the same time in two different processes. I'm using Cygwin bash on Windows 10. My... (3 Replies)
Discussion started by: siegfried
3 Replies

2. Shell Programming and Scripting

Shell script works fine as a standalone script but not as part of a bigger script

Hello all, I am facing a weird issue while executing a code below - #!/bin/bash cd /wload/baot/home/baotasa0/sandboxes_finance/ext_ukba_bde/pset sh UKBA_publish.sh UKBA 28082015 3 if then echo "Param file conversion for all the areas are completed, please check in your home directory"... (2 Replies)
Discussion started by: ektubbe
2 Replies

3. UNIX for Dummies Questions & Answers

Calling a script from master script to get value from called script

I am trying to call a script(callingscript.sh) from a master script(masterscript.sh) to get string type value from calling script to master script. I have used scripts mentioned below. #masterscript.sh ./callingscript.sh echo $fileExist #callingscript.sh echo "The script is called"... (2 Replies)
Discussion started by: Raj Roy
2 Replies

4. Shell Programming and Scripting

Script will keep checking running status of another script and also restart called script at night

I am using blow script :-- #!/bin/bash FIND=$(ps -elf | grep "snmp_trap.sh" | grep -v grep) #check snmp_trap.sh is running or not if then # echo "process found" exit 0; else echo "process not found" exec /home/Ketan_r /snmp_trap.sh 2>&1 & disown -h ... (1 Reply)
Discussion started by: ketanraut
1 Replies

5. Shell Programming and Scripting

create a shell script that calls another script and and an awk script

Hi guys I have a shell script that executes sql statemets and sends the output to a file.the script takes in parameters executes sql and sends the result to an output file. #!/bin/sh echo " $2 $3 $4 $5 $6 $7 isql -w400 -U$2 -S$5 -P$3 << xxx use $4 go print"**Changes to the table... (0 Replies)
Discussion started by: magikminox
0 Replies
Login or Register to Ask a Question