Solved

Unable to run a cron job

Posted on 2007-12-05
9
629 Views
Last Modified: 2013-12-27
Hi, I wrote a simple script which is working fine, if I am runing it manually. However when trying to run it as cron, it does not work. Can you suggest why -
Cron is -
12 14 * * *  /operations/services/webapps/8.1/Share/ABC.sh > /home/JoeM/temp/Test.log
Manually I run it under a service account say "MyService tcsh". So, it needs to be run under a service account. How do I do that ?
0
Comment
Question by:LordSM
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 48

Expert Comment

by:Tintin
ID: 20416239
99.9% of problems with running scripts via cron is forgetting that cronjobs run it a very minimal environment, so if your script relies on certain paths and/or environment variables, you need to ensure they are set in the script.

What user do you currently have the cronjob as?
0
 
LVL 38

Expert Comment

by:yuzh
ID: 20416334
cron doesn't use any login ENV settings, therefore, it have trouble to run your script.

the workaround is to modify your script to use full path to command
or

use:  su - fred -c command
    use user fred's login env to run the script.

eg:
   12 14 * * *  su - JoeM -c "/operations/services/webapps/8.1/Share/ABC.sh > /home/JoeM/temp/Test.log"

or
12 14 * * *  su - root -c "/operations/services/webapps/8.1/Share/ABC.sh > /home/JoeM/temp/Test.log"
   assume that JoeM's login ENV can run the script.

also have a look at the answer in http:Q_21080002.html
0
 

Author Comment

by:LordSM
ID: 20416489
ABC.sh is a simple script, which just runs to other scripts -

#!/bin/sh
./ScriptA.sh
./ScriptB.sh

Also, would I need to to specify password for sudo acceess. So it would be something like
 12 14 * * *  sudo -u JoeM tcsh -c "/operations/services/webapps/8.1/Share/ABC.sh > /home/JoeM/temp/Test.log"
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 40

Expert Comment

by:omarfarid
ID: 20416511
Do you schedule the job as root? If not root then you need to provide password
0
 

Author Comment

by:LordSM
ID: 20416518
no, it is to be done as a service account. So, where exactly do I specify password? in the script? how would that work or look like?
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 20416554
0
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 20416605
where is . when you run ABC.sh?
Do ScriptA.sh or ScriptB.sh depend on the environment?
0
 
LVL 48

Expert Comment

by:Tintin
ID: 20416681
What you need to do is create a sudo entry that doesn't require a password, eg:

serviceuser   ALL= (joem)  NOPASSWD: /operations/services/webapps/8.1/Share/ABC.sh

then your serviceuser cronjob would look like:

12 14 * * *  sudo -u joem /operations/services/webapps/8.1/Share/ABC.sh > /home/JoeM/temp/Test.log
0
 

Author Comment

by:LordSM
ID: 20416731
I think, it is working fine now. It was a typo in the path I was giving. Thanks though
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question