Looping a bash script
Here's the deal - Although I've been around Linux for several years, I'm still a scripting n00b in many ways.
What's going on... I am running Red Hat Enteprise Linux 4.x on a Dell PowerEdge 1750. Attached to it is a Dell PowerVault 220S configured as an 800 GB RAID 5. I am currently transferring 700+ GB of data from a TerraVault via a mounted SMB share to the 800 GB RAID 5. I am currently monitoring the progress manually via the following command shell command: [rhe4 ~]$ df -lh | grep "/dev/sdb1" /dev/sdb1 808G 194G 573G 26% /vol1 What I would ultimately like to do is the following: I'd like to append the output to file every 3 minutes until 730G has been reached. A time and date stamp would be nice too. Something along the lines of: Fri Sep 22 14:07:14 PDT 2006 /dev/sdb1 808G 194G 573G 26% /vol1 Fri Sep 22 14:10:34 PDT 2006 /dev/sdb1 808G 194G 573G 26% /vol1 Obviously I need to create some sort of while-do-loop but not really sure how to go about doing this and I'm not versed in sed/awk, ergo - the reason I need a little help here. Any takers? Thanks in advance! |
Put this in a file filename.sh
Code:
#!/bin/sh The sleep command is in seconds, so sleep 180 is 3 minutes. To kill it you'll have to CTRL+C. Otherwise, you can add a variable before the while loops starts and then increment it within the loop and exit when it has run a certain number of times. |
Stepping through...
Quote:
I got the filename, setting the environment... while true... hmmm... but what are we comparing it to? While -WHAT- is true? From what I can see... it's going to do the following... while true... (while the following is true...) do (do the following...) date - outputs date to stdout df -lh | grep "/dev/sdb1" - outputs drive info to stdout sleep 180 - pauses for 180 seconds (3 minutes) done - end loop Once the script reaches the done marker, there's nothing left to be "true" as we haven't compared the current data size x against the maximum (730G). Also, since the next itteration would be incremented by 3 minutes, it would no longer be true, but false. Also, we haven't appended anything to a log file... We're missing 2 key components. So in my seudo/quazi code here's the logic I am seeing... Start loop Append date to copystat.log Append df -lh | grep "/dev/sdb1" to copystat.log check df -lh | grep "/dev/sdb1" for current drive capacity if current drive capacity is less than 730G loop after 3 minutes else if current drive capacity is 730G or more, end loop Hope this helps. I'm not sure as to how to write a script to accomodate this logic. Thanks agian, |
I stand corrected
Quote:
So this is better than nothing. Thanks again |
Code:
#!/bin/bash |
Here's another crack (probably not the most elegant, but it worked for me assuming there's no way to jump from 729G to 731G in 3 minutes time)
Code:
#!/bin/sh |
All times are GMT -5. The time now is 08:01 AM. |