I have a shell script that looks something like the following:
mysql -uroot db1 < db1.sql
mysql -uroot db2 < db2.sql
mysql -uroot db3 < db3.sql
mysql -uroot db4 < db4.sql
....
different db names in more than 160 lines.
I want to run this script with nohup and have a status later.
So, basically, I need a quick fix to insert another line after each restore command above that says the database is restored.
mysql -uroot db1 < db1.sql
echo db1 is restored
mysql -uroot db2 < db2.sql
echo db2 is restored
mysql -uroot db3 < db3.sql
echo db3 is restored
mysql -uroot db4 < db4.sql
echo db4 is restored
....
How can this be done with vi and unix utilities?
Thanks in advance,
-MKH
I can make all sorts of modifications/additions on the same line. My challenge is adding the new line. I created the script using
ls -l | awk '{print $9}' > restore.sh
and then using different vi/awk commands to modify the lines into single mysql restore lines.
I ran the script overnight, but was looking for ways to report the status of the restore.
Looks like you didn't know that you can put two commands on the same line, separated by a semicolon. With this trick you might have been able to manage it yourself.
mysql -uroot db1 < db1.sql; echo db1 is restored
Important note: simply echo-ing that something happend - especially like you intend to do here - is not something you can really rely on, thus I suggest following solution:
mysql -uroot db1 < db1.sql && echo "db1 is restored" || echo "db1 restore failed"
Otherwise your report will say that the db was restored even if the restore failed, for whatever the reason.