shell script : log to txt and insert new line everytime


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers shell script : log to txt and insert new line everytime
# 1  
Old 01-31-2012
shell script : log to txt and insert new line everytime

Hi,

I have this script,
Code:
    while [ 1 ]
    do
          ps  ax|grep 5060 > log.txt
          echo " "
          sleep 1
    done 
}

I want to actually put a new line everytime the loop is executed in log.txt , but I do not know how to "embed" the echo " " inside the log.txt.
(so to say in log txt it will fill with result of grep command in every line, not overwritten, until I press ctrl+c)

Can anyone help?

Thank you
Moderator's Comments:
Mod Comment Please use code tags!
!

Last edited by vbe; 01-31-2012 at 05:48 AM..
# 2  
Old 01-31-2012
Hi,
you script currently overwrites log.txt every second. Use >> to append.
Code:
while [ 1 ]
do
   ps ax|grep 5060 >> log.txt
   echo " " >> log.txt
   sleep 1
done

This User Gave Thanks to cero For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Split Every Line In Txt Into Separate Txt File, Named Same As The Line

Hi All Is there a way to export every line into new txt file where by the title of each txt output are same as the line ? I have this txt files containing names: Kandra Vanhooser Rhona Menefee Reynaldo Hutt Houston Rafferty Charmaine Lord Albertine Poucher Juana Maes Mitch Lobel... (2 Replies)
Discussion started by: Nexeu
2 Replies

2. UNIX for Dummies Questions & Answers

Script to delete files line by line in .txt document

Friends, I am in need to delete files from a directory on a regular basis. I want to place all the files to be deleted in delete .txt file and require a script to delete files, line by line from this delete.txt file. Please help me with this script as am new to unix scripting. (3 Replies)
Discussion started by: fop4658
3 Replies

3. Shell Programming and Scripting

HELP: Shell Script to read a Log file line by line and extract Info based on KEYWORDS matching

I have a LOG file which looks like this Import started at: Mon Jul 23 02:13:01 EDT 2012 Initialization completed in 2.146 seconds. -------------------------------------------------------------------------------- -- Import summary for Import item: PolicyInformation... (8 Replies)
Discussion started by: biztank
8 Replies

4. Shell Programming and Scripting

Korn Shell script to insert at specific line

Hi, I am trying to put together a Korn Shell script to insert at a specific line. The system we use is SunOS 5.10 I can get the line number by using:- num=`sed -n '/export ENV/=' ./tmp.file` Not getting much headway using the above variable's value to insert - export SYBASE=/opt/sybase15... (5 Replies)
Discussion started by: aj8200
5 Replies

5. Shell Programming and Scripting

executing a shell script everytime the terminal is opened

the problem statement is Write a shell script, which gets executed the moment the user opens a terminal. It should display the message "Hello your_name, welcome to 172.16.4.120 server” How to get around this? (2 Replies)
Discussion started by: arindamlive
2 Replies

6. Shell Programming and Scripting

Print the 2nd line everytime after defined pattern is found.

Hi, I have a text file similar to the example below and I want to print the second line every time after the "--------------------------" pattern is found. The pattern is a fixed length of - characters. Example of input; 1 -------------------------- 2 3 39184018234 4 ... (10 Replies)
Discussion started by: lewk
10 Replies

7. Shell Programming and Scripting

to insert some word somewhere in the line with shell (or perl)

hello mighty all there is a line of 50 words and i need to take a random number of words from the beginning (20 words for example) then put my word then add other 10 words from the continue then add another my special word then add 20 words till the end.. my own knowledge base can say it is... (12 Replies)
Discussion started by: tip78
12 Replies

8. Shell Programming and Scripting

Shell script to parse a line and insert a word

Hi All, I have a file like this, data1,data2,,,data5,data6. i want to write a shell script to replace data3 with "/example/string". which means my data file should look like this . data1,data2,example/string],,data5,data6. Could you guys help me to get a sed command or any other command... (8 Replies)
Discussion started by: girish.raos
8 Replies

9. Shell Programming and Scripting

shell script to read a line in gps receiver log file and append that line to new file

Hi, I have gps receiver log..its giving readings .like below Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. GPSD,R=1 $GPGSV,3,1,11,08,16,328,40,11,36,127,00,28,33,283,39,20,11,165,00*71... (3 Replies)
Discussion started by: gudivada213
3 Replies

10. Shell Programming and Scripting

shell script to insert data from gps.txt to mysql database

Hi, I have gps receiver, by using gpsd data i can read gps log data to my database(my sql). Steps: 1. telenet localhost 2947 > gps.txt (press enter) 2. r (press enter) //then i will get the data like below in gps.txt file Trying 127.0.0.1... Connected to localhost.... (1 Reply)
Discussion started by: gudivada213
1 Replies
Login or Register to Ask a Question