Loop
Some of the systems monitoring commands with built-in looping functionality, commands such as vmstat, iostat, .... Very often we would like to repeat the same command to monitor certain activities like file size, disk usage.
This shell function does exactly this:
loop() { sec=$1 shift cmd=$* while : do eval $cmd sleep $sec done }
Now you just have to provide the interval and the command you like to loop, just like this:
$ loop 5 df -h / Filesystem size used avail capacity Mounted on /dev/md/dsk/d30 5.9G 4.9G 931M 85% / Filesystem size used avail capacity Mounted on /dev/md/dsk/d30 5.9G 4.9G 931M 85% / Filesystem size used avail capacity Mounted on /dev/md/dsk/d30 5.9G 4.9G 931M 85% / ^C
Labels: shell script, unix
0 Comments:
Post a Comment
<< Home