Sponsored Content
Full Discussion: BASH log file
Top Forums Shell Programming and Scripting BASH log file Post 302816145 by Don Cragun on Monday 3rd of June 2013 11:13:36 AM
Old 06-03-2013
Quote:
Originally Posted by Rahul619
... ... ...
---------- Post updated 06-03-13 at 05:23 AM ---------- Previous update was 06-02-13 at 08:39 AM ----------
Code:
#!/bin/bash
# NOTE: This script runs a.sh and b.sh at the same tiem and reports the exit
# status of both before terminating (if either one fails) or moving to to c.sh
# (if both succeed).
# Start a and b...
./bin/a.sh &
pida=$!         # save pid of a.sh
./bin/b.sh &
pidb=$!         # save pid of b.sh

# Reap a...
# NOTE: The following wait will not collect the exit status of b.sh even if
# it finishes first.
wait $pida
esa=$?          # save exit status of a.sh

# NOTE: Following line creates close.log rather than appending to it.  So,
# we get a clean log for each invocation of this script.
# NOTE: There is no need to redirect stderr from these echo commands; the
# only reason for echo to fail would be if there is an error writing to the
# log file (and redirecting that error message to a file that can't be written
# to means that we would get no notification of the error).
echo "a.sh job status : $esa" >close.log
if [ $esa -eq 0 ]
then
        echo "a.sh is success at $(date)" >>close.log
else
        echo "a.sh failed at $(date)" >>close.log
fi

Don, from ur note its clear that wait $pida will not collect the status of b.sh.. can u pls tell me whether wait $pida will interupt the background execution of b.sh which was started in parallel with a.sh ??

thanks a lot in advance !!
Neither the command wait $pida nor the later command wait $pidb have any effect on the execution of a.sh nor b.sh. They merely cause this script to suspend until a.sh and b.sh, respectively, terminate (if they haven't already terminated).

Furthermore, any subsequent attempts to wait for $pida or $pidb will fail. Once the status of a terminated child has been reaped, the child no longer exists; so an attempt to wait for it again will yield an ECHILD error resulting in the wait utility returning exit code 127.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash tail monitor log file

Hi there, I have a problem here that involves bash script since I was noob in that field. Recently, I have to monitor data involve in logs so I just run command tail -f for the monitoring. The logs was generate every hour so I need to quickly change my logs every time the new hour hits according... (2 Replies)
Discussion started by: kriezo
2 Replies

2. Shell Programming and Scripting

bash: color strings in log file

hello im looking for an easy way to color specific strings in text file. simple example: cat file1 acb 1234 qwer 5678 my goal: cat file1 (color the acb red and the 5678 blue) acb 1234 qwer 5678 cheers (2 Replies)
Discussion started by: modcan
2 Replies

3. Shell Programming and Scripting

Logging ALL standard out of a bash script to a log file, but still show on screen

Is it possible to store all standard-out of a bash script and the binaries it calls in a log file AND still display the stdout on screen? I know this is possible to store ALL stdout/stderr of a script to a single log file like: exec 1>&${logFile} exec 2>&1 But running a script with the... (3 Replies)
Discussion started by: ckmehta
3 Replies

4. Shell Programming and Scripting

bunch of ^@^@^@^@^@^@^@^@'s in bash log file

I have a bash script that has been running fine for months that scans a bunch of files and gives me a log file output, it has suddenly started putting 1.5M of a repeating sequence of ^@^@^@^@^@^@^@^@^@^@ on the first line of the logfile, is this a unicode problem I should be setting something in my... (5 Replies)
Discussion started by: unclecameron
5 Replies

5. Shell Programming and Scripting

how to make my own file as a running log file in bash

Hi, I have written a small script from that iam appending the output to a file.If multiple users invoke the same script or if i invoke the same script n number of times (using &), the output file(ZZ/OUT) contains messup information. #!/bin/bash # echo "Hello" >> /tmp/ZZ/OUT sleep 10 echo... (4 Replies)
Discussion started by: blrguest
4 Replies

6. Shell Programming and Scripting

Log Out SSH User in Bash

So, I've been writing a system to allow users temporary access onto a system. Essentially, there's a web server with a PHP script, the PHP script takes a Username & Password from a webform, and passes it to a script, createusr.sh. The script looks something like this: pass=$(perl -e 'print... (2 Replies)
Discussion started by: FreddoT
2 Replies

7. Shell Programming and Scripting

Bash Script Closest Timestamp (LOG FILE)

Hi All, I need something where I could take the date from FILE1 and in this case the date is Thu Sep 10 13:48:42 EDT 2015 and I need it to match the closest PREVIOUS date in the log file FILE2 this means in this specific case it would be Thu Sep 10 2015 13:35:28. I only need the closest... (3 Replies)
Discussion started by: roberto999
3 Replies

8. Shell Programming and Scripting

Bash script for looking in log file

Hello, I'm a beginner in shell scripting. I would really appreciate some help from the forum. I want to write a small script that will look in apache error log. If it finds the appropriate word. It would execute some commands. In my case the apache error log is situated in:... (2 Replies)
Discussion started by: ajaysingh99
2 Replies

9. Shell Programming and Scripting

Bash to select text and apply it to a selected file in bash

In the bash below I am asking the user for a panel and reading that into bed. Then asking the user for a file and reading that into file1.Is the grep in bold the correct way to apply the selected panel to the file? I am getting a syntax error. Thank you :) ... (4 Replies)
Discussion started by: cmccabe
4 Replies

10. Shell Programming and Scripting

Call one bash file from another bash file.

hi .. greetings ...i need help in bash programming. i am on linux mint. i have two .sh files.(netcheck.sh and dlinkreboot.sh).. please note . both bash files are working perfectly well independently... but cant work together. . in short i want one bash file to call the other bash file... (2 Replies)
Discussion started by: emmfranklin
2 Replies
WAIT(2) 							System Calls Manual							   WAIT(2)

NAME
wait - wait for process to terminate SYNOPSIS
wait(status) int *status; wait(0) DESCRIPTION
Wait causes its caller to delay until a signal is received or one of its child processes terminates. If any child has died since the last wait, return is immediate; if there are no children, return is immediate with the error bit set (resp. with a value of -1 returned). The normal return yields the process ID of the terminated child. In the case of several children several wait calls are needed to learn of all the deaths. If (int)status is nonzero, the high byte of the word pointed to receives the low byte of the argument of exit when the child terminated. The low byte receives the termination status of the process. See signal(2) for a list of termination statuses (signals); 0 status indi- cates normal termination. A special status (0177) is returned for a stopped process which has not terminated and can be restarted. See ptrace(2). If the 0200 bit of the termination status is set, a core image of the process was produced by the system. If the parent process terminates without waiting on its children, the initialization process (process ID = 1) inherits the children. SEE ALSO
exit(2), fork(2), signal(2) DIAGNOSTICS
Returns -1 if there are no children not previously waited for. ASSEMBLER
(wait = 7.) sys wait (process ID in r0) (status in r1) The high byte of the status is the low byte of r0 in the child at termination. WAIT(2)
All times are GMT -4. The time now is 08:38 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy