LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to write the updated output of a continious running program to a file? (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-write-the-updated-output-of-a-continious-running-program-to-a-file-4175430657/)

nayaksan 10-05-2012 05:44 AM

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

GlennsPref 10-05-2012 05:59 AM

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.

nayaksan 10-05-2012 06:42 AM

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?

unSpawn 10-05-2012 06:54 AM

Quote:

Originally Posted by nayaksan (Post 4797966)
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 (Post 4797935)
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.

nayaksan 10-05-2012 09:41 AM

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

unSpawn 10-05-2012 11:34 AM

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.

nayaksan 10-06-2012 07:23 AM

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

unSpawn 10-06-2012 08:29 AM

Quote:

Originally Posted by nayaksan (Post 4798729)
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'.


All times are GMT -5. The time now is 06:47 AM.