Unable to run a cron job

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 ?
Who is Participating?
ozoConnect With a Mentor Commented:
where is . when you run ABC.sh?
Do ScriptA.sh or ScriptB.sh depend on the environment?
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?
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

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

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

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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

LordSMAuthor Commented:
ABC.sh is a simple script, which just runs to other scripts -


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"
Do you schedule the job as root? If not root then you need to provide password
LordSMAuthor Commented:
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?
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
LordSMAuthor Commented:
I think, it is working fine now. It was a typo in the path I was giving. Thanks though
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.