How to capture the exit code of a shell script in a perl script.?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to capture the exit code of a shell script in a perl script.?
# 1  
Old 08-26-2013
How to capture the exit code of a shell script in a perl script.?

hi,

i want to pop up an alert box using perl script. my requirement is.
i am using a html page which calls a perl script. this perl script calls a shell script.. after the shell script ends its execution, i am using exit 0 to terminate the shell script successfully and exit 1 to terminate the shell script when an error occurs in the shell script. i want to capture this exit code in the perl script. and depending on the value 0 or 1, i want to pop up an alert box with success or failure message respectively. any1 is having any idea. its urgent please..
# 2  
Old 08-26-2013
use system() method of perl
# 3  
Old 08-26-2013
ya i used system(), but i need to generate the output of the shell script to a log file also. i do not know how to send the output of the shell script to a log file from system command.

Code:
$return = system("sh", "shell_script.sh", $NAME, $FileName);

i want to send the output to a log file..

Code:
$return = system("sh", "shell_script.sh", $NAME, $FileName, >/app/home/$NAME/output.log, 2>/app/home/$NAME/error.err);

but the command gives an error.

ok i got the where i did wrong.. i need to include ">/app/home/$NAME/output.log" and "2>/app/home/$NAME/error.err" in double quotes.

---------- Post updated at 03:30 PM ---------- Previous update was at 03:23 PM ----------

no, its not creating a log file.

Last edited by Little; 08-26-2013 at 06:58 AM..
# 4  
Old 08-26-2013
It works fine for me

Code:
[root@www test]# ll
total 16
-rw-r--r-- 1 root root  0 Aug 26 23:19 error.err
-rw-r--r-- 1 root root  0 Aug 26 23:19 output.log
-rwxr-xr-x 1 root root 96 Aug 26 23:19 script.pl
-rwxr-xr-x 1 root root 48 Aug 26 23:18 script.sh
 
[root@www test]# 
[root@www test]# 
[root@www test]# cat script.sh
#!/bin/bash
echo stderr >&2
echo hello
exit 0
[root@www test]# cat script.pl
#!/usr/bin/perl
 
my $ret = system("./script.sh > output.log 2> error.err");
$ret = $ret >> 8;
print "$ret\n";
 
[root@www test]# perl script.pl
0
[root@www test]# cat error.err
stderr
[root@www test]# cat output.log
hello
[root@www test]#


Last edited by MR.bean; 08-26-2013 at 10:25 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Exit code 267 from shell script

Hi, We have a problem in Linux (GNU/Linux 3.10.0-693.1.1.el7.x86_64) with a shell script returning 267 as return code. The script, load_flag.sh is called from main_script.sh (both script samples given below). The exit code from load_flag.sh is used to decide whether to continue execution of... (1 Reply)
Discussion started by: Arunnath
1 Replies

2. Shell Programming and Scripting

Capture run time of python script executed inside shell script

I have bash shell script which is internally calling python script.I would like to know how long python is taking to execute.I am not allowed to do changes in python script.Please note i need to know execution time of python script which is getting executed inside shell .I need to store execution... (2 Replies)
Discussion started by: Adfire
2 Replies

3. Shell Programming and Scripting

How to capture exit code of child script and send it to parent script?

#!/usr/local/bin/bash set -vx /prod/HotelierLinks/palaceLink/bin/PalacefilesWait /prod/HotelierLinks/palaceLink/bin/prodEnvSetup 03212013 & if then echo "fatal error: Palace/HardRock failed!!!!" 1>&2 echo "Palace Failed" | mail -s "Link Failed at Palace/HardRock" -c... (1 Reply)
Discussion started by: aroragaurav.84
1 Replies

4. Shell Programming and Scripting

Exit code from piping in unix shell script

Hi , I have following code in my shell script : "$TS_BIN/tranfrmr" "${TS_SETTINGS}/tranfrmr_p1.stx" "${TS_LOGS}/tranfrmr_p1.err" | ( "$TS_BIN/cusparse" "${TS_SETTINGS}/cusparse_p2.stx" "${TS_LOGS}/cusparse_p2.err" | ( "$TS_BIN/tsqsort" "${TS_SETTINGS}/srtforpm_p3.stx"... (8 Replies)
Discussion started by: sonu_pal
8 Replies

5. Shell Programming and Scripting

How to grep sql error in shell script and exit the script?

I need help in the following script. I want to grep the sql errors insert into the error table and exit the shell script if there is any error, otherwise keep running the scripts. Here is my script #!/bin/csh -f source .orapass set user = $USER set pass = $PASS cd /opt/data/scripts echo... (2 Replies)
Discussion started by: allinshell99
2 Replies

6. Shell Programming and Scripting

convert perl code to shell script

This is about how to Monitoring folder for new files using shell script im doing a project using smsserver tools 3. i have used a perl script to handle incoming messages. the content of each message must be directed to a java program. this program generates the answer to reply to the user... (2 Replies)
Discussion started by: x34
2 Replies

7. Shell Programming and Scripting

Capture unexpected exit in shell script

Hi, I have shell script that checks processes forever. But somehow it is killed and I want to know what causes it. while do check the processes if they are running, if not restart them done I want to capture the output when the script is terminated, how can I do that? /Andreas (2 Replies)
Discussion started by: mr_andrew
2 Replies

8. UNIX for Dummies Questions & Answers

How to capture exit code for a bg job

If I execute a job in background (in ksh or bash), how would I capture the exit code for that job? Thanks, - CB (1 Reply)
Discussion started by: ChicagoBlues
1 Replies

9. Shell Programming and Scripting

How to run perl code within a shell script...?

Hi, I have a sheel script that invokes a perl script...Now, instead havin the perl script as a separate file I'd like put the contents in the sheel script itself...But I am not sure how ro run that perl script contents.please help me Thanks (1 Reply)
Discussion started by: vijay_0209
1 Replies

10. Shell Programming and Scripting

Capture Oracle return code in shell script

I am using the following code in my shell script list=`sqlplus -s $user/$pwd@$dbms<<EOF WHENEVER SQLERROR EXIT SQL.SQLCODE set pagesize 0 feedback off verify off heading off echo off select * from control_tbl where src_nm=$3 and extrct_nm=$4; exit SQL.SQLCODE; EOF` ERROR=$?... (1 Reply)
Discussion started by: Vikas Sood
1 Replies
Login or Register to Ask a Question