LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-05-2012, 06:44 AM   #1
nayaksan
LQ Newbie
 
Registered: Oct 2012
Posts: 4
Blog Entries: 1

Rep: Reputation: Disabled
How to write the updated output of a continious running program to a file?


Hi,
I want to execute sipp Load scripts through a shell scripts. The sipp scripts will run more than 8 hrs continiously as per my requirment in the background.

when i wrote the code in the shell as
./sipp a> mylogs.txt &

It wrote the outputs of the ./sipp a to the mylogs.txt continiously.(i.e. it appends the updated output to the mylogs.txt in every 1 secs). Hence it increased the size of mylogs.txt file in every secs. What i need is it should only write the upadted output in every second from the begginging of file in stead of appending the things in every secs, which increase my file size.

Please suggest a suitable code for it.

Regards,
Sanjay
 
Old 10-05-2012, 06:59 AM   #2
GlennsPref
Senior Member
 
Registered: Apr 2004
Location: Brisbane, Australia
Posts: 3,366
Blog Entries: 33

Rep: Reputation: 216Reputation: 216Reputation: 216
Quote:
Hi, Welcome to LQ!

LQ has a fantastic search function that may save you time waiting for an answer to a popular question.

With over 4 million posts to search it's possible the answer has been given.

Hi, I'm no coder... That said...

some of my scripts print to a file when run,

in order to not overwrite the old file,

I set the name of the file to include the current time and date.

for example, an rpm database list I like to diff from time to time...

Code:
echo "run rpm -Va | grep "Unsatisfied dep" & send to /home/glenn/build/anote-rpm-Va-grep-Unsatisfied-dep-list-`date +%Y-%m-%d-%H`.txt"
sudo rpm -Va | grep "Unsatisfied dep" > /home/glenn/build/anote-rpm-Va-grep-Unsatisfied-dep-list-`date +%Y-%m-%d-%H`.txt
cat /home/glenn/build/anote-rpm-Va-grep-Unsatisfied-dep-list-`date +%Y-%m-%d-%H`.txt
By inserting
Quote:
`date +%Y-%m-%d-%H`
to the file name I am able to find what I need to.

HTH, Glenn

Ps. I guess, that `"date" +...` is a BASH interpretation/implementation.(should work ;-))

This only updates every/any hour.

It's possible to write a new file as fast as possible, maybe every second ( add -%M-%S) if the hardware can do it.

Last edited by GlennsPref; 10-05-2012 at 07:18 AM. Reason: I Guess....
 
Old 10-05-2012, 07:42 AM   #3
nayaksan
LQ Newbie
 
Registered: Oct 2012
Posts: 4
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
Hi,
Thanks for your replay.
It's fine. Every sec it will create a new file and writes the updated output.
But i don't require the old files as it will increase the size and may hang my system after 8 to 10 hrs execution of my sipp script.
So what i need is when it creates the new to write the updated output, it should delete automatically the previously created/old file as i don't require that files.

Please suggest is there any suitable code for it?
 
Old 10-05-2012, 07:54 AM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529
Quote:
Originally Posted by nayaksan View Post
Every sec it will create a new file and writes the updated output.
That is not consistent with what you wrote in your OP:
Quote:
Originally Posted by nayaksan View Post
Code:
./sipp a> mylogs.txt &
Start by posting your "sipp" scripts contents (and the command line you run or cron job it with, if changed) so we can see what it actually does.
 
Old 10-05-2012, 10:41 AM   #5
nayaksan
LQ Newbie
 
Registered: Oct 2012
Posts: 4
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
I have written the code as follows

#myscript.sh

#!bin/sh

cd /usr/bin;

#flow1

nohup ./sipp 192.65.221.186:5060 -i 10.92.219.170 -p 5060 -sf PCP1.xml &

pid_pcp1=$!

#flow2

