General
cancel
Showing results for 
Search instead for 
Did you mean: 

scheduling the cron jobs with the use of operands

SOLVED
Go to solution
simma100
Occasional Contributor

scheduling the cron jobs with the use of operands

Need to schedule the cronjob, like i am having 2 scipts on my crontab. if 1st job completed successfully then the 2nd job need to start. Is there any operands can we use for that. Please let me know if any options are there.

 

Thanks!

Simhan

14 REPLIES
Dennis Handly
Acclaimed Contributor

Re: scheduling the cron jobs with the use of operands

You only have the first script in your crontab.  If successful, the first script can start the next.

 

Or have three scripts.  The new one starts the first and if successful, starts the next.

Stephan_
Regular Advisor

Re: scheduling the cron jobs with the use of operands

Hi,

create a script f.e. cronscript.sh

 

/path/to/first/script && /path/to/second/script

 

 

add the following line to your crontab (Change times)

 

*   *    *    *    *    /path/to/cronscript.sh

 

Or you can enter that line directly into the crontab, using && will only execute the second command if the return code of the first one was zero.

 

hth

Stephan

 

How to assign points on this new forums --> Kudos - what, where, how, and why!
How to find the right forum --> New forum location by ITRC tree

"we wouldn't call it code, if we could read it ..."
simma100
Occasional Contributor

Re: scheduling the cron jobs with the use of operands

Hello Stephen,

 

If i  want to scedule the ignite backup once the tape drive is rewinded

 

0 5 11 6 /usr/sbin/mt -t /dev/rmt/omn rewind && * * * * /usr/sbin/make_tape_recovery -A -i -v inc_entire=/dev/vg00 /dv/rmt/0mn

 

Is that right.. Please correct me if i am wrong.

Dennis Handly
Acclaimed Contributor

Re: scheduling the cron jobs with the use of operands

>If I  want to schedule the ignite backup once the tape drive is rewound

 

In this case you shouldn't have separate commands in crontab.  Instead create one script that does the rewind, waits, then does the ignite.

Stephan_
Regular Advisor

Re: scheduling the cron jobs with the use of operands


simma100 wrote:

Hello Stephen,

 

If I  want to schedule the ignite backup once the tape drive is rewinded

 

0 5 11 6 /usr/sbin/mt -t /dev/rmt/omn rewind && * * * * /usr/sbin/make_tape_recovery -A -I -v inc_entire=/dev/vg00 /dv/rmt/0mn

 

Is that right.. Please correct me if I am wrong.


Hi again,
0 5 11 6 /usr/sbin/mt -t /dev/rmt/omn rewind && /usr/sbin/make_tape_recovery -A -I -v 

 

This should work, or as mentioned before create separate scripts for it.

 

Best,

Stephan

How to assign points on this new forums --> Kudos - what, where, how, and why!
How to find the right forum --> New forum location by ITRC tree

"we wouldn't call it code, if we could read it ..."
simma100
Occasional Contributor

Re: scheduling the cron jobs with the use of operands

so stephen, don't want to mention the tape device file at the last in the ignite command ?
Stephan_
Regular Advisor
Solution

Re: scheduling the cron jobs with the use of operands

Ups,

sorry of course you should add it - seems i did not copy all, to finalize

 

0 5 11 6 /usr/sbin/mt -t /dev/rmt/omn rewind && /usr/sbin/make_tape_recovery -A -I -v inc_entire=/dev/vg00 /dv/rmt/0mn

 

Best,

Stephan

How to assign points on this new forums --> Kudos - what, where, how, and why!
How to find the right forum --> New forum location by ITRC tree

"we wouldn't call it code, if we could read it ..."
simma100
Occasional Contributor

Re: scheduling the cron jobs with the use of operands

Thanks stephen.. i got that one.. again thanks a ton... :)
Bill Hassell
Honored Contributor

Re: scheduling the cron jobs with the use of operands

Actually, there are a lot of problems with just a rewind and trying to run the backup with a one-liner. Here are the things that need to be checked before you start the Ignite backup:

 

  • Is the device file really a tape?
  • Is there a tape inserted in the drive?
  • Is the tape write-protected?
  • Is the tape busy with another program?

Now the make_tape_recovery program can be run. Additionally, the steps above and the MTR command should be logged in case of a problem and ideally, an email sent to the system administrators. I have attached a script that accomplishes all of these tests and writes the results into the file /var/adm/mtr.log. You can store the file in /usr/contrib/bin/mtr and schedule it in cron like this:

 

1 1 * * 0 /usr/contrib/bin/mtr /dev/rmt/0mn admins@mycompany.com

 

That above will run the backup every Sunday at 1:01am.



Bill Hassell, sysadmin
Stephan_
Regular Advisor

Re: scheduling the cron jobs with the use of operands

Is it me or is the attachment missing?

 

Thanks,

Stephan

How to assign points on this new forums --> Kudos - what, where, how, and why!
How to find the right forum --> New forum location by ITRC tree

"we wouldn't call it code, if we could read it ..."
Bill Hassell
Honored Contributor

Re: scheduling the cron jobs with the use of operands

Attachments don't seem to be working...the post is rejected without comment when I add an attachment.

 

Here is a link where you can download the file:

 

ftp://ftp.sourcedirect.com/contrib/mtr

 



Bill Hassell, sysadmin
Stephan_
Regular Advisor

Re: scheduling the cron jobs with the use of operands

Actually after some testing - it looks like only picture extensions are allowed to attach.

 

I will open a thread in the Feedback area about it.

 

Thanks,

Stephan

How to assign points on this new forums --> Kudos - what, where, how, and why!
How to find the right forum --> New forum location by ITRC tree

"we wouldn't call it code, if we could read it ..."
Steven E. Protter
Exalted Contributor

Re: scheduling the cron jobs with the use of operands

Shalom,

The best way to make a two script process have step two wait for step 1 to be done is to control it with a single script.

script.ksh
!#/usr/bin/ksh
echo "Steve was here"
rc=$?
if [ $rc -eq 0 ]
then
echo "Ready to run second process"
# insert second script name here, full path
else
echo "First step failed. Do not pass go, do not collect $200"
fi
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Bill Hassell
Honored Contributor

Re: scheduling the cron jobs with the use of operands

It turns out that only PC-safe files are allowed as attachments...that is, abc.txt is OK but abc is not. The Lithium engine 'adds' the extension .wht to a no-extension filename. So my mtr script is presented here as mtr.txt. Feel free to rename it to a more Unix-like filename.

 

(finding posted to the Community feedback page)



Bill Hassell, sysadmin