Top output to textfile not working in cronjob


 
Thread Tools Search this Thread
Operating Systems Linux Ubuntu Top output to textfile not working in cronjob
# 1  
Old 08-08-2013
Top output to textfile not working in cronjob

Hello,
If i run the following script from the cmdline it works just fine however if i run it via root cronjob it doesn't write to the file at all. It is chmod 777 now so shouldnt be any right issues.

Shellscript looks like this:
Code:
/usr/bin/top -b -n 1 -u nagios >> /var/log/test.log

Cronjob like this:
Code:
38 * * * * sh /shellScripts/test.sh >> /var/log/dummy.txt

Any idea?
Simply i want to log top output to a textfile when cronjob runs.

Last edited by Scott; 08-08-2013 at 01:46 PM.. Reason: Please use code tags
# 2  
Old 08-08-2013
Any output would go to /var/log/test.log, not /var/log/dummy.txt. Is that where you are checking?

Also, in this case errors, would to the job owner's email (usaually).
# 3  
Old 08-08-2013
Quote:
Originally Posted by Scott
Any output would go to /var/log/test.log, not /var/log/dummy.txt. Is that where you are checking?

Also, in this case errors, would to the job owner's email (usaually).
Ye i am checking in the test.log file.
It writes there just fine if i do it from cmdline, not sure why cronjob isn't picking it up. Is there anyway to see what the cronjob says about it?
# 4  
Old 08-08-2013
And the location of the script is definitely /shellScripts/test.sh? The directory is at least r-x for the user running the cronjob?

Can you check /var/log/cron to check the job actually ran?

I ran a text doing (albeit in RedHat) exactly what you said you are doing and have no problems.
This User Gave Thanks to Scott For This Post:
# 5  
Old 08-08-2013
does your script have PATH variable set or at least the commands have their full paths (i.e., /bin/hostname instead of hostname, /usr/bin/rm instead of just rm, etc.)? if yes, look at something else in your current environment that will not be there should cron run your script and then account for it inside your script ...
# 6  
Old 08-08-2013
Quote:
Originally Posted by Scott
And the location of the script is definitely /shellScripts/test.sh? The directory is at least r-x for the user running the cronjob?

Can you check /var/log/cron to check the job actually ran?

I ran a text doing (albeit in RedHat) exactly what you said you are doing and have no problems.

Yep the directory is read and execute for users.
If i check the syslog i saw the following:


Code:
Aug  8 18:03:01 ubuntuServer CRON[21762]: (CRON) info (No MTA installed, discarding output)
Aug  8 18:05:20 ubuntuServer crontab[21804]: (root) BEGIN EDIT (root)
Aug  8 18:05:40 ubuntuServer crontab[21804]: (root) REPLACE (root)
Aug  8 18:05:40 ubuntuServer crontab[21804]: (root) END EDIT (root)
Aug  8 18:05:42 ubuntuServer crontab[21816]: (root) BEGIN EDIT (root)
Aug  8 18:06:01 ubuntuServer cron[1335]: (root) RELOAD (crontabs/root)
Aug  8 18:06:01 ubuntuServer crontab[21816]: (root) REPLACE (root)
Aug  8 18:06:01 ubuntuServer crontab[21816]: (root) END EDIT (root)
Aug  8 18:07:01 ubuntuServer cron[1335]: (root) RELOAD (crontabs/root)
Aug  8 18:07:01 ubuntuServer CRON[21841]: (root) CMD (sh /shellScripts/test.sh >/dev/null 2>&1)


Got that "No MTA Installed" so i added the "/dev/null 2>&1" just to see the difference.

---------- Post updated at 11:19 AM ---------- Previous update was at 11:13 AM ----------

Quote:
Originally Posted by Just Ice
does your script have PATH variable set or at least the commands have their full paths (i.e., /bin/hostname instead of hostname, /usr/bin/rm instead of just rm, etc.)? if yes, look at something else in your current environment that will not be there should cron run your script and then account for it inside your script ...
I've not set any special path variables.
The entire scriptfile looks like this:

Code:
#!/bin/sh
clear
/usr/bin/top -b -n 1 -u nagios >> /var/log/test.log

# 7  
Old 08-08-2013
the MTA (mail transfer agent) issue does not seem to be related to your script as it shows up in the logs more than a few minutes before your script runs and the script/program creating the log entries is doing some editing -- most likely a sql maintenance script -- while your top script does not ... besides, the script you posted does not send email so there would be no need for MTAs ...

