Problems with a .sh file in cron


 
Thread Tools Search this Thread
Operating Systems Linux Ubuntu Problems with a .sh file in cron
# 1  
Old 11-26-2011
Error Problems with a .sh file in cron

Hi guys. This is my first post so bear with me.

I'm trying to get cron to run a shell script in my home directory (/home/server) that checks the temperature of my HDD. The script works fine, however I can't run it in cron. I've checked the syslog and I have only seen two errors:
- Exited with error number 127
- Exited with error number 1

I really need a simple guide showing me how to run a shell file from cron, as I've been searching for absolutely ages and I haven't found one tutorial on it.

Do I have to put .sh, or just the script name? I'm really confused... Smilie
# 2  
Old 11-26-2011
And how do you launch your script in cron?
Most certainly if you execute your script in interactive mode runs fine, but not when executed by cron, you have to look at your environment!
Something set in your profile that cron ignores...
# 3  
Old 11-26-2011
Well, I have heard a lot about the environments. I usually run the script using 'bash tempcheck.sh'. The script is:

Code:
#!/bin/bash

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

I also have the SHELL, MAILTO, HOME and PATH variables set in the crontab file:

Code:
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/home/server

And I was trying to run the script like so:
Code:
*/20 * * * * root /home/server/tempcheck.sh

or...
Code:
*/20 * * * * root /home/server/tempcheck

# 4  
Old 11-26-2011
The full error message should be in unix mail for the owner of the cron.

File extensions have no meaning in unix (beyond being documentary). You always specify the exact name of the script.

The script itself must be set executable.
Please post "ls -lad yourscriptname" so we can check the basics.

I can see some issues with the script where full pathnames will be required (e.g. poweroff and templog.txt).
Stongly advise you turn the "poweroff" line into an echo while you are testing the script.

I believe that $TEMP is a reserved variable. Maybe change it to ${TEMPERATURE} .

Last edited by methyl; 11-26-2011 at 08:31 AM..
# 5  
Old 11-26-2011
I do set all my files to 777 so my game server don't have problems with permissions etc. I have done ls on the script and it came back with the following:
Code:
-rwxrwxrwx 1 777 root 216 2011-11-22 17:14 tempcheck.sh

I will also change the $TEMP variable in the script. Where do I read/change the mail setting as I have no idea where it's going. Does it actually mean 'mail' (email) or is it just a log? Also, what full path would I specify with poweroff and hddtemp?


EDIT:
I've also amended the script and crontab file:

tempcheck.sh
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 >> templog.txt
if [ $TEMPERATURE -ge 50 ]; then
poweroff
fi

crontab file:
Code:
*/20 * * * * root /home/server/tempcheck >> /home/server/cronlog.txt

# 6  
Old 11-26-2011
Do you get anything in templog.txt ? Did you find any errors in root mail?
# 7  
Old 11-26-2011
Quote:
Originally Posted by methyl
Do you get anything in templog.txt ? Did you find any errors in root mail?
I will check templog now, but, what is and how do I set the mail setting? I mean, what is root mail and where is it?

EDIT:
There's nothing in my cronlog.txt file or templog.txt, although in /var/log/syslog there are multiple errors like:
Code:
(server) CMD (root /home/server/tempcheck >> /home/server/cronlog.txt)
(CRON) error (grandchild #15590 failed with exit status 127)
(CRON) info (No MTA installed, discarding output)


Last edited by Rautoner; 11-26-2011 at 11:37 AM..
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