Problems with a .sh file in cron


 
Thread Tools Search this Thread
Operating Systems Linux Ubuntu Problems with a .sh file in cron
# 8  
Old 11-26-2011
Am I having eyesight trouble or what is that root before tempcheck ?

I would redirect STDOUT and STDERR in two separate files to see what is happening
This User Gave Thanks to vbe For This Post:
# 9  
Old 11-26-2011
I think vbe has spotted it. Perhaps your Ubuntu has a normal unix crontab syntax which does not contain the username field (i.e. "root"). Is the crontab you are editing called "root". Are there any other entries in the file which could use to compare.

You can't beat actually posting the error messages verbatim. The 127 error means that cron can't find the file to be executed. The error suggests that it may be trying to execute a file called "root"? The MTA error means that cron can't find your Mail Transport Agent - maybe because you don't have email configured?
This User Gave Thanks to methyl For This Post:
# 10  
Old 11-27-2011
I know that I don't have my mail configured because I've never had to. Where do I configure it? I know how to run servers and websites, not errors on linux Smilie I'll remove the 'root' before the file and see what the syslog says. Also, the crontab I'm editing isn't called root, I just use 'crontab -e' to edit it. Oh, and should I put all these in the root's crontab (sudo crontab -e), so that it won't have a problem running the script, as I know that hddtemp and poweroff will need to be root.
By the way, what does verbatim mean?

---------- Post updated at 07:11 PM ---------- Previous update was at 07:01 PM ----------

Same thing. Here's the current syslog:

