10-02-2008 07:08 PM
I am trying to return a value to a calling program on HP Tru64 UNIX from a shell script on Linux. In the program on linux, I use FTP to get a file and handle errors like unable to login etc. These errors are handled by doing a grep on the log file for "Unable to login" text and assigning a value to a variable called Login a value of 1 if the process could not login to the FTP Site. When this error occurs, I do a exit 1 but befor doing this, I want to return a value to the calling program to indicate that this process has failed and would like to use this returned value in the calling program to echo a message saying that the program has failed. How can I achieve this? Please advise.
10-02-2008 07:56 PM
Are you doing something like this on the
rsh linux_host shell_script [args]
If so, then on the Tru64 system, the exit
status from the rsh command won't tell you
what the exit status was from the remote
command, so, as you've seen, "exit 1" there
does nothing for you.
The remote script _can_ write text to stdout
and/or stderr, and this can be examined by
the person or process which does the rsh.
For example, instead of
you could write it back on stderr:
dy # cat test.sh
sts=$(( "$1" + "$1" ))
echo "sts=$sts" >&2
(I have an HP-UX system up at the moment, so
pretend that "remsh" is "rsh".)
dy # remsh dy './test.sh 3'
Here, the "3" was on stdout, and "sts=6" was
on stderr. If we redirect stdout:
dy # remsh dy './test.sh 3' > /dev/null
then only the status string is seen.
The best way to do this may depend on what
the remote script is doing with stdout and
stderr now. If nothing, then you can do
practically anything you wish. One advantage
to using stderr for the status string is that
complaints from real problems will also go to
dy # remsh dy './test.sh fred' > /dev/null
./test.sh: fred + fred : The specified number is not valid for this command.
10-03-2008 01:20 AM
I'm not entirely sure how you're running things, however searching a log file for errors is likely to give you problems.
If I were you I would rewrite the script in Perl, using the Net::FTP module. This allows for much better error handling.