Operating System - HP-UX
1753318 Members
6225 Online
108792 Solutions
New Discussion юеВ

Re: cron question about multiple commands

 
SOLVED
Go to solution
Jeroen_D
Regular Advisor

cron question about multiple commands

Hi,

we are using fbackup to backup our data to tape. We find its logging insufficient so we want to read the tape afterwards and create a file which contains the names of everything on the tape.

Is this a good way:
45 18 * * 1-4 /etc/fbackup -c /ses/backup_config -0 -g /ses/daily_backup -V/tmp/cron/backup_result -f/dev/rmt/0m ; /etc/frecover -I /tmp/cron/backup_result_index ; mt offl
45 18 * * 5 /etc/fbackup -c /ses/backup_config -0 -i/ -V/tmp/cron/backup_result -f/dev/rmt/0m ; /etc/frecover -I /tmp/cron/backup_result_index ; mt offl


The question I have is: will the commands after the ";" be executed ONLY when the previous command has completed?

Maybe a simple question, but I need to be sure.

TIA,
Jeroen.
9 REPLIES 9
Sanjay_6
Honored Contributor

Re: cron question about multiple commands

Hi Jeroen,

Normally any command after ";" is supposted to run after the previous command has completed.

Hope this helps.

Regds
Pete Randall
Outstanding Contributor

Re: cron question about multiple commands

Jeroen,

Yes, that's true.


Pete

Pete
Patrick Wallek
Honored Contributor
Solution

Re: cron question about multiple commands

Yes. If you have a list of commands separated by a semicolon, they will be executed sequentially.

# date ; sleep 30 ; date

The above would display the date, sleep 30 seconds and display the date again.

Note that the commands would be executed no matter what. This means that is the first command fails, the next will be executed anyway.

If you want the execution of the 2nd command to be based on the successful (return code of 0) execution of the first, use a && separator.

# date && sleep 2 && date

Fred Ruffet
Honored Contributor

Re: cron question about multiple commands

"echo ; ls" will execute both echo and ls, whatever is echo exit code.

"echo && ls" will execute ls only if echo exit code is 0.

Maybe you should do a script. Complex lines in crontab make it not clear and harder to maintain.

Regards,

Fred
--

"Reality is just a point of view." (P. K. D.)
Tom Danzig
Honored Contributor

Re: cron question about multiple commands

Have you tried fbackup with the -v option? I would think this would give you what you want as far as logging of backup info is concerned without having to run the frecover process.

Just a thought.
Michael Schulte zur Sur
Honored Contributor

Re: cron question about multiple commands

Hi Jeroen,

it will start after the preceding command has finished for good or bad. If you want to garuantee that the next command runns only in case of successful completion then use && as delimiter. see man sh-bourne

greetings,

Michael
Ian Dennison_1
Honored Contributor

Re: cron question about multiple commands

Jereon,

Ummm, several commands together - why not put them in a script? Test the outcome of each previous command (using either $? or capture the standard output and check for error messages) before executing the next one?

Share and Enjoy! Ian
Building a dumber user
Michael D. Zorn
Regular Advisor

Re: cron question about multiple commands

I use -I indexfile with fbackup. That writes the filenames to 'indexfile' (I make the name from 'date' to keep the logs separate. If you're doing daily backups you could have 5 files - "index.mon" through "index.fri").

#commandA ; commandB
will run them in sequence.

A matter of style: I'd put the commands in a script and call the script from cron - here's mine:

15 23 * * 5 /var/adm/fbackupfiles/backup.users.cart

Here's the guts of the script (runs in ksh):

fbackup -f $CART -0u \
-g ${FBDIR}/Graphs/graph.FullUsers \
-V ${FBDIR}/Headers/U$(date "+%y%m%d") \
-c ${FBDIR}/config \
-I ${FBDIR}/Indices/users.$(date "+%y%m%d")
ERRN=$?

if [ $ERRN = 0 ]
then
mailx -s "Weekly users backup done" $SYSMAIL << EOF
EOF

else
mailx -s "Weekly backup failed" $SYSMAIL < /dev/null
fi

Whenever I forget to put a tape in the drive, I get message #2

If there's a concern that the backup might complete and the tape is still bad, your plan is good (do an actual frecover).

Recently, though, I've had a backup tape with an end-of-reel problem - it "wouldn't sync". Last year I made 2 separate backups of all the filesystems. This year neither of the tapes I needed were good. (But it might be the drives.)

In that case, I'd probably get a good Index file off the tape and still not be able to recover.

For archival (doomsday) backups I'm going to ftp the files to a machine where I have a CD writer (a Dell PC) and put them on CD. (If I ever get to 11.x things might be easier.
Jeroen_D
Regular Advisor

Re: cron question about multiple commands

Hi guys,

thanks for the massive replies!

Jeroen.