Direct two scripts to write to one file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Direct two scripts to write to one file
# 1  
Old 03-27-2009
Direct two scripts to write to one file

I have an interesting dilemma. I am trying make a script that is continuously scanning for new data. This script cannot be paused or stopped it needs to run constantly. I also want to periodically time stamp the output to make it easier to sort through. The trouble is that I can't think of a way to write a single script to do this.

I can however write two separate scripts to perform the function. The catch is that every time the time-stamp script goes to write the time-stamp it erases the contents of said file.

Can anyone think of a way around this because I am out of ideas.
# 2  
Old 03-27-2009
What scripting language are you using or better yet please post your code. Thank you.
# 3  
Old 03-27-2009
Script 1 this is the one that must run constantly. Pretty basic I know.
Code:
#! /bin/sh
actual=`date`
echo "Process ID for tcpdump launched $actual is $$" > /log/procID.log
tcpdump -i en0 -A -s 0 port 80 | grep Referer: > /log/tcpdump.log

Script 2 this is the one that just timestamps the log created by the first script
Code:
#! /bin/sh
count=1
actual=`date`
echo "Process ID for the timer launched $actual is $$" > /log/procID.log
while [ $count != 0 ]
do
timer=`date "+%H:%M:%S"`
echo "$timer" > /log/tcpdump.log
sleep 60
done

I may be doing this all wrong, my expertise is in computer repair / server setups. I don't know a whole lot about UNIX scripting. So if you see a simple way to merge these into a single script please tell me.
# 4  
Old 03-28-2009
In the second script change from overwriting the file ">" to append ">>" and that should do it
# 5  
Old 03-28-2009
Well that solved one problem but created another. Once the timer script timestamps the log the tcpdump script stops writing to it until the timer script is shutdown.
# 6  
Old 03-28-2009
change both scripts so they append the file ">>" if the file does not exist it will create it. I tried in my machine and it worked just fine.
# 7  
Old 03-29-2009
You are indeed correct now I just need to clean up the formatting a bit. Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to write BTEQ batch scripts in UNIX?

Hi All, I need to write Unix shell script. To star with : I need to do some file checking on unix file system, then based on file existance, I need to run diff SQL in Teradata Bteq. After that, depending on Results of SQL, I need to code other shell scripting like moving file, within same... (4 Replies)
Discussion started by: Shilpi Gupta
4 Replies

2. Shell Programming and Scripting

File not exist in direct

friends can do this from unix AIX I need to ask for a file that does not exist then if file.txt * **** echo "execute procedure" else *** echo "File does not exist" if You can sucedere that the file does not exist (2 Replies)
Discussion started by: tricampeon81
2 Replies

3. Shell Programming and Scripting

Manipulating sed Direct Input to Direct Output

Hi guys, been scratching round the forums and my mountain of resources. Maybe I havn't read deep enough My question is not how sed edits a stream and outputs it to a file, rather something like this below: I have a .txt with some text in it :rolleyes: abc:123:xyz 123:abc:987... (7 Replies)
Discussion started by: the0nion
7 Replies

4. UNIX for Dummies Questions & Answers

re-direct to log file

#!/bin/ksh -x cd /tmp/tj ftp -n servername.com << DONE user username password as put test.log quit close DONE echo "testing..." sh -x scriptname, and it shows all, but username, as, put, quit, close, DONE. how can i see those ? (1 Reply)
Discussion started by: tjmannonline
1 Replies

5. Shell Programming and Scripting

Write a scripts to kill idle user for 60 min. & email user list to admin in text file

Folks, I have written one script for following condition by referring some of online post in this forum. Please correct it if I'm missing something in it. (OS: AIX 5.3) List the idle user. (I used whoidle command to list first 15 user and get username, idle time, pid and login time).... (4 Replies)
Discussion started by: sumit30
4 Replies

6. Shell Programming and Scripting

how to write RC scripts!!! pls assist

Hi all, I would like to know how to write an rc script? Am planning on doing some memory management during the boot itself, so planning on implementing it through the rc scripts.... I wanted to know what the constraints are ,how the script itself need to be designed, and all such stuffs!!! I... (4 Replies)
Discussion started by: wrapster
4 Replies

7. Shell Programming and Scripting

how to write orginal scripts to backups

hi iam new of scripting. give me some informtion of how to write backups file thanks&regards Naveen.g (1 Reply)
Discussion started by: naveeng.81
1 Replies

8. UNIX for Dummies Questions & Answers

direct output to a file then email it

Ok so i have this script and I dont know how to have the output go to a file and then email that file to someone. #!/bin/ksh print "AL" print "AM" print "AN" print "RL\n" nawk '/PROD/ {print $3, $2}' /home/user/switch_listtest | sort -k1,2 print "End of Report" Thank you in... (2 Replies)
Discussion started by: llsmr777
2 Replies

9. UNIX for Dummies Questions & Answers

how to write perl substitute command in shell scripts

How to write perl substitute command in shell script without invoking a perl script file seperately. for ex: shell script to relace IT with CSC in a file using perl substitute command. (3 Replies)
Discussion started by: param_it
3 Replies

10. UNIX for Dummies Questions & Answers

Learning to write UNIX Shell Scripts

Hi All, I am relatively new to UNIX. I know some basic commands. I am learning to write shell scripts. My first aim is to connect to a Data Base via shell script. Any ideas on this? Any links, docs which will tell me about scripting?? Thanks VEN (1 Reply)
Discussion started by: VENC22
1 Replies
Login or Register to Ask a Question