这是一个简单的脚本,仅用于查看文件是否已下载.在此脚本中,即使找不到任何内容,find命令的求值始终为零.所以我把它注释掉了.
This is a simple script just to see if the file has been downloaded. On this script the find command always evaluated to zero - even if it didn't find anything. So I commented it out.
上,我必须在文件名的末尾添加下划线.
on the filename="day_CTRwFEES_hoo01M_" I had to add an underscore to the end of the filename.
使用下划线$filename_$yesterday.CSV将两者分开是无效的. -我必须去掉下划线,将其添加到文件名中,然后组合变量以使其按以下方式工作-$filename$yesterday.
Using an underscore $filename_$yesterday.CSV to separate the two did not work. - I had to take out the underscore, add it to the filename and then combine the variables to make it work like this - $filename$yesterday.
如何在不将下划线添加到变量$filename末尾的情况下使其工作?
How could I get it to work without adding the underscore to the end of the variable $filename?
#!/bin/bash set -x dayofweek=$(/bin/date +%w) today=$(/bin/date +%Y%m%d) yesterday=$(/bin/date -d "1 day ago" +%Y%m%d) friday_morning=$(/bin/date -d "3 days ago" +%Y%m%d) filename="day_CTRwFEES_hoo01M_" #if find /data/today/ -type f -name "$filename_$yesterday.CSV" ; then if ls "/data/today/$filename$yesterday.CSV" ; then echo "successful" else echo "$filename$yesterday.CSV was not downloaded, please check." | mail -s "$filename$yesterday.CSV not downloaded" casper@big_bank fi casper@good_host5981dap:~/walt/morning_checks$ ./check_day_CTRwFEES_hoo01M ++ /bin/date +%w + dayofweek=5 ++ /bin/date +%Y%m%d + today=20141024 ++ /bin/date -d '1 day ago' +%Y%m%d + yesterday=20141023 ++ /bin/date -d '3 days ago' +%Y%m%d + friday_morning=20141021 + filename=day_CTRwFEES_hoo01M_ + ls data/today/day_CTRwFEES_hoo01M_20141023.CSV /data/today/day_CTRwFEES_hoo01M_20141023.CSV + echo successful successful〜
推荐答案通过告诉bash变量名在何处结束.
By telling bash where the variable name ends.
"${filename}_$yesterday.CSV"更多推荐
bash变量插值用连字符或下划线分隔变量
发布评论