Code:
Nov 26 19:09:01 server CRON[25789]: (root) CMD (  [ -x /usr/lib/php5/maxlifetime ] && [ -d /var/lib/php5 ] && find /var/lib/php5/ -depth -mindepth 1 -maxdepth 1 -type f -cmin +$(/usr/lib/php5/maxlifetime) ! -execdir fuser -s {} 2>/dev/null \; -delete)
Nov 26 19:09:01 server CRON[25790]: (server) CMD (/home/server/tempcheck >> /home/server/cronlog.txt)
Nov 26 19:09:01 server CRON[25788]: (CRON) error (grandchild #25790 failed with exit status 127)
Nov 26 19:09:01 server CRON[25788]: (CRON) info (No MTA installed, discarding output)
Nov 26 19:10:01 server CRON[25993]: (server) CMD (/home/server/tempcheck >> /home/server/cronlog.txt)
Nov 26 19:10:01 server CRON[25992]: (CRON) error (grandchild #25993 failed with exit status 127)
Nov 26 19:10:01 server CRON[25992]: (CRON) info (No MTA installed, discarding output)

---------- Post updated 27-11-11 at 03:21 PM ---------- Previous update was 26-11-11 at 07:11 PM ----------

I solved it!
Thanks for your help guys. I amended the script like so:

Code:
#!/bin/bash

TEMPERATURE=$(/usr/sbin/hddtemp /dev/sda | cut -d: -f3 | sed 's/..$//' | sed 's/ //')
echo $(date '+DATE: %m/%d/%y  TIME:%H:%M:%S') - Temperature was: $TEMPERATURE >> /home/server/templog.txt
if [ $TEMPERATURE -ge 50 ]; then
/sbin/poweroff
fi

and the crontab file like so:

Code:
*/5 * * * * /home/server/tempcheck.sh >> /home/server/templog.txt

# 11  
Old 11-27-2011
Setting files owned by root to 777 is a disaster waiting to happen. NEVER do this.

If it is owned by root and 777, anybody can rewrite your file and you will run it, as root.

Imagine what this would do to your system:

Code:
dd if=/dev/zero of=/dev/sda


You really should not do this.

Last edited by mark54g; 11-27-2011 at 04:35 PM.. Reason: explanation
# 12  
Old 11-27-2011
Verbatim is a word means "repeating the exact words that were used". When dealing with computer error messages you must report the whole message exactly as it appeared on the screen - complete with all punctuation, space characters, upper/lower case etc..

Glad it's working. The "man" pages for Ubuntu cite two different formats for a crontab file (without and with a username). I'm glad that yours is a normal "unix" format crontab.

Setting up basic unix mail should be straightforward. Source a "how to" manual for your Operating System. Internet mail is more difficult and will depend on your environment.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Execution Problems with Cron

Good evening, ive got this cron to be run: if i run this manually it doesnt work,it takes me to the prompt again /export/app/CO/opge/scr/Informe_parametros_colombia.ksh >/dev/null 2>&1 here is the code fragment: coopge@coopge: opge PRODUCCION>more... (1 Reply)
Discussion started by: alexcol
1 Replies

2. UNIX for Dummies Questions & Answers

cron problems

I am trying to setup a cron that runs a script to update my ip for my domain name every time I reboot and checks if my ip changes every 5 minutes and if it does then I update it. I am running Ubuntu server 12.04. The file /etc/cron.d/ipupdate contains # # # Run ipupdate # # /5 * ... (3 Replies)
Discussion started by: Bros2
3 Replies

3. UNIX for Dummies Questions & Answers

Execution Problems with Cron

Hi friends, today i created a cron job , registered the crontab file associated but dont know why the cron is not getting executed at the right time.?? content of Crontab file : 21 15 * * * /subrat/myt i wanted to execute the script myt on 15:21 PM of everyday. the script myt... (2 Replies)
Discussion started by: paras.oriental
2 Replies

4. UNIX and Linux Applications

Execution Problems with Cron

Hi all!! I have a nerve-wracking concept (probably for me!!) which is not understood. My crontab entry looks this way. 33 09 22 3 * /home/myexp.sh "Bgp4 ALL" >/dev/null 2>&1 But cron gets started occasionally. Sometimes it does. Sometimes it does not. And sometimes it hangs in the middle (I... (1 Reply)
Discussion started by: dhivyasuresh
1 Replies

5. Programming

execution problems with cron

how to store a date into file? and how we can access date from the file? ---------- Post updated at 06:09 AM ---------- Previous update was at 06:08 AM ---------- how we can store date in file? (1 Reply)
Discussion started by: causalmodi777
1 Replies

6. Shell Programming and Scripting

Problems with Cron and isql

Dear Friends, I am running a script which runs a select query from a sybase table and outputs the result (1 row) into a .txt file in unix. When I run the script manually it behaves normally. However it doesnt run in crontab. #!/usr/bin/ksh . /opt/ivb/config/set_env ... (1 Reply)
Discussion started by: santoshpayal
1 Replies

7. UNIX for Dummies Questions & Answers

Problems using rsync with cron

Hi, I've created a cron job for a script with a rsync command in it. The script is named pull.sh and contains the following line : What it is supposed to do is pull backup files from the production server of my company to my local server. It should also generate the log file (output.log)... (1 Reply)
Discussion started by: anaigini45
1 Replies

8. UNIX for Dummies Questions & Answers

cron problems

Hi there, this time a have a other problem :) i will start a script over the cron. if i start the script manual (per command) it works without any problems, but over the cron it doesent work. my cron looks like this: 26 15 * * * /path/scriptname.sh 2> /path/error.log there is no... (3 Replies)
Discussion started by: scotty
3 Replies

9. UNIX for Advanced & Expert Users

Cron problems

Hi, I am having a few problems with cron. I have created a shell script (to rotate www logs - this works) and then did the following (as root) #crontab -e 2 0 * * 3 /cron_scripts/wwwlogs.sh ? w ? q # crontab -l entry not shown e.g. it did not show what I had just writern I then... (6 Replies)
Discussion started by: warrend
6 Replies

10. UNIX for Dummies Questions & Answers

Very urgent!! Cron problems

I'm having serious problems running cron. I want to create midnight backups of my files on my unix server and there is something wrong with cron. Here is what I do: First I saw that cron is running (while logged on as root) by typing "ps -aedf|grep cron" and I noticed that there is 1 instance... (4 Replies)
Discussion started by: pappous
4 Replies
Login or Register to Ask a Question