LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-11-2011, 01:25 PM   #1
ScorchPipe
Member
 
Registered: Sep 2010
Posts: 38

Rep: Reputation: 0
Script won't run in crontab.... only manually


Hi

I want to start out by saying that I've search for this problem but none of those solutions where of any relevance to me/didn't work.

I have this bash script I want to run in crontab that will check my /dev/md0 for failed devices (I dont want sendmail or postfix for this).

The script won't run if not run manually. So I ask for help: Does anyone see a problem with the script or crontab? Is it even possible?

Here's /etc/crontab:
0 12 * * * /bin/sh /checkRAID.sh

I have also tried
0 12 * * * root /bin/sh /checkRAID.sh


Here's the script. Notice that this version of the script will email me if the raid WORKS. Just for testing purpose. The script is located under / and has chmod 777.

#!/bin/sh

set `/sbin/mdadm --detail /dev/md0|grep -i "Failed Devices :"|cut -d ":" -f 2`
failed=$1

if [ $failed -eq 0 ] ; then

# Specify the following options

# Senders email:
SendersEmail="mymail1@hotmail.com"

# Senders usernamne:
Username="mymail1@hotmail.com"

# Senders password:
Password="mypassword"

# Recievers email:
RecieversEmail="mymail2@hotmail.com"

# Subject:
Subject="Meddelande om /dev/md0"

# Message:
Message="Raiden funkar"

# SMTP Server:
Server="smtp.live.com:587"

# Sending the email

sendEmail -f $SendersEmail \
-t $RecieversEmail \
-s $Server \
-xu $Username \
-xp $Password \
-u $Subject \
-m $Message

else
echo "ej ok"

fi


EDIT:
I run CentOS 5.5

Last edited by ScorchPipe; 03-11-2011 at 01:27 PM.
 
Old 03-11-2011, 01:29 PM   #2
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,527

Rep: Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898
In general cron doesn't work, because it uses a limited PATH.
Make sure to use the whole path to all the commands.
If the PATH is correct, try to use
Code:
0 12 * * * /checkRAID.sh
Kind regards

Last edited by repo; 03-11-2011 at 01:33 PM.
 
Old 03-11-2011, 01:39 PM   #3
ScorchPipe
Member
 
Registered: Sep 2010
Posts: 38

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by repo View Post
In general cron doesn't work, because it uses a limited PATH.
Make sure to use the whole path to all the commands.
If the PATH is correct, try to use
Code:
0 12 * * * /checkRAID.sh
Kind regards
Ok i'll try
 
Old 03-11-2011, 03:19 PM   #4
devUnix
Member
 
Registered: Oct 2010
Location: Bengaluru, India
Distribution: RHEL 5.1 on My PC, & SunOS / Sun Solaris, RHEL, SuSe, Debian, FreeBSD and other Linux flavors @ Work
Posts: 576

Rep: Reputation: 48
Yes, as suggested by "repo" try this:

Code:
0 12 * * * /checkRAID.sh
Note: How are you making sure that the cron is not executing the script? By checking your inbox? Can you, for just testing purpose, comment out the email part and log the output to a file and see whether it works or not?

Code:
0 12 * * * /checkRAID.sh > /tmp/checkRAID.log
 
Old 03-11-2011, 05:11 PM   #5
ScorchPipe
Member
 
Registered: Sep 2010
Posts: 38

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by devUnix View Post
Yes, as suggested by "repo" try this:

Code:
0 12 * * * /checkRAID.sh
Note: How are you making sure that the cron is not executing the script? By checking your inbox? Can you, for just testing purpose, comment out the email part and log the output to a file and see whether it works or not?

Code:
0 12 * * * /checkRAID.sh > /tmp/checkRAID.log

The first one didn't work.

I assumed that cron is not executing the script since the script itself works fine.
Also, when I had
Code:
0 12 * * * root /bin/sh /checkRAID.sh
it puts this in /var/log/cron:
Mar 11 12:00:01 Rorschach crond[16435]: (root) CMD (/bin/sh /checkRAID.sh)

(Otherwise there is nothing in the log)

I will try your method tomorrow. Gotta get some sleep now
 
Old 03-11-2011, 05:17 PM   #6
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,527

Rep: Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898
Quote:
Mar 11 12:00:01 Rorschach crond[16435]: (root) CMD (/bin/sh /checkRAID.sh)
The script is executed.
However, if you don't recieve the mail, make sure the path to all the commands in the script are correct.
Especially the sendEmail command.
Look in your root's mailbox, to see if you get a mail from cron with errormessages.

Kind regards
 
Old 03-22-2011, 08:29 AM   #7
alienslideshow
LQ Newbie
 
Registered: May 2008
Posts: 4

Rep: Reputation: 0
I am also struggling with this problem and its only on LINUX servers. I work on HPUX, Sun and AIX boxes and have to trouble setting up a cron job.

In order to make it work I had to add */20 * * * * /script >> outfile

This, crontab notices. But I also have ...command... >> outfile... within the script. So I changed back to */20 * * * * /script, and now after a day of struggling it works.

I've noticed this kind of behavior before with linux and its really a problem. While updating SUDO and /etc/passwd and /etc/group files I'll have to test 3 or 4 different sudo accounts and linux gets confused and can't keep up with the changes.

Do the same thing in HPUX, AIX or Solaris, no problem.
 
Old 03-22-2011, 11:11 AM   #8
trist007
Senior Member
 
Registered: May 2008
Distribution: Slackware
Posts: 1,027

Rep: Reputation: 69
From Dillon's cron man page
Quote:
Whenever crond must run a job, it first creates a daemon-owned temporary file O_EXCL and O_APPEND to store any output, then fork()s and changes its user and group permissions to match that of the user the job is being run for, then exec's /bin/sh -c to run the job.
Depends which type of cron you're using. For example in Slackware 13.0, if you're using Dillon's cron then it uses /bin/sh to execute it's commands, which is why ***** /bin/sh /checkRAID.sh doesn't work properly. So because the cron runs it's jobs with /bin/sh just use
***** /checkRAID.sh.

Last edited by trist007; 03-22-2011 at 11:13 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
My BASH script work perfect when i run it manualy, but not when it run in the crontab roqarg Linux - Newbie 30 05-06-2010 02:37 PM
[SOLVED] script not running via crontab, run's fine manually astroboiii Linux - Software 10 02-08-2010 11:36 PM
Script won't run in crontab rastellig Linux - Software 2 03-25-2009 10:18 AM
How to run this script in Crontab baig Linux - Newbie 2 11-30-2008 03:34 PM
Script doesn't run in crontab dani81 Linux - General 1 11-16-2004 04:42 AM


All times are GMT -5. The time now is 02:55 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration