Personally I've had some very bad experiences with changing running scripts and therefor recommend to never ever ever do that. The last time is some while ago (~5 years?) so I'm not sure if things have changed in the mean while. It's just too unpredictable what will happen when you do.
About your other question regarding an estimated time, you could use something like this:
Code:
function eta { echo "$@" | awk '{ time=($4-$3)/($3/($2-$1)); printf("%dh%dm%ds\n",time/3600, time/60%60, time%60); }'; }
Then after each 'long running job' call this with 4 parameters:
o The time when your script started (in unix/epoch seconds)
o The time now (in unix/epoch seconds)
o The number of long running jobs that are finished
o The total number of long running jobs that have to be processed
So for example:
Code:
#!/bin/bash
function eta { echo "$@" | awk '{ time=($4-$3)/($3/($2-$1)); printf("%dh%dm%ds\n",time/3600, time/60%60, time%60); }'; }
start=$(date +%s)
for job in 1 2 3 4 5; do
echo "Start Job $job/5"
sleep $((RANDOM%10+5))
echo "Done Job $job/5"
eta $start $(date +%s) $job 5
done