Getting the return code of a backgrounded process
Hello all...
Been a while since I've posted here, but nice to be back. I'm writing a C shell script that will write a directory to two tape drives at the same time as part of an archive system (one of the tapes goes offsite, the other stays local). In the script, I want to get the return code from tar which I know I can do by something like: Code:
tar -cvf /dev/st0 somedir Code:
tar -cvf /dev/st0 somedir & Any help much appreciated. |
do want the exit code or just if it failed or not ?
Code:
tar -cvf /dev/st0 somedir && status1=0 & Code:
tar -cvf /dev/st0 somedir && status1=$? & |
i meant
Code:
tar -cvf /dev/st0 somedir ;status1=$? & |
You're right, $? is Bash, but $status should work in csh.
Never thought of simply concatenating the commands together DOH!!! Sometimes you miss the obvious when you've been staring at code all day :) Many thanks, I'll give it a try :D |
Close but no cigar...
The problem with doing it like that (and it makes sense when you think about it) is that the two tar commands won't run at the same time, it executes one at a time. Since I'm writing 200GB data to each tape, I want to make full use of my twin LTO drive unit. Any more suggestions? PS. On another note, I've switched all my scripts to bash as it seems a lot more predictable than C!! |
what if you make each command a bash script and run each in the back ground ?
output the status to a file or the screen. |
After lots of searching on the net, it seems that getting exit codes of multiple forks is no mean feat!! So, I've come up with a workaround to have my original script call another script that stores the exit code in a file.
Here's an example: Code:
#!/bin/bash Code:
#!/bin/bash I'm still open to suggestions... Gaz. |
Quote:
We must have been posting at the same time. Gaz. |
All times are GMT -5. The time now is 05:32 PM. |