0

I have this script. When I run it from the command line, it works fine. When I run it from cron, it only prints out half of the data

The results should look like this:

07/Feb/2012 11 0.5

07/Feb/2012 11  0.333333

07/Feb/2012 11  0.3

currently I'm getting just the date data when I run it from cron:

07/Feb/2012 11 
07/Feb/2012 11  
07/Feb/2012 11  
07/Feb/2012 11

This is the script:

#!/bin/bash
#
PATH=/opt/someApp/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/awk

# Generate data and hour stamp
date '+%d/%b/%Y %H' > /var/www/stats/datedata

#Crank out  and consider utlisation
/usr/bin/./top -d 3 -n3 | /bin/./grep "Cpu" | awk '{ sum += $2/3 } END { print sum }' > /var/www/stats/usage_cpu

#
/usr/bin/./paste /var/www/stats/datedata /var/www/stats/usage_cpu >> /var/www/stats/thedata

This is my crontab entry: (I'm using /etc/crontab to set this up)

20 *    * * *   root    /var/www/stats/./stats.sh
4
  • The question you are asking seems to be semi ambiguous... are you asking "How can I get the cronscript to return the output in the format that I want?"
    – Thomas Ward
    Feb 7, 2012 at 1:13
  • What I'm trying to explain is that the script works ok when I run it, but when cron runs the script it does not do the processing of the top awk line thus giving me only 2 coloums of data (the date related stuff) not the date and Cron awk stuff Feb 7, 2012 at 2:30
  • I get what you're explaining, but I didn't understand the question being asked, because I didnt see any specific question within your post. Given your explanation, though, the question is "How can I get the crontab to display the output correctly?".
    – Thomas Ward
    Feb 7, 2012 at 2:55
  • For some reason crontab is not letting me generate data from either awk grep or top - I have opened up permissions on all files that the script writes to - have added I think enough path info. Feb 7, 2012 at 3:19

1 Answer 1

0

Try calling /usr/bin/awk instead of just awk.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.