Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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
share|improve this question
    
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 W. Feb 7 '12 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 –  Steve_gingercat Feb 7 '12 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 W. Feb 7 '12 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. –  Steve_gingercat Feb 7 '12 at 3:19

1 Answer 1

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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