Thanks.
My bash version is: ---------- Post updated at 07:06 PM ---------- Previous update was at 06:58 PM ----------
Quote:
Originally Posted by sea
You can set the return code to a variable so you can reuse it at any later time again.
Example - 1.sh
Output:
Hope this helps
Thanks for your reply.
I am calling child script from parent script and I want to capture the exit status of the child script into main script. Can I store exit status of child script in variable and use it in parent script?
I know that, we can export variable from parent script and use its value in child script but does it work other way?
That case is about the same:
Or likewise:
or even:
Quote:
Can I store exit status of child script in variable and use it in parent script?
Not unless you export the variable, in which case, they must not have the same name, or you can just fetch the latest 'output/export'.
However, you could read the logfile for sure.
That case is about the same:
Or likewise:
or even:
Not unless you export the variable, in which case, they must not have the same name, or you can just fetch the latest 'output/export'.
However, you could read the logfile for sure.
hth
I want to catch the output of the $script in log file (both stdout and stderr). How can I do that?
If I use tee command to capture both stdout and stderr like below, I loose the exit status.
Last edited by Prathmesh; 11-13-2014 at 10:12 AM..
Reason: included code to explain myself better
I wrote a database backup script where I have exec in the script redirecting stdout and stderr in the script to a log file. Hence, when I run the script I don't see any output. But I can run the script as "nohup ./myscript.sh &" then I just tail -f on the log file to see exactly what it is doing. I tried using tee in the past to split the output, but could not get it working either. Maybe a newer bash version would work fine...
Suppose we do not have control over the script which we are calling $script in this case. And it has only echo commands and it is not saving output to any file, only displaying output on terminal. But, we need to capture whatever output of echo command it is displaying in the main script (from where we are calling $script ) on screen terminal as well as in the file. Then how can we do it?
I wrote a database backup script where I have exec in the script redirecting stdout and stderr in the script to a log file. Hence, when I run the script I don't see any output. But I can run the script as "nohup ./myscript.sh &" then I just tail -f on the log file to see exactly what it is doing.
This is really the preferred way to do it -- from the outside. Complicated schemes with pipes, tees, and fifos are liable to break down, subject to deadlocks, and can make your script dependent on a terminal: Untrustworthy and not worth the trouble. Even 99% success is not good enough. Putting in pipes also messes up the ordering, increases overhead manyfold, and can screw up your terminal prompt afterwards.
When redirecting it from the outside through tee, since you are using BASH, just check the script's return status in PIPESTATUS:
PIPESTATUS is even updated for a single command, so ${PIPESTATUS[0]} remains safe either way, as long as you're using BASH.
Last edited by Corona688; 11-13-2014 at 12:03 PM..
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)