- Community Home
- >
- Servers and Operating Systems
- >
- Legacy
- >
- Operating System - Tru64 Unix
- >
- How to return a value from a shell script on Linux...
Operating System - Tru64 Unix
1748216
Members
3490
Online
108759
Solutions
Forums
Categories
Company
Local Language
юдл
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
юдл
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-02-2008 07:08 PM
тАО10-02-2008 07:08 PM
How to return a value from a shell script on Linux to a calling program on Hp Tru64 UNIX
Hi All,
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.
Thanks
Aishwarya.
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.
Thanks
Aishwarya.
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-02-2008 07:56 PM
тАО10-02-2008 07:56 PM
Re: How to return a value from a shell script on Linux to a calling program on Hp Tru64 UNIX
What's "a calling program on HP Tru64 UNIX"?
Are you doing something like this on the
Tru64 system?:
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
exit $sts
you could write it back on stderr:
dy # cat test.sh
#!/bin/sh
echo "$1"
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'
sts=6
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
sts=6
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
stderr:
dy # remsh dy './test.sh fred' > /dev/null
./test.sh[3]: fred + fred : The specified number is not valid for this command.
Are you doing something like this on the
Tru64 system?:
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
exit $sts
you could write it back on stderr:
dy # cat test.sh
#!/bin/sh
echo "$1"
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'
sts=6
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
sts=6
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
stderr:
dy # remsh dy './test.sh fred' > /dev/null
./test.sh[3]: fred + fred : The specified number is not valid for this command.
- Tags:
- rsh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-03-2008 01:20 AM
тАО10-03-2008 01:20 AM
Re: How to return a value from a shell script on Linux to a calling program on Hp Tru64 UNIX
Hi Aishwarya,
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.
Cheers,
Rob
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.
Cheers,
Rob
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP