[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

CRON job questions

Posted on 2008-11-15
24
Medium Priority
?
899 Views
Last Modified: 2013-12-21
I have some unix questions:

1.  How can i monitor if a cron job runs every day or not and whether it passed or failed?
2.  how can is see all the cron jobs running under my login aaccount?
3.  How can i rebuild a cron job
4.  Can cron jobs be scheduled either via commands or separate files?
5.  How can i see the allocate space for my unix account and much space is availabe for storage?

THank you,
0
Comment
Question by:sam15
  • 9
  • 9
  • 3
  • +2
24 Comments
 
LVL 40

Expert Comment

by:omarfarid
ID: 22969926
1- crontab jobs output is sent via mail to user mail box , or depending on your system, look at the log dir under /var (varies from OS to OS)

2- to list crontab jobs under your account run

crontab -l

3- to make a new crontab job run

EDITOR=vi ; export EDITOR
crontab -e

The above will let you edit a temp file that is your crontab jobs schedules using vi editor. Then you edit, save and exit from the temp file

4- Scheduling is done as described above or by running

crontab -l > file
vi file
crontab file

5- for storage, use commands like df or du
0
 
LVL 14

Expert Comment

by:sjm_ee
ID: 22971280
4 - you can also schedule individual jobs using the command "at".
0
 
LVL 10

Expert Comment

by:dfke
ID: 22971283
cron actions are logged in the /var/adm/cron/log file. It has info about time, commend ,running PID and if the job is passed or failed. If you cannot read the file you need to login as root first.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:sam15
ID: 22971577
so if i have a cron job that is supposed to be run nightly and it either FAILED or DID NOT  RUN.

On next day, i can go the log file or mail and it would tell me that it did not run or it will just not show a record at all which tells me last time it ran was twoweeks ago.
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 22974306
from the logs you can see if the job ran. If it was not run then you will not see any log.
0
 
LVL 10

Expert Comment

by:dfke
ID: 22974404
ie.  if you say a particular job is logged 2 weeks ago then it is not running every night.
Let's say a command  /X needs to run every night at 2am.

Then the crontab line should look like:

 2 * * * /X

Output in /var/adm/cron/log should be:

root      : CMD ( /X : PID ( <PID>) : <Date> 02:00:00 2008
Cron Job with pid: <PID> Successful / Failed


0
 

Author Comment

by:sam15
ID: 22987758
Do you know why i can't get to that cron directory under /var/adm/

/var/adm $ ls -al
total 59738
dr-xr-x---   2 bin      cron            512 Sep 20 04:58 cron
/var/adm $ cd cron
ksh: cron:  not found.
0
 
LVL 48

Expert Comment

by:Tintin
ID: 22988069
You need to be root to be able to cd to /var/adm/cron

0
 

Author Comment

by:sam15
ID: 22989368
so I can't tell if the cron job scheduled under my account ran or not if i am not root?
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 22991150
On solaris 8 it is in dir

/var/cron

and file log

and only root can read

did you check your mail on the system?

also,  you can redirect the output of your script to a log file which you can check from time to time
0
 
LVL 48

Expert Comment

by:Tintin
ID: 22991205
If you don't have root privs, then simply you can't check the cronlog.
0
 

Author Comment

by:sam15
ID: 22991404
this is ibm aix machine.

I checked the mail and there is nothing there.

It seems the only way is a log file like you say. How do i set this up now without affecting the cron jobs. or do i have to delete and reshcedule them
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 22991578
I think you just add logging to the schedule, e.g.

EDITOR=vi ; export EDITOR

crontab -e

Then modify entries to look like e.g. from

0 * * * * /path/to/script1

to

0 * * * * /path/to/script1 >> /path/to/script1.log 2>&1

save and exit.

OR

if not interested in logging every thing, then edit script1 and redirect the specific commands in that script



0
 
LVL 10

Expert Comment

by:dfke
ID: 22992675
In your situation running crontab -e won't open the root crontab as you're not logged in as root, instead it will try to edit the crontab for your own account or opens a new file to create one if your admin allows you to do so. I know my users can't do that. So if your command is not listed with crontab -l it must be rescheduled in the root crontab so consult your admin about this one.

As for the free space try the df command.
0
 

Author Comment

by:sam15
ID: 23038089
This is the crontab statement. Is this wirting a log anywhere to check?
this is a solaris machine too.

crontab -l
0,5,10,15,20,25,30,35,40,45,50,55 * * * * /bin/csh /itec/mesg/runbatch.csh >/dev/null 2>&1
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 23041811
the output is sent to /dev/null which is basically no where and 2nd csh does not support 2>&1

try

0,5,10,15,20,25,30,35,40,45,50,55 * * * * /bin/csh /itec/mesg/runbatch.csh >>&  /path/to/logfile
0
 

Author Comment

by:sam15
ID: 23044017
thank omar

so you are saying there is something wrong with this cron statement?

How do you fix it to make it output to a log file every time it runs with date/timestamp and whther the run was success or failure.

thank you,
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 23048250
try this:

0,5,10,15,20,25,30,35,40,45,50,55 * * * * /bin/csh /itec/mesg/runbatch.csh >>&  /path/to/logfile`/usr/bin/date "+%d%d%y"`
0
 

Author Comment

by:sam15
ID: 23052182
is this going to write an entry to /path/to/logile every time the cron runs?

what is that '/usr/bin/date "+%d%d%y" do? is it running a date command from the bin directory
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 23054784
no, it is going to send output of your script (if any) to a new file that has date stamp  in its name. the

`/usr/bin/date "+%d%m%y"`

will get the date (in the format DDMMYY) (please note the inverted comma (`) and attach it to file name
0
 

Author Comment

by:sam15
ID: 23057965
but since the cron is calling a batch program that has really large output is it going to create one file every 5 mintues with the ooutput of the batch program? It has many of scp and debug statements.

Is not there a way to have one log file with a high level entry on time/date the job ran like this

Monday 10/10/2008 at 12:00:10 PM: - job ran successfully
Monday 10/10/2008 at 12:05:10 PM - job ran successfully
Monday 10/10/2008 at 12:10:10 Pm - job failed execution
.........
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 23058223
the system has its own cron log file to show jobs ran and info about them. e.g. on solaris the file is

/var/cron/log

and sample log from it from my system:

>  CMD: /usr/bin/ls /tmp > /tmp/ls.out
>  omar 1250 c Sat Nov 29 05:00:00 2008
<  omar 1250 c Sat Nov 29 05:00:01 2008
>  CMD: /usr/bin/ls /tmp > /tmp/ls.out
>  omar 1260 c Sat Nov 29 06:00:00 2008
<  omar 1260 c Sat Nov 29 06:00:01 2008

If you are interested then you may add the date command with an echo command at the end of your scrip and then have the script output redirected to the same file e.g.

0,5,10,15,20,25,30,35,40,45,50,55 * * * * /bin/csh /itec/mesg/runbatch.csh >>&  /path/to/logfile

the echo command at the end of your script could be like this

echo "`/usr/bin/date` - Job ran successfully"
0
 

Author Comment

by:sam15
ID: 23058332
but is not this a fake message. The cron may fail in reality and you can get this message.
for example, if the batch file was deleted or something else went wrong would this be written to the file too as "job ran successfully".
0
 
LVL 40

Accepted Solution

by:
omarfarid earned 2000 total points
ID: 23059544
the success of failure of the script is something that you can build in your script logic. That is, you can write your script in such a way that you report the success of you commands in the script. cron can report if the script failed to run but can not till about the success of the commands in the script.
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

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

Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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…
Suggested Courses
Course of the Month18 days, 6 hours left to enroll

830 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