![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Please help - disk space check script | maddhadder71 | Shell Programming and Scripting | 0 | 05-08-2008 05:16 AM |
| Disk space script | asadlone | Shell Programming and Scripting | 8 | 06-03-2007 12:32 PM |
| Frustrating Disk space script | vivsiv | Shell Programming and Scripting | 4 | 06-05-2006 04:53 PM |
| disk space script debug - posted before | bryan | Shell Programming and Scripting | 3 | 04-28-2005 04:50 PM |
| available disk space on disk device??? | alan | UNIX for Dummies Questions & Answers | 4 | 01-01-2004 11:06 PM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Disk Space Monitoring Script
#!/bin/bash
# Disk Space Monitoring for more than 95 % # and Sending Alerts by Mail if [ df -k |awk '$5 > 95 ]; then `df -k |awk '$5 > 95 {print $1 " ----------- " $5}' |mailx -s "More than 95% disk usage in DEV" email@test.com'; else exit 0 fi I get the below error: ================ bash-3.00$ ./disk_usage_mail_alert-sriram.sh ./disk_usage_mail_alert-sriram.sh: line 14: syntax error near unexpected token `else' ./disk_usage_mail_alert-sriram.sh: line 14: `else ' |
| Forum Sponsor | ||
|
|
|
|||
|
that's very kludgy. the usage of awk is more than meets the eye
try this Code:
df -k | awk 'int($5) > 95{
subject = $1 " More than 95% disk usage "
email = "email@test.com"
cmd = "mailx -s \"" subject "\" " email
cmd | getline #or system(cmd)
}
'
|
|
|||
|
Can you suggest what is the syntax I am missing ?
bash-2.03$ ./new.sh awk: syntax error near line 5 awk: illegal statement near line 5 ./new.sh: line 8: 11058 Broken Pipe df -k 11059 Exit 2 | awk 'int($5) > 95{ subject = $1 " More than 95% disk usage " email = "email@test.com" cmd = "mailx -s \"" subject "\" " email cmd | getline #or system(cmd) } ' ==================================== bash-2.03$ cat new.sh (the script) ==================================== 1 2 df -k | awk 'int($5) > 95{ 3 subject = $1 " More than 95% disk usage " 4 email = "email@test.com" 5 cmd = "mailx -s \"" subject "\" " email 6 cmd | getline #or system(cmd) 7 } 8 ' ==================================== bash-2.03$ Last edited by sriram003; 08-23-2007 at 06:55 AM. |
|
|||
|
thanks, its good practice to close that. However, for my version of awk (GNU) , the "if" part, i don't think its needed cause i tested it. i think it differs across versions
|
|
||||
|
Quote:
Code:
df -k | awk 'int($5) > 95 {
subject = $1 " More than 95% disk usage "
email = "email@test.com"
cmd = "mailx -s \"" subject "\" " email
cmd | getline #or system(cmd)
close(cmd)
}
'
And once again - sorry for the confusion! Last edited by vgersh99; 08-23-2007 at 08:27 AM. |