[SOLVED] Problem in wait statement


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [SOLVED] Problem in wait statement
# 8  
Old 12-04-2012
It's getting stuck on wait? That makes sense, since it's not about to die. Okay then, you can remove it from the shell's control with disown.

Of course, this means you'll have to make sure you kill this process yourself when the shell quits, since it won't be under the shell's control any more. Closing the output pipe will probably do it, but if it hangs, wait a second then kill it.

Code:
( exec tee -a $OUT_LOG < $OUT_PIPE >&3 ) &
PID="$!"
disown
trap "exec 1>&-; exec 2>&-; sleep 1 ; kill $PID" EXIT

# 9  
Old 12-05-2012
Hi Corona,

The script runs fine after this but i didn't found any DB Logs.Their was no log file created in the required folder.The script went fine on the terminal only.Smilie


Thanks
Vikram
# 10  
Old 12-05-2012
This works here:

Code:
#!/bin/sh

function init_stdout_redirect {
    OUT_LOG=$1
    OUT_PIPE=$(mktemp -u)

    # Create the output pipe
    mkfifo $OUT_PIPE

    # Save stdout and stderr as 3 and 4
    exec 3>&1 4>&2

    # Tee the output pipe into the log file
    ( exec tee -a $OUT_LOG < $OUT_PIPE >&3 ) &

    # Save tee's pid
    TEE_PID=$!

    trap "exec 2>&-; exec 1>&-; sleep 1 ; kill ${TEE_PID} ; rm -f ${OUT_PIPE}" EXIT

    # Redirect the output to the pipe
    exec > $OUT_PIPE 2>&1
 }

init_stdout_redirect log.file

echo asdf
echo qwertyuiop>&2
exit

The data shows up on screen and in the log file.
# 11  
Old 12-06-2012
Iam afraid to tell its not working yet. Iam attaching the logs and the script which iam using.

+ init_stdout_redirect /apps/psr/database/logs/env53b_Refresh_2012-12-05-2346.log
+ OUT_LOG=/apps/psr/database/logs/env53b_Refresh_2012-12-05-2346.log
++ mktemp -u
+ OUT_PIPE=/tmp/tmp.XGCWt20093
+ mkfifo /tmp/tmp.XGCWt20093
+ exec
+ TEE_PID=20105
+ trap 'exec 2>&-; exec 1>&-; sleep 1 ; kill 20105 ; rm -f /tmp/tmp.XGCWt20093' EXIT
+ exec
+ exec tee -a /apps/psr/database/logs/env53b_Refresh_2012-12-05-2346.log
+ Get_Database_Variables_From_Env_Xml env53b
+ local function_name=Get_D

What i feel is the wait statement in the main build_environment script needs to be remove.
# 12  
Old 12-10-2012
I forgot the disown.

I wouldn't remove the wait unless that's your code and not the rest of the script, I don't know what it was for.

Code:
function init_stdout_redirect {
    OUT_LOG=$1
    OUT_PIPE=$(mktemp -u)

    # Create the output pipe
    mkfifo $OUT_PIPE

    # Save stdout and stderr as 3 and 4
    exec 3>&1 4>&2

    # Tee the output pipe into the log file
    ( exec tee -a $OUT_LOG < $OUT_PIPE >&3 ) &

    # Save tee's pid
    TEE_PID=$!

    disown

    trap "exec 2>&-; exec 1>&-; sleep 1 ; kill ${TEE_PID} ; rm -f ${OUT_PIPE}" EXIT

    # Redirect the output to the pipe
    exec > $OUT_PIPE 2>&1
 }

# 13  
Old 12-10-2012
Note: disown is bash/ksh93..
# 14  
Old 12-10-2012
I was under the impression that shells without disown didn't need disown either...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Windows & DOS: Issues & Discussions

Plink wait problem

Hi, I have run into a problem to which i can't seem to find any solution, posting here is my last resort. Problem: I am using plink to access my router and run a few configuration commands. When in enter configurations mode, instead of sending next command plink keeps on waiting for manual... (7 Replies)
Discussion started by: zaainabbas
7 Replies

