- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- script execution fails when executed from crontab
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-13-2010 08:52 AM
тАО01-13-2010 08:52 AM
#!/bin/bash
avg=`uptime | awk '{print $8" " $9 " "$10 $11 $12 }' | tr -s , " "`
cur=`more /proc/loadavg | awk '{print $1}' | tr -d , | cut -d. -f1`
str="============================="
info="Curent $avg"
if [ $cur -ge 6 ]; then
info1="Server load is high presently"
touch /tmp/tmp.00
echo -e "$str\n$info\n$info1\n$str\n" >> /tmp/tmp.00
ps aux | head -1 >> /tmp/tmp.00
ps aux | sort -rn +2 | head -10 >> /tmp/tmp.00;
mail -s "Alert: Load Average for `hostname` on `date` " email1 < /tmp/tmp.00;
mail -s "Alert: Load Average for `hostname` on `date` " email2 < /tmp/tmp.00;
rm -f /tmp/tmp.00
else
#echo -e "$str\n$info\n$str"
exit 0;
fi
when i execute this script i don get any error.
However, when it runs through cron it throws an error.
./monitor_loadavg.sh: line 7: [: too many arguments
i don see anything wrong with line 7.
Please suggest if i am doing anything wrong
Thanks
SUnny
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-13-2010 09:26 AM
тАО01-13-2010 09:26 AM
SolutionOn line 3, you use the "more" command to read /proc/loadavg. When you're running the script in your session, "more" can find the $TERM and $LINES environment variables that identify your terminal type and the number of lines in your terminal window.
But when running from cron, there is no terminal, and those variables won't exist. I guess "more" might produce some extra output (a notification message or something). You don't need it anyway: this version of line 3 of your script should work just the same, but without the uncertain behavior of "more":
cur=$(awk '{print $1}' < /proc/loadavg | tr -d, | cut -d. -f1)
mK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-13-2010 09:28 AM
тАО01-13-2010 09:28 AM
Re: script execution fails when executed from crontab
Probably because you don't see what "$cur"
is.
> if [ $cur -ge 6 ]; then
if [ "$cur" -ge 6 ]; then
But, if "cur" contains multiple tokens, then
you'll probably need to look more closely at
its definition.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-13-2010 10:24 AM
тАО01-13-2010 10:24 AM
Re: script execution fails when executed from crontab
Add an echo $cur on line 6 to debug the problem.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-16-2010 12:09 AM
тАО01-16-2010 12:09 AM
Re: script execution fails when executed from crontab
Besides this change, you can probably replace tr(1) and cut(1) by more awk functions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-16-2010 09:25 AM
тАО01-16-2010 09:25 AM
Re: script execution fails when executed from crontab
your suggestion worked for me.