CRON job questions

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,
sam15Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

omarfaridCommented:
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
sjm_eeCommented:
4 - you can also schedule individual jobs using the command "at".
0
dfkeCommented:
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
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

sam15Author Commented:
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
omarfaridCommented:
from the logs you can see if the job ran. If it was not run then you will not see any log.
0
dfkeCommented:
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
sam15Author Commented:
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
TintinCommented:
You need to be root to be able to cd to /var/adm/cron

0
sam15Author Commented:
so I can't tell if the cron job scheduled under my account ran or not if i am not root?
0
omarfaridCommented:
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
TintinCommented:
If you don't have root privs, then simply you can't check the cronlog.
0
sam15Author Commented:
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
omarfaridCommented:
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
dfkeCommented:
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
sam15Author Commented:
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
omarfaridCommented:
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
sam15Author Commented:
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
omarfaridCommented:
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
sam15Author Commented:
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
omarfaridCommented:
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
sam15Author Commented:
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
omarfaridCommented:
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
sam15Author Commented:
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
omarfaridCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.