944,208 Members | Top Members by Rank

Ad:
May 17th, 2006
0

Simple script loop question

Expand Post »
Hey all. Thanks in advance for any help you can give, hopefully this is an easy one. I want to create a loop to run a simple performance monitor like vmstat and record it to a file, but have very limited scripting skills.

Starting with this...

date >> /var/log/perfmon.log
vmstat 3 10 >> /var/log/perfmon.log

I basically want it to sleep for 5 minutes using sleep 300, but how do I start the process again (restart the loop)?

Thanks
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mattlock73 is offline Offline
2 posts
since May 2006
May 17th, 2006
0

Re: Simple script loop question

while true
do
date >> /var/log/perfmon.log
vmstat 3 10 >> /var/log/perfmon.log
sleep 300
done

but instead of giving a sleep of 5 minutes why don't you cron the whole thing. Schedule the commands so that they run after every 5 min.

Amit
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kamitsin is offline Offline
16 posts
since Apr 2006
May 17th, 2006
0

Re: Simple script loop question

Quote originally posted by kamitsin ...
while true
do
date >> /var/log/perfmon.log
vmstat 3 10 >> /var/log/perfmon.log
sleep 300
done

but instead of giving a sleep of 5 minutes why don't you cron the whole thing. Schedule the commands so that they run after every 5 min.

Amit
Originally that's what I was going to do, however the particular box I am trying to get this running on has had cpu spike issues that cause crons to fail during the spikes. Hoping that an active process may have more luck staying active than a new process starting. Am also going to collect data for a specific interval, write to file then tar the files by date/time. Wasn't sure how to do that by cron. Anyway, got it working the way I wanted it until the real scripting guy gets back from vacation thanks!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mattlock73 is offline Offline
2 posts
since May 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: help with my fist script
Next Thread in Shell Scripting Forum Timeline: automated email on a log event





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC