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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to make my own file as a running log file in bash
# 1  
Old 04-01-2011
Question 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.

Code:
#!/bin/bash
# 
echo "Hello" >> /tmp/ZZ/OUT
sleep 10
echo "World" >> /tmp/ZZ/OUT
sleep 10
echo "---------end -----------" >> /tmp/ZZ/OUT
sleep 5

                  cat OUT 
Hello
Hello
Hello
World
World
World
---------end -----------
---------end -----------
---------end -----------

I would like to know is there any possibility to get consistent output like log file (/var/log/message) for any number of time script invocation. like below.

Hello
World
---------end -----------
Hello
World
---------end -----------

Thanks in advance.
-regards
guest.

Last edited by pludi; 04-01-2011 at 09:10 AM..
# 2  
Old 04-01-2011
processes which are gonna invoke your script can write output into different files. say psid.out.log for example.

if you want only one log file, you may consider to add some prefix to each appended text, to indicate the log message was from which process.
# 3  
Old 04-01-2011
Quote:
Originally Posted by sk1418
processes which are gonna invoke your script can write output into different files. say psid.out.log for example.

if you want only one log file, you may consider to add some prefix to each appended text, to indicate the log message was from which process.
Thnx for the suggestion.
however I want some sort of syncronization technique to my script so tht my output is consistant.Otherwise I need a mechanism how the log file(/var/log/messages) use to append automatically.
# 4  
Old 04-01-2011
Code:
out1=$( command1 )
sleep 10
out2=$( command2 )
sleep 10
printf "%s\n" "$out1" "$out2" "---------end -----------" >> /tmp/ZZ/OUT

This User Gave Thanks to cfajohnson For This Post:
# 5  
Old 04-01-2011
Quote:
Originally Posted by cfajohnson
Code:
out1=$( command1 )
sleep 10
out2=$( command2 )
sleep 10
printf "%s\n" "$out1" "$out2" "---------end -----------" >> /tmp/ZZ/OUT

Thanks a lot!!!.
This is working fine which as per my expectation.... gr8..Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash - make csv file

Hello, im trying to make csv file from a text file that it is the output of pssh command (multiple ssh ) now if i run the command date on all of our servers: i get this output : 14:02:46 192.168.25.230:22 Thu Jul 6 14:02:46 EEST 2017 192.168.70.230: Thu Jul 6 12:02:46 BST 2017 ... (1 Reply)
Discussion started by: batchenr
1 Replies

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

3. UNIX for Dummies Questions & Answers

Bash/vi: Make file go away once I close it.

Hi Everyone, It's a little difficult to explain what exactly I am looking for. When I open a file in vi, and then close it, I get back the prompt, but I can still see the file on top. I don't want that. I want to be able to see all the previous commands which I have typed. For example: I... (4 Replies)
Discussion started by: the_learner
4 Replies

4. Shell Programming and Scripting

BASH log file

hi .. am new to bash script.. #!/bin/bash logfile = "${HOME}/log/test.log" ./1.sh echo " script over " can anyone telme hw to set the logfile ?? the above code calls the 1.sh and echo statement gets printed in cmd prompt, but i could not see the log file . (8 Replies)
Discussion started by: Rahul619
8 Replies

5. Shell Programming and Scripting

[Solved] The SCRIPT command - Can we see the log file of a running session?

Hello. This is my situation. script .anything ls -l . ---How can I see the content of .anything using (i.e) cat .anything? If not possible can someone suggest a sequence to simulate a console-recorder to "observ" from a RUNNING script session? Thanks Paolo Please use code tags... (3 Replies)
Discussion started by: paolfili
3 Replies

6. Shell Programming and Scripting

make the name of file and fetch few things from log file

Hello All, I am working on a script where I need to fetch the value from a log file and log file creates with different name but few thing are common DEV_INFOMGT161_MULTI_PTC_BLD01.Stage_All_to_stp2perf1.042312114644.log STP_12_02_01_00_RC01.Stage_stp-domain_to_stp2perf2.042312041739.log ... (2 Replies)
Discussion started by: anuragpgtgerman
2 Replies

7. Programming

makeutility: how to get the make-file name inside of the make-file?

How I can get the current make-file name in a make-file So, if I run make with specified file:make -f target.mak is it possible to have the 'target' inside of the that 'target.mak' from the file name? (2 Replies)
Discussion started by: alex_5161
2 Replies

8. Shell Programming and Scripting

how to make a log file of extract time

Dear All, Please apology to me if this question already posted, because I try to find it but not found. I have make bash script to automatically download data from ftp and this running very well. and after the data downloaded it will automatically extract the data and keep in the specific... (2 Replies)
Discussion started by: chenboly
2 Replies

9. UNIX for Dummies Questions & Answers

getting help on finding exception in running log file

Hi all, I am trying to write a script for an application server log file where i want to put this script as a cron tab entry and it will check the server log file last 1000/500 line for every fifteen minute. i am using the script like this. count=`tail -n 1000 Trace.log | grep -c... (1 Reply)
Discussion started by: senthilkumar_ak
1 Replies

10. Programming

Error while running C++ make file

The problem is that the original program was compiled using v5.0 MQ client but now we are using MQ client v5.3. Had modified the "make file" options as follows but still i could see the errors. #CLIENT_V5_LIBS = -limqb23ss -limqc23ss -lmqic -lmqmcs -lnsl -ldl CLIENT_V5.3_LIBS =... (1 Reply)
Discussion started by: hram
1 Replies
Login or Register to Ask a Question