BASH log file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting BASH log file
# 8  
Old 06-03-2013
thanks a lot Don Cragun .. cant expect anything clear more dan this. it was awesome and clear.. once again thanks 4 ur patience 2 explain it line by line Smilie !!

---------- 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 !!
# 9  
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
Login or Register to Ask a Question