[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


Unable to run a cron job

Posted on 2007-12-05
Medium Priority
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 ?
Question by:LordSM
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +2
LVL 48

Expert Comment

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?
LVL 38

Expert Comment

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

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

Author Comment

ID: 20416489
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"
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 40

Expert Comment

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

Author Comment

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?
LVL 40

Expert Comment

ID: 20416554
LVL 84

Accepted Solution

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

Expert Comment

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

Author Comment

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

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
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.
Suggested Courses

649 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