[英]Adding current date and time into a bash script echo command
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. 我想将当前日期和时间添加到每次完成步骤时都会显示到屏幕上的echo命令。
So my command creates and inserts about 20 databases. 因此,我的命令创建并插入了大约20个数据库。 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. 通过使用反引号,可以使用date命令的结果 。 If you need another date format, just see what "date --help" has on offer. 如果您需要其他日期格式,请查看提供的“ date --help”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.