Operating System - HP-UX
1833934 Members
1761 Online
110063 Solutions
New Discussion

Scripting question on HP-UX 11

 
SOLVED
Go to solution
Carlo Henrico_1
Regular Advisor

Scripting question on HP-UX 11

I have a script with the following 2 statements (amongst others):

1. find *.arc | cpio -pdmx /nfs_mounted_dir
2. mv *.arc finalised

Is it possible that statement 1 is not yet finished before statement 2 is processed?

Besides a "sleep", is there some other way to ensure 1 is finished before 2 is executed? How do I test for the cpio's return code for example?

Thanks

Carlo
Live fast, die young - enjoy a good looking corpse!
8 REPLIES 8
Stefan Farrelly
Honored Contributor

Re: Scripting question on HP-UX 11


No, its not possible 2. will run until the command in 1. is done. Its strictly sequential.

You can test the return status with;
[ $? -ne 0 ] && echo previous command failed

You could ensure 1. is finished with a return code of 0 before running 2. by changing your script to;

find *.arc | cpio -pdmx /nfs_mounted_dir
if [ $? -eq 0 ]
then
mv *.arc finalised
else
echo find command failed, didnt run mv
fi
Im from Palmerston North, New Zealand, but somehow ended up in London...
Justo Exposito
Esteemed Contributor

Re: Scripting question on HP-UX 11

Hi Carlo,

If you have an script with this two steps there is no posible that the second step start until the first finished.

You can check if a command run ok with the shell variable $? if this variable is cero it's fine. Example:

if [ $? = 0 ]
then
mv *.arc finalised
else
echo "error in the CPIO step"
fi

Hope this helps,

Justo.

Help is a Beatiful word
James Beamish-White
Trusted Contributor

Re: Scripting question on HP-UX 11

Hiya Carlo,

No, the first statement should complete before moving on to the next statement.

To test for the return code of a previous statement, use $? i.e.

if [ $? = 0 ]; then
echo Previous statement worked fine.
fi

Cheers!
James
GARDENOFEDEN> create light
harry d brown jr
Honored Contributor
Solution

Re: Scripting question on HP-UX 11

Step one (1) will finish BEFORE step two (2), BUT you might be experiencing data buffering from the find into cpio because of the NFS mounted directory, so a sleep of 5 to 60 seconds should work, depending upon the speed of the NFS mount.

Is "finalised" a directory?

live free or die
harry
Live Free or Die
Carlo Henrico_1
Regular Advisor

Re: Scripting question on HP-UX 11

Yes, finalised is a directory. What I am finding is that the file is under finalised but not on the nfs directory (100MB link speed).

I will try the return codes and come back with points. Thanks guys.

Cheers

Carlo
Live fast, die young - enjoy a good looking corpse!
Ralph Grothe
Honored Contributor

Re: Scripting question on HP-UX 11

If you want some sort of synchronosity in the shell you can send job 1 in the background by appending a "&" to the command, and continue with job 2.
You assure that job 2 waits for the forked background job by the "wait" call (see man wait).
In a more capable language such as C or Perl you would do a fork(), exec(), wait() or waitpid().
Madness, thy name is system administration
harry d brown jr
Honored Contributor

Re: Scripting question on HP-UX 11

Carlo,

Try a quick test with a simple change to your script by replacing the NFS directory with a LOCAL directory.

Also, is the output (STDOUT & STDERR) redirected in any way?

live free or die
harry
Live Free or Die
harry d brown jr
Honored Contributor

Re: Scripting question on HP-UX 11


Carlo,

The forum has a new feature that allows you to view any past QUESTIONS you have posted, which allows you to find replies that you haven't acknowledged.

This member has assigned points to 78 of 128 responses to his/her questions.

http://forums.itrc.hp.com/cm/TopSolutions/1,,BR170913!1!questions,00.html


live free or die
harry
Live Free or Die