- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: pass the return status of perl script to shell...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
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
Community
Resources
Forums
Blogs
- 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
тАО04-28-2008 06:18 AM
тАО04-28-2008 06:18 AM
pass the return status of perl script to shell script
I am calling a perl script to ftp files from one server to another server and I want the exit status of the perl script to be passed to the calling shell script so tht I can send success or failure mail from shell script
- Tags:
- exit status
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-28-2008 06:49 AM
тАО04-28-2008 06:49 AM
Re: pass the return status of perl script to shell script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-28-2008 06:58 AM
тАО04-28-2008 06:58 AM
Re: pass the return status of perl script to shell script
As with any process, exit with the value you wish to propagate to the caller.
In this case, your Perl script "knows" the status of the FTP action. For example:
...
$ftp->login() or die "Can't login!";
...
In this case, the 'die' causes the Perl script to exit with a non-zero return status.
If you want to handle other conditions and exit later, set a variable with some return code and simple 'exit($lastaction)'.
In any case, your shell wrapper can then test the '$?' variable for the result of the Perl script just like any command's return status.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-28-2008 08:51 AM
тАО04-28-2008 08:51 AM
Re: pass the return status of perl script to shell script
besides checking the variable $?, you can directly use something like the following in your shell script, when no further handling of the exit-status is required:
#!/usr/bin/sh
...
if my-perl-script.pl arg1 arg1;
then # further processing
print OK
else
print -u2 ERROR in xxx
exit 1
fi
...
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-28-2008 08:57 AM
тАО04-28-2008 08:57 AM
Re: pass the return status of perl script to shell script
small additions:
- you could drop the ';' at the end of the 'if' condition
- you could pass $? to the calling environment of the shell script
#!/usr/bin/sh
...
if my-perl-script.pl arg1 arg1
then # further processing
print OK
else
print -u2 ERROR in xxx
exit $?
fi
...
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-29-2008 02:11 AM
тАО04-29-2008 02:11 AM
Re: pass the return status of perl script to shell script
Better yet, keep it and do:
if ... ; then
>you could pass $? to the calling environment of the shell script
I'm not sure this will work. The print will destroy $?.
my-perl-script.pl arg1 arg1
result=$?
if [ $result -eq 0]; then # further processing
print OK
else
print -u2 ERROR in xxx
exit $result
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-29-2008 02:18 AM
тАО04-29-2008 02:18 AM
Re: pass the return status of perl script to shell script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-29-2008 03:14 AM
тАО04-29-2008 03:14 AM
Re: pass the return status of perl script to shell script
Dennis is right - either print or pass the exit status:
EITHET THIS:
#!/usr/bin/sh
...
if my-perl-script.pl arg1 arg1
then # further processing
print OK
else
print -u2 ERROR $? in xxx
exit 1
fi
...
OR THIS:
#!/usr/bin/sh
...
if my-perl-script.pl arg1 arg1
then # further processing
print OK
else
exit $?
fi
...
mfG Peter