nohup ./sipp 192.65.221.186:5060 -i 10.92.219.171 -p 5060 -sf PCP2.xml &

pid_pcp2=$!

#flow3


nohup ./sipp 192.65.221.186:5060 -i 10.92.219.172 -p 5060 -sf PCP3.xml &

pid_pcp3=$!

#flow4


nohup ./sipp 192.65.221.186:5060 -i 10.92.219.173 -p 5060 -sf PCP3.xml &

pid_pcp4=$!


sleep n

kill -SIGUSR1 $pid_pcp1

kill -SIGUSR1 $pid_pcp2

kill -SIGUSR1 $pid_pcp3

kill -SIGUSR1 $pid_pcp4



Actually my requirment is

i have to start these sipp scripts for traffic generation at a time by using a shell script. Then i want to check their outputs whenever i need.

After a specific duration i want to gracefully terminate the above flows.

Starting and gracefully shut down is working fine. Only i am facing problem is that how can i check the updated ouput status
of all flows whenever i need. If i started the above flows individually in different terminal
then i can view the outputs of them in their respective terminals. But here as i have started them
in background in one shell script then how can i check the individual output status of flows whenever i need.


Please suggest how to do the same?

Regards,
Sanjay
 
Old 10-05-2012, 12:34 PM   #6
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529
It would have been more efficient to state that sipp actually is sipp. This also means that executing
Code:
./sipp a> mylogs.txt &
doesn't make any sense as it can write its own log files (see the -trace_.* switches) and you shouldn't switch to /usr/bin because then that's where it writes its output. Instead cd to say "/home/sanjay/sipp/logs" and write logs there and reference the full path for the binary like "/usr/bin/sipp" and the configuration files like "/home/sanjay/sipp/configs/PCP1.xml". If you want to remove all stale log files then you best remove them before you start a new run, for example:
Code:
find /home/sanjay/sipp/logs -type f -name PCP\* -print0 | xargs -0 -iX rm -f 'X'
or if you want to check first if they're still in use:
Code:
find /home/sanjay/sipp/logs -type f -name PCP\*|while read ITEM; do [ -e "${ITEM}" ] && { fuser "${ITEM}" >/dev/null 2>&1||rm -f "${ITEM}"; }; done
If you want to run sipp in the background BTW see the "-bg" switch. Finally, if you want to start different sipp sessions simultaneously and be able to view their screens then you could run each session from a different terminal but another option is to run each session as part of a screen session. 'man screen' for a first glance at how that works.
 
1 members found this post helpful.
Old 10-06-2012, 08:23 AM   #7
nayaksan
LQ Newbie
 
Registered: Oct 2012
Posts: 4
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
Hi,
I think man screen command will be helpful for me.
I want to execute all the above 4 sipp commands simultaneously by starting one shell script. beacuse that is my requirment.
Only thing is i want to see their screen outputs whenever i need.
Please suggest how can i implement this "man screen" command for my code above to see the screen outputs of 4 sipp processes when ever i need individually or together?

I was trying a lot to implement the man screen command for my code. But i am not able to get any idea. please suggest.
Regards
sanjay
 
Old 10-06-2012, 09:29 AM   #8
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529
Quote:
Originally Posted by nayaksan View Post
I was trying a lot to implement the man screen command for my code.
Please post your updated script with respect to advice given and how you have tried to use 'screen'.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Strange output when running a C program over itself Dralnu Programming 5 05-13-2009 05:15 PM
I (sometimes) cant write my program file when a copy of it is running foof Linux - Newbie 6 11-13-2008 05:17 PM
How to write script with check running program VooZ2_uk Programming 3 12-13-2006 10:57 AM
Exercise 1-9. Write a program to copy its input to its output, replacing each string zombi3 Programming 3 12-21-2003 03:28 AM
how to write a program can have 2 threads running at the same time?? man9 Programming 3 10-07-2000 02:43 PM


All times are GMT -5. The time now is 04:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration