Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
In the case of the netstat utility it has an option to do what you want.
Code:
netstat -c
Also, if you used cron to invoke netstat every second it would probably end up taking more than one second to start and run and output. Therefore you could end up having more than one instance running which could mess up your log file or could have file locking problems. So you probably want do this:
Code:
netstat -i -c >logfile.txt
I found this information using the man page for netstat.
Code:
man netstat
Last edited by stress_junkie; 01-17-2007 at 02:52 PM.
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 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?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.