Passing error message back to script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Passing error message back to script
# 1  
Old 06-27-2012
Passing error message back to script

I have one script that calls another script during execution. The other script does some processing, then either returns with exit 0 (if successful), or exits with error code numbers (if failed). However, in addition to the error code, I would like for that second script to be able to pass a message, in a string perhaps, to the initial script.

Would that be feasible?
# 2  
Old 06-27-2012
You can better returning the numbers only and use mappings with number and error description to recognize it.
# 3  
Old 06-27-2012
May be with command substitution.

Hint:
Code:
lem@biggy:/tmp$ cat file1
#!/bin/sh
false || echo "problem"
exit 0

lem@biggy:/tmp$ cat file2
#!/bin/sh
echo first
echo $(/tmp/file1)
echo last
exit 0

lem@biggy:/tmp$ ./file2
first
problem
last
lem@biggy:/tmp$

This User Gave Thanks to Lem For This Post:
# 4  
Old 06-27-2012
Simply source the called script, then all variables set there are available in the calling script too.
Code:
$ ./script1.sh
calling script 2
String: it works
Value: 1

$ cat script1.sh
echo calling script 2
. ./script2.sh
RET_VAL=$?
echo String: $RET_STRING
echo Value: $RET_VAL

$ cat script2.sh
RET_STRING="it works"
return 1
$

This User Gave Thanks to cero For This Post:
# 5  
Old 06-27-2012
Or ... read the output from the called script:

Code:
#script1
./script2 | read reply
echo "Reply is: ${reply}"

#script2
echo "Working"
exit 0

./script1
Reply is: Working


Last edited by methyl; 06-27-2012 at 10:09 AM.. Reason: improve example
This User Gave Thanks to methyl For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing control back to the shell script

Hi All, I have a shell script(test_abc.sh) with the following shell commands, which are invoking the same shell script with different parameters. test_abc.sh . ./test.sh abc >> test.log . ./test.sh xyz >> test.log . ./test.sh pys >> test.log . ./test.sh abc >> test.log . . ... (4 Replies)
Discussion started by: dev.devil.1983
4 Replies

2. Solaris

Mail loops back to me error in /var/adm/message after patching

Hi, I am getting the below messsage in /var/adm/message after patching but sendmail is working after restoring the backup file. sendmail: q4G7U1Cj014774: SYSERR(root): 127.0.0.1 config error: mail loops back to me (MX problem?) sendmail: q4G801cw025824: SYSERR(root): 127.0.0.1 config... (3 Replies)
Discussion started by: fayaz
3 Replies

3. Solaris

Message passing toolkit

Hello, Has somebody download it before oracle deleted from support section? I tried dl it from: oracle.com/us/products/tools/message-passing-toolkit-070499.html Oracle Message Passing Toolkit but: section decommissioned. Same in support and edelivery I phoned to oracle support and... (2 Replies)
Discussion started by: time0ut
2 Replies

4. Shell Programming and Scripting

Passing variable to Expression in back ticks.

Hi, In my perl script I want to check whether *.csv files exist and take the count . Below is the code: $path = “/home/usr/jan/myfiles” my $File_Count = `ls *.csv | wc -l `; # Checks in the current directory #Works fine if files exists. my $File_Count = `ls $path/*.csv | wc -l `; # I need... (2 Replies)
Discussion started by: jisha
2 Replies

5. Shell Programming and Scripting

Passing a variable from a child script back to the parent

Hi I have written a script using ftp to get files from one server and copy them to 2 dirrerent servers. I wish to call this script from a parent script that will check the number of files copied and run a check sum for each file. As the filenames for the files in the get portion of the script... (3 Replies)
Discussion started by: Andy82
3 Replies

6. UNIX for Advanced & Expert Users

Message passing to kerenel

i want to add a system call(successfuly added) and pass the message(which contains int and a string) /*code i used my program calling system call printmsg*/ message mm; mm.m1_i1=10; mm.m1_p1="hello"; printmsg(&mm); /*user library*/ printmsg(*m1) { printf("integer... (1 Reply)
Discussion started by: kathir_dz
1 Replies

7. Linux Benchmarks

What are the benchmark programs for Message passing?

Is there any benchmark programs for Message Passing like SPLASH-2 for Shared Memory. (0 Replies)
Discussion started by: gkreddy
0 Replies

8. Shell Programming and Scripting

passing oracle parameters back to Shell

Hi All, Does anyone have any solutions for passing back multiple variables back to the SHELL from a call to an ORACLE procedure: eg #username='scott' #password='tiger' #database='orcl' username='ITGCD03D03' password='tC5epIew' database='ITGCD03D' sqlplus -s... (4 Replies)
Discussion started by: satnamx
4 Replies

9. Programming

Passing Parameters and getting values back from a c program to Shell script

I am having a shell script which has to be called from a C program. I have to pass two parameters to this script. HOw can I do that? eg: int main() { char st1; char str2; // call a shell script call_sh(str1,str2) where call_sh is the name of the shell script. then i need to get the return... (5 Replies)
Discussion started by: Rajeshsu
5 Replies

10. Programming

how to passing message along pipes??

Dear All, Would you tell me how I can passing a message along pipes? I have built a token ring connected with pipes, but I don't know how to pass the message along it through the command line... Thx. Yours, i- (1 Reply)
Discussion started by: iminus
1 Replies
Login or Register to Ask a Question