Sponsored Content
Top Forums Shell Programming and Scripting Need output of script on screen and file with correct return status of the called script. Post 302924962 by sea on Thursday 13th of November 2014 08:28:38 AM
Old 11-13-2014
You can set the return code to a variable so you can reuse it at any later time again.

Example - 1.sh
Code:
#!/bin/bash
echo "I'm script: $0" | tee -a ./1.log
[[ $UID -eq 34567 ]]
RET=$?
echo "The exit code was $RET, and now it can be re-used"
echo "Returned: $RET" | tee -a ./1.log

echo "Cat'ing:"
cat 1.log

Output:
Code:
sh 1.sh 
I'm script: 1.sh
The exit code was 1, and now it can be re-used
Returned: 1
Cat'ing:
I'm script: 1.sh
Returned: 1

Hope this helps
This User Gave Thanks to sea For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Redirecting to standard output from within called script

Hi, How to achieve this? Let us assume the following: There are 2 scripts a.ksh and b.ksh $ cat a.ksh sh b.sh 2>&1 >> /work/log/a_log.txt $ cat b.sh echo "abcd" My requirement is, is there a way to display this abcd in standard output also alongside of writing into a_log.txt?... (8 Replies)
Discussion started by: vigneshra
8 Replies

2. UNIX for Dummies Questions & Answers

Return info from a called external script

New to Unix scripting and have written two scripts, one calling the other. When it returns to the calling script is it possible to return information, like a return code? :confused: (1 Reply)
Discussion started by: cathrop
1 Replies

3. UNIX for Dummies Questions & Answers

how to print script output to screen and file

Hi all, I have a script that bulk loads thousands of lines of data. I need to log the output during the execution of the script. I know I can redirect (">") the output to a file; however, I want the output going to both the screen and the log file. I thought I could use pipe to pipe the... (10 Replies)
Discussion started by: orahi001
10 Replies

4. Shell Programming and Scripting

How to return the value from the called shell script to the calling sh script

Hi all, I have two ksh scripts #sample1.sh #!/bin/ksh . ./sample2.sh echo $fileExist #sample2.sh #!/bin/ksh func() { i=1 return $a } func echo $? Here how should I return the value of sample2.sh back to sample1.sh? Thanks in advance. (2 Replies)
Discussion started by: gp_singh
2 Replies

5. Shell Programming and Scripting

return status after run the shell script

Hello, I wanted to delete all files which are placed 14 days back. Here is my below script. My script works very well and it deletes all files 14 days back. I wanted to display message incase if the delete script is not successful. The below script returns always successful. But the directory... (6 Replies)
Discussion started by: govindts
6 Replies

6. Shell Programming and Scripting

Not the correct output, works fine via CLI, not inside the script.

Guys, I need you help please. The script below is not working correclty for checking via a awk/if statement . Can you tell me what i am doing wrong in the script code "if($1 == "$RETENTION_LEVEL") " Syntax RETENTION_LEVEL=`echo $LINE | cut -f2 -d" "` echo " ==============... (4 Replies)
Discussion started by: Junes
4 Replies

7. Shell Programming and Scripting

Return value to shell script, depending on status of pl/sql udpate

Hi All, I need to return value to the main shell script, depending on whether the UPDATE command in the embedded pl/sql is successfu or not. #!bin/ksh updateStatus=`sqlplus --conn details-- << EOF DECLARE var_rows NUMBER; BEGIN update table_name set column_name =... (7 Replies)
Discussion started by: rituparna_gupta
7 Replies

8. Shell Programming and Scripting

Script will keep checking running status of another script and also restart called script at night

I am using blow script :-- #!/bin/bash FIND=$(ps -elf | grep "snmp_trap.sh" | grep -v grep) #check snmp_trap.sh is running or not if then # echo "process found" exit 0; else echo "process not found" exec /home/Ketan_r /snmp_trap.sh 2>&1 & disown -h ... (1 Reply)
Discussion started by: ketanraut
1 Replies

9. Shell Programming and Scripting

Output not in correct format - cd script

I have a script that looks like this: dirname2=/usr/tmp/filelist/*/* for dirname2 in /tmp/filelist/*/*; do (cd $dirname2/catalog ||echo "file does not exist" && echo "$dirname2" |cut -d '/' -f 7,8 && echo $i && ls -la |awk 'NR>3 {SUM += $5} END { print "Total number of kb " SUM }');done... (2 Replies)
Discussion started by: newbie2010
2 Replies

10. Shell Programming and Scripting

Shell script to pass the config file lines as variable on the respective called function on a script

I want to make a config file which contain all the paths. i want to read the config file line by line and pass as an argument on my below function. Replace all the path with reading config path line by line and pass in respective functions. how can i achieve that? Kindly guide. ... (6 Replies)
Discussion started by: sadique.manzar
6 Replies
CONFMODULE(3)						     Library Functions Manual						     CONFMODULE(3)

NAME
confmodule - communicate with Debian configuration system FrontEnd. SYNOPSIS
#!/bin/sh -e . /usr/share/debconf/confmodule db_version 2.0 db_capb 'backup' CAPB=$RET db_input 'foo/bar' || true db_go || true DESCRIPTION
This is a library of shell functions that eases communication with Debian's configuration management system. It can communicate with a FrontEnd via the debconf protocol. The design is that each command in the protocol is represented by one function in this module. The func- tionname is the same as the command, except it is prefixed with "db_" and is lower-case. Call the function and pass in any parameters you want to follow the command. Any textual return code from the FrontEnd will be returned to you in the $RET variable, while the numeric return code from the FrontEnd will be returned as a return code (and so those return codes must be captured or ignored). NOTES
Once this library is loaded, any text you later output will go to standard error, rather than standard output. This is a good thing in gen- eral, because text sent to standard output is interpreted by the FrontEnd as commands. If you do want to send a command directly to the FrontEnd, you must output it to file descriptor 3, like this: echo GET foo/bar >&3 The library checks to make sure it is actually speaking to a FrontEnd by examining the DEBIAN_HAS_FRONTEND variable. If it is set, a Fron- tEnd is assumed to be running. If not, the library turns into one, and runs a copy of the script that loaded the library connected to it. This means that if you source this library, you should do so very near to the top of your script, because everything before the sourcing of the library may well be run again. SEE ALSO
debconf-devel(7), dpkg-preconfigure(8), dpkg-reconfigure(8), debconf_specification in the debian-policy package AUTHOR
Joey Hess <joeyh@debian.org> CONFMODULE(3)
All times are GMT -4. The time now is 07:51 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy