I have a script that takes many hours to finish. I would like to add the current date and time to an echo command that prints to the screen every time a step completes.
So my command creates and inserts about 20 databases. some databases take several hours to insert so I would like to print the time each step finishes to the screen so you can know where in the process the restore is. Here is what I have so far.
#!/bin/sh
for DB_File in *.sql ; do
mysqladmin create ${DB_File%%-*}
echo ${DB_File%%-*} has been created. date +%x_%X
mysql ${DB_File%%-*} < $DB_File
echo $DB_File inserted into database. date +%x_%X
done
This should work:
for DB_File in *.sql ; do
mysqladmin create ${DB_File%%-*}
echo ${DB_File%%-*} has been created. `date "+%F %T"`
mysql ${DB_File%%-*} < $DB_File
echo $DB_File inserted into database. `date "+%F %T"`
done
By using backquotes the result of date command is used. If you need another date format, just see what "date --help" has on offer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With