2. Shell Programming and Scripting

[Solved] Help with shell Script ,wait for some files for some time??

Hi All, I have the requirement that ,i have to write a shell script that job has to wait for a 7 touch files created by another application for 4 hours, if i get all 7 touch files ,i have to send a mail that i jobs are completed, if if it is waiting for more than 4 hours i have to send a mail... (2 Replies)
Discussion started by: Pradeep Shetty
2 Replies

3. Shell Programming and Scripting

[Solved] If statement in bash

I have the following code in bash, however "set red frmt" is not displayed. echo "iarg_rd = $iarg_rd" iarg_rd="2" if ; then echo "Hello World" fi if ; then frmt="${gap}${!frmt_titl_yl}" elif ; then frmt="${gap}${!frmt_titl_bk}" elif ; then echo... (2 Replies)
Discussion started by: kristinu
2 Replies

4. Shell Programming and Scripting

[Solved] While read line and if statement not working

I'm looking for some help in figuring why my little bit of code will not process any entries other then the first one in my list. while read line ;do hostname=${line//\"} a=`ssh user@$hostname uptime;echo $?` if ];then dt=`date` touch... (6 Replies)
Discussion started by: whegra
6 Replies

5. Shell Programming and Scripting

[Solved] FOR loop / IF statement returning error

The code at the bottom is a simplified example of what we have. If I use the following: && echo "echo failed" $? returns 1 When I use if ; then echo "echo failed" ; fi $? returns 0 Does anyone know what's wrong with this? Using AIX 6.1 and KSH for NUM in 1 2 3 do ... (5 Replies)
Discussion started by: jfxdavies
5 Replies

6. Shell Programming and Scripting

[Solved] 0403-057 Syntax error for if statement

I am getting the following error when I am running a script in ksh when trying to execute an if statement comparing two numerical values tstmb.sh: 1.5321e+08: 0403-057 Syntax error Below is my code snippet. #!/bin/ksh set -x TODAY=$(date +%y%m%d) for file in $(ls -rt *.log | tail... (11 Replies)
Discussion started by: kiran1112
11 Replies

7. Shell Programming and Scripting

[Solved] Strange Problem in case statement while shift

Hi, Here is my code as below: test.ksh: ======= #!/bin/ksh option="${1}" while do case $1 in -f) FILE="${2}" echo "File name is $FILE" ;; -d) DIR="${2}" echo "Dir name is $DIR" ;; -*) echo "`basename ${0}`:usage: | " (5 Replies)
Discussion started by: zaq1xsw2
5 Replies

8. Shell Programming and Scripting

plz, i wait your help, AWK problem

I have tracefile of three nodes (0 , 1 and 2 ) as follows: + 0.02 0 1 tcp 40 ------- 1 0.0 2.0 0 0 - 0.02 0 1 tcp 40 ------- 1 0.0 2.0 0 0 + 0.02 2 1 tcp 40 ------- 2 2.1 0.1 0 1 - 0.02 2 1 tcp 40 ------- 2 2.1 0.1 0 1 r 0.025032 0 1 tcp 40 ------- 1 0.0 2.0 0 0 + 0.025032 1 2 tcp 40 -------... (11 Replies)
Discussion started by: ASAADAOUI
11 Replies

9. Shell Programming and Scripting

wait problem

Hello, I have been trying to figure out why the wait isnt waiting for the sleep process to complete till now and have found out that since sleep runs as different process and not a child process the wait isnt waiting. script: cat test|while read i do echo $i sleep 30 & done wait ps... (4 Replies)
Discussion started by: wannalearn
4 Replies

10. UNIX for Dummies Questions & Answers

I/O wait Problem

When running top, I notice a bit more I/O wait time than usual. Is there a tool or piece of software out there that can me help evaluate the performance of these operations on my machine? Thanks! (5 Replies)
Discussion started by: unavb
5 Replies
Login or Register to Ask a Question