change 2> /dev/null in your cronjob listing to 2> /shellScripts/test.err.log and see if there are any errors logged in the error log ...
This User Gave Thanks to Just Ice For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

PHP cronjob not working but manual working

Hi, Can anyone help me on my PHP cron not working, but when i do the manual it work. # manual run working /usr/local/bin/php /root/dev/test.php # crontab not working 55 8 * * * /usr/local/bin/php /root/dev/test.php Thank in advances Regards, FSPalero Please use CODE tags as... (2 Replies)
Discussion started by: fspalero
2 Replies

2. UNIX for Dummies Questions & Answers

Top Command Output is not coming via Cronjob

Dear All, I created a small script to get the CPU, GIS usage etc automatically. However when i run this script manually its working , but when i run through cronjob i am not getting any output. Can anyone please help me on this. I am using SuseLinux. Thank you in advance. #!/bin/sh {... (2 Replies)
Discussion started by: Nitin Kapoor
2 Replies

3. Shell Programming and Scripting

Cronjob is NOT working

Hi; Here is the output from crontab -l: 2,7,12,17,22,27,32,37,42,47,52,57 * * * * /var/tmp/gcsw/jmap_samples/jmap_script.sh > /var/tmp/gcsw/jmap_samples/histo_`date '+%Y%m%d%H%M'`.txtWhen I manually run the line: /var/tmp/gcsw/jmap_samples/jmap_script.sh >... (2 Replies)
Discussion started by: gc_sw
2 Replies

4. UNIX for Dummies Questions & Answers

Cronjob not working

Hi, I am trying to run a script through crontab but it doesn't run. The script sends an email of the logfile created.When I reun through command line it works perfectly but doesn't send any email through cron. There are othe jobs in cron wich runs perfectly. Please let me know if I am doing... (3 Replies)
Discussion started by: Rossdba
3 Replies

5. Shell Programming and Scripting

Script to get required output from textfile

Hi Iam running below script on one text file. usr/xpg4/bin/awk 'BEGIN {print "IP HOST_NAME SUB "} /IP IS/ {IP=$3} /local/ {HOST=$1} /PPPoE/ {SUB=$3 ;print IP, HOST, SUB} ' /Scripts/sub_report_$FILE>/Scripts/sub_final_report_.txt the output is coming as below IPHOST_NAME SUB ... (16 Replies)
Discussion started by: surender reddy
16 Replies

6. Shell Programming and Scripting

Regarding overwriting the textfile with output what we get!

Hi freinds, My problem is I have a script which is used for our office work... in that with my userid i can append the LOGFILE with the output which i get while running the script.. for this i use the below command output >> $LOGFILE but with the same script my colleague is... (6 Replies)
Discussion started by: smarty86
6 Replies

7. Solaris

cronjob not working

Hi All , I have a cron jobs that is not working while put inside cron. But on executing from manually, it works fine, Pl anyone find if there is anything wrong in the script. 30 22 * * 1-5 cd /home/ab90737/introscope/util/bin; ./batchgenerateReport.pl ../config/reps.config >... (1 Reply)
Discussion started by: jegaraman
1 Replies

8. Solaris

cronjob not working

I am trying to schedule a job via cronjob. Not sure what the problem is. below is my script and the error. 45 10 * * * /u01/app/oracle/jpark/sched_exp_mis.sh Error received. Your "cron" job on tama /u01/app/oracle/jpark/sched_exp_mis.sh produced the following output: ... (19 Replies)
Discussion started by: mrx1350
19 Replies

9. UNIX for Advanced & Expert Users

cronjob not working

I created a file in /u01/oradata directory as cronjb.ksh which contains following script 30 12 * * * /export/home/oracle/u01/oradata/rman.ksh '/export/home/oracle' is my root directory. I then moved cronjb.ksh file to my '/export/home/oracle' directory. i typed crontab cronjb.ksh. However my... (8 Replies)
Discussion started by: manna
8 Replies

10. UNIX for Advanced & Expert Users

formatting textfile inside ksh script using awk not working

I cannot seem to get this text file to format. Its as if the awk statement is being treated as a simple cat command. I manned awk and it was very confusing. I viewed previous posts on this board and I got the same results as with the the awk command statement shown here. Please help. ... (6 Replies)
Discussion started by: tekline
6 Replies
Login or Register to Ask a Question