[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: OT: A question about bash scripting



On Mon, 2012-10-29 at 21:31 +0000, Dom wrote:
> Would this do what you are after?
> 
> ### Killall and Restore session
> started=$(date +%s)
> sleep 2
> 
> ### Time
> month=$(date +%B)
> mon=$(date +%b)
> d_y_t=$(date '+/%d/%Y %T')
> done=$(date +%s)
> echo
> printf "Attended time to restore session:      %4d:%02d\n" 
> $(((done-started)/60)) $(((done-started)%60))
> printf "Session restored at %9.9s%s\n" "$month" "$d_y_t"
> echo
> 
> (The first "printf" is a long line that will probably get spilt by 
> email. It should all be on one line).
> 
> Also the SECONDS shell counter variable is useful for this sort of thing.
> 
> For example:
> ### Killall and Restore session
> SECONDS=0
> 
> ...
> 
> done=$SECONDS

Thank you :)

that's it.

 started=$(date +%s)
 SECONDS=0
 sleep 72
 
 ### Time
 month=$(date +%B)
 mon=$(date +%b)
 d_y_t=$(date '+/%d/%Y %T')
 done=$(date +%s)
 done_2=$SECONDS

 ((seconds=(done-started)-(((done-started)/60)*60)+100))
 min_sec=$(((done-started)/60))":"${seconds: -2}
 echo
 echo    "Attended time to restore session:         $min_sec"
 echo -n "Session restored at " ; printf %9.9s $month ; echo $d_y_t
 echo

 ((min=(done_2/60))) ; ((sec=(done_2%60)))
 echo
 printf "Attended time to restore session: %9d:%02d\n" $min $sec
 printf "Session restored at %9.9s%s\n" "$month" "$d_y_t"
 echo

 ### Log file
 grep "Write to log file enabled." $log_file > /dev/null
 if [ $? -eq 0 ] ; then
  echo "   Restore: $min_sec $mon$d_y_t"        >> $log_file
  printf "   Restore: %s:%02d %s%s\n" "$min" $sec "$mon" "$d_y_t" >> $log_file
 fi

Regards,
Ralf


Reply to: