[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Job scheduled via CRON on Linux does not run

Posted on 2013-10-25
15
Medium Priority
?
597 Views
Last Modified: 2013-11-11
I scheduled a job via CRON on Linux server:

>crontab -e

30 13 * * * /root/myscript.ksh 2>&1  >> /root/myscript.log

The job did not run and nothing got written to the log file

What am I doing wrong?
0
Comment
Question by:YZlat
[X]
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
15 Comments
 
LVL 35

Expert Comment

by:Seth Simmons
ID: 39601067
does it run manually?
is cron service running?
0
 
LVL 13

Assisted Solution

by:Daniel Helgenberger
Daniel Helgenberger earned 468 total points
ID: 39601075
Who's the user you are using crontab -e with?
Cron logs may be in /var/log/cron - depending on your distro.
Also, put this line in a file in /etc/cron.d/ - this ensures it is run by root.
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 39601080
For cron jobs you need to:

1- use full path names to file and folders
2- set env variables needed, since cron will not read .profile, etc. e.g. you need to set PATH
3- redirect output & errors (stdout & stderr) to files
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 40

Expert Comment

by:omarfarid
ID: 39601088
also, make sure that script file is executable and you set shell to be used in the script itself, e.g. put this at your script:

#!/usr/bin/ksh
0
 
LVL 35

Author Comment

by:YZlat
ID: 39621585
already using #!/usr/bin/ksh


What do I set PATH to?
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 39621611
You need to set it to the directories where your binaries / commands are. e.g.

PATH=/usr/bin:/path/to/my/commands

You could simply take it from your login shell:

echo $PATH

This should give you the PATH you have when you login to system and then you set it to the same in your shell script (and export it with: export PATH).
0
 
LVL 35

Author Comment

by:YZlat
ID: 39621703
how do I find out the directory for the binaris/commands?

Also how do I find out which user cron runs under?

I am brand new to linux

P.S> I moved my script to /etc/cron.d as has been suggested:

30 13 * * * /etc/cron.d/myscript.ksh 2>&1  >> /etc/cron.d/myscript.log

but the script does not seem to run and myscript.log file still does not get generated
0
 
LVL 40

Assisted Solution

by:omarfarid
omarfarid earned 932 total points
ID: 39621779
Ok, in your question you said:

"I scheduled a job via CRON on Linux server:

>crontab -e

30 13 * * * /root/myscript.ksh 2>&1  >> /root/myscript.log"

The user that crontab job is scheduled under is the same user logged in and ran crontab -e

you could find username by running command

username

or running command

id

As I mentioned before, while logged in run command

echo $PATH

this sould give your directories under which binaries or commands are located (dir names are separated by : )
0
 
LVL 35

Author Comment

by:YZlat
ID: 39621828
thanks, I know I can do echo $PATH, but when running a script via crontab I need to set PATH inside the script and export it. What do i set it to? or do i just do export PATH?


But even then it still does not explain why cronta does not run the job or even generate a log file
0
 
LVL 40

Accepted Solution

by:
omarfarid earned 932 total points
ID: 39622091
e,g,

when you run

echo $PATH

you will get something like

/usr/bin:/sbin:/usr/user1/bin:/usr/local/mycmd

then you can add to your script line like

PATH=/usr/bin:/sbin:/usr/user1/bin:/usr/local/mycmd ; export PATH
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 39622093
do you have other crontab jobs? check with

crontab -l

to see if other crontab jobs are scheduled
0
 
LVL 35

Author Comment

by:YZlat
ID: 39638921
nope, no other cron jobs - it is a new server
0
 
LVL 35

Author Comment

by:YZlat
ID: 39639101
setting $PATH didn't make a difference:(
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 39639215
can you run simple crontab job and see if you get it run?

can you share the script you are trying to run?
0
 
LVL 35

Author Closing Comment

by:YZlat
ID: 39639758
thanks!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
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…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

650 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