Creating an application loop
Hi! Can someone point me on a way to create a command that continuously runs for every second then sleeps when told. For example
I would like to run netstat -i for every second and output the output to a file and terminate when I tell it to. I tried this with cron but would like a program that just loops until I tell it to stop Thanks. |
In the case of the netstat utility it has an option to do what you want.
Code:
netstat -c Code:
netstat -i -c >logfile.txt Code:
man netstat |
Thanks for the reply, I really am looking for more of an application loop than anything. I need to run it on other commands other than netstat that do not have the count option. I would rather learn how to script out a program that runs continuously until stopped.
Thanks. |
"watch" might do what you want, although I don't think there's an option to make it put the output in a file. You can do this by adding tee:
Code:
watch -n 5 'netstat -i |tee -a my.log' |
Thanks tee might work however can you give me advice on how to append date to each of the outputs so I can tell each 2 second interval. I used the following watch -n 1 'netstat -i | tee -a | date +%r >> my.log' how do I append a date to the output of each instance of the netstat -i?
|
This is probably what you're looking for:
Code:
watch '(date ; netstat -i; echo "") |tee -a log' |
Thanks A lot this works perfectly.
|
All times are GMT -5. The time now is 06:53 AM. |