Shell Script to Repeat the Execution of Command / Job Based on Time Interval Periodically

_____________________________________________________________________________________________________________________


Suppose if you are copying some huge files from server to another server and you wanted to see the progress in size, number you can use these scripts. These scripts will run periodically according to the sleep commands.

Using yes Command

To find the size of the files copied.
yes "date;ls -ltr * |awk '{ sum+=\$5 } END {print \"Bytes InGb:\" sum/1024/1024/1024}'; sleep 60" | sh
To find the number of files copied.
yes "date;ls -l|wc -l; sleep 60" | sh

Using while loop
while true
do
date
ls -ltr * |awk '{ sum+=$5 } END {print "Bytes In Gb:" sum/1024/1024/1024}'
ls |wc -l
sleep 60
done

Examples:
while true
> do
> date
ls -ltr * |awk '{ sum+=$5 } END {print "Bytes In Gb:" sum/1024/1024/1024}'
ls |wc -l
> sleep 60
> done
Wed May 22 09:10:12 CEST 2013
Bytes In Gb:0.089733
9

_____________________________________________________________________________________________________________________

0 comments:

Post a Comment

 

acehints.com Copyright 2011-17 All Rights Reserved | Site Map | Contact | Disclaimer | Google