cancel
Showing results for 
Search instead for 
Did you mean: 

cron issue

 
newunix
Frequent Advisor

cron issue

after setting cron as
cat samplecron

0,10,20,30,40,50 * * * * /usr/bin/bdf >> /tmp/bdf.log

i can get the output but my problem is

if i schedule new cron job and i execute crontab filename ,, previous running cron job get removed.

how can i preserve the previous running cron jobs.
15 REPLIES
Elmar P. Kolkman
Honored Contributor

Re: cron issue

You can do that by adding the entries together. With the crontab -l command you can view your current jobs.

Easiest way:
$ crontab -l >oldcron.txt
$ cat oldcron.txt newcron.txt | crontab -

Every problem has at least one solution. Only some solutions are harder to find.

Re: cron issue

>how can I preserve the previous running cron jobs.

Your crontab entry must contain ALL of your jobs. If you want to add more, you can use "crontab -e".
Hakki Aydin Ucar
Honored Contributor

Re: cron issue

Hi,
How did you enter new cron jab ?
crontab -e ??

You mean after save the crontab, you cannot see your previous job anymore inside cron with the command:
# crontab -l ??
newunix
Frequent Advisor

Re: cron issue

hi hakki

when i created first cron job i used vi samplecron

then i executed crontab firstcronjob

for adding second cron job for the same user again i used vi editor and i executed
crontab secondcronjob

after that i listed jobs with crontab -l ,, firstcronjob was missing

Re: cron issue

>and I executed crontab secondcronjob

That's what Hakki suspected. You can't do that. You must put ALL of your user's crontab entries in one "logical" file. The one you pass to crontab(1).
Steven Schweda
Honored Contributor

Re: cron issue

> cron issue

Is that anything like a _problem_?

> [...] and i executed
> crontab secondcronjob

man crontab

Not knowing your HP-UX version, I can't quote
the exact text, but I'd guess that it says
something like:

Create or replace your crontab file by
copying the specified file, [...]

Nothing there about "appending the specified
file".


> crontab -e ??

You might consider using that option.
newunix
Frequent Advisor

Re: cron issue

so if i want to add another cron job for the same user ,,,

i have to use crontab -e and add the second job.

after that do i need to execute
crontab secondjob
newunix
Frequent Advisor

Re: cron issue

can i have an example for particular user having one job already and to add another cron job.

Re: cron issue

>I have to use crontab -e and add the second job. after that do i need to execute: crontab secondjob

No, you keep using "crontab -e". Or you can use "crontab -l" and put that in a file and resubmit that file with your changes.

>can I have an example for particular user having one job already and to add another cron job.

Use "crontab -e" to edit your existing crontab entry. Then add as many as you want.

Note: One problem with "crontab -e" is that you don't have a backup if your disks crash and it isn't in a source management system.

So you could just start with a file and just add to it, then use "crontab file" each time.
Elmar P. Kolkman
Honored Contributor

Re: cron issue

newunix, what you want exactly what I described in the first reply...

If you want to do it for another user, you have to add the '-u ' option.

So:

$ crontab -l -u dummyuser >oldjobs
$ cat oldjobs newjobs | crontab -u dummyuser
Every problem has at least one solution. Only some solutions are harder to find.
rariasn
Honored Contributor

Re: cron issue

Hi:

# cd /var/spool/cron/crontabs

Save old cron.

# crontab -l > crontab.old

Modify crontab file:

# crontab -e

List crontab file:

# crontab -l

rgs,

Re: cron issue

>rariasn: # cd /var/spool/cron/crontabs

There is no need to go there unless you want to back up these files.
Also don't edit these files directly.
Jim Walls
Trusted Contributor

Re: cron issue

newunix,

As a new UNIX user/administrator you need to quickly learn that "man" is your best friend...

man crontab

... will give you the the answer you need.

djoshi
Frequent Advisor

Re: cron issue

I know it's a old thread.

hi newunix,

If you are creating cron like vi xyz.cron, after adding all jobs to xyz.cron, you have to use below command to activate above crontab.
crontab xyz.cron

If you are adding more cron jobs to xyz.cron edit in vi and then again use crontab xyz.cron to activate.

Thx,
madhuchakkaravarthy
Trusted Contributor

Re: cron issue

hi djoshi
!its better to use crontab -e instead of vi

Regards
Mc