Simple script loop question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Simple script loop question
# 1  
Old 05-17-2006
Simple script loop question

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 (obviously).

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
# 2  
Old 05-17-2006
Use something like this:
Code:
while true; do date >> /var/log/perfmon.log; sleep 300; done &
vmstat 300 >> /var/log/perfmon.log &

Remember that you cannot run the vmstat command in a loop, as it will display cumulative stats the first time it runs.
# 3  
Old 05-17-2006
Got it running right, finally. And yes, I am actually running vmstat 3 10 (collecting for 30 seconds) in the script. Thanks for the input though.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with simple bash script involving a loop

Dear unix wizards, I'd be very grateful for your help with the following. I have a hypothetical file (file.txt) with three columns: 111 4 0.01 112 3 0.02 113 2 0.03 114 1 0.04 115 1 0.06 116 2 0.02 117 3 0.01 118 4 0.05 Column 2 consists of pairs of integers from 1 to 4 (each... (5 Replies)
Discussion started by: aberg
5 Replies

2. Shell Programming and Scripting

[Solved] Simple script not working- for loop

Hi all, Please guide me writing this script Follwing is the file which I have created, which contains the files to be copied. cat system1-dr.txt /etc/passwd /etc/shadow /etc/group /etc/vfstab /etc/profile /etc/default/init /etc/shells /etc/dfs/dfstab /etc/dfs/sharetab... (11 Replies)
Discussion started by: manalisharmabe
11 Replies

3. Shell Programming and Scripting

simple while loop script to check a connection

Hi, I am completely new to shell scripting. Basically I am wanting to create a simple while loop script to check if a network connection is available from 'netstat -a' and if its present then output a character to the serial port. I think i am nearly there.. but need some assistance.. this is... (9 Replies)
Discussion started by: zippyzip
9 Replies

4. Shell Programming and Scripting

Simple while read line loop question

#!/bin/bash count=1 while read line do if (($count > 4)); then awk -v var1="$count" '{printf "%3s%8s%11s%11s%11s\n",var1,$2,$3,$4,$5}' else echo $line fi count=$((count+1)) done < posre_sub.itp > test cat test INPUT: ; position restraints for... (3 Replies)
Discussion started by: origamisven
3 Replies

5. UNIX for Dummies Questions & Answers

simple script with while loop getting problem

Hello forum memebers. can you correct the simple while program. #! /bin/ksh count=10 while do echo $count count='expr$count-1' done I think it will print 10 to 1 numbers but it running for indefinite times. (2 Replies)
Discussion started by: rajkumar_g
2 Replies

6. Shell Programming and Scripting

really simple for loop question

apologies for the basicness of this question, but within a for loop how can i "list" my values as opposed to adding them to the same line for example if i use this it works fine for n in peter paul david do echo "my name is $n" done but i wanted to list my items ( i have quite a... (2 Replies)
Discussion started by: rethink
2 Replies

7. Shell Programming and Scripting

Simple LOOP script help

I am trying to create a simple ksh loop script. What I've pasted below is not working. Any help is appreciated. typeset -i count typeset -i tcount count=0 tcount=0 while $tcount >= 11 do print "\$count is $count" pwd ls -l sleep 30 $(( $tcount = $count + 1 )) ... (5 Replies)
Discussion started by: musikman65
5 Replies

8. Shell Programming and Scripting

Simple for loop question

Hello I am a beginner of shell scripting and i am having trouble to do a for loop. I want a for loop to do stuff 3 times. i.e. in visual basic i do this for (counter = 0; counter < 3; counter++) on my shell script i have something like this at the moment ... (7 Replies)
Discussion started by: arex876
7 Replies

9. Shell Programming and Scripting

Simple for script question

I haven't done any scripting for quite a while and was trying to remember how to do a script with a for loop that uses another command for input straight from the terminal, IE: for num in `cat somefile | awk <whatever>` do echo $num; echo blah; echo blahblah; done; Hopefully something quick... (1 Reply)
Discussion started by: Vryali
1 Replies

10. Shell Programming and Scripting

Simple while loop question

I have written a script that countsdown from 20 to 1 and has a sleep in between each count but I want to make it sleep for half a second but I get errors whenever I change the sleep from 1 second to half a second any ideas? I am using Sun OS 5.9 heres what I've got: X=0 while do echo... (3 Replies)
Discussion started by: Brokeback
3 Replies
Login or Register to Ask a Question