Bash 脚本检查 ftp 上的实际日期文件
Bash script check actually date files on ftp
我有简单的脚本:
lftp user@server -e "cd dir && ls -ltr ;exit" > list.txt
if files=$(cat list.txt | grep "`date | awk '{print " "}'`") ; then
echo "$files" | mailx -s "File exists" name@name.com
else
echo "$files" | mailx -s "File not exists" name@name.com
end if
问题是因为这个来自文件的 grep 日期不能正常工作,有时是工作。
如果实际日期文件存在,有人可以告诉我什么是检查 ftp 服务器并给我发送电子邮件的更好方法吗?
我认为这里可能存在三个问题。第一个是 date | awk '{print " "}'
在天数的末尾包含一个逗号。第二个是天数由 ls
和 date
填充 space,但 awk
将去除填充。第三个是 bash
中 if
的终止符是 fi
而不是 end if
.
尝试
if files=$(grep "`date '+%b %e'`" list.txt); then
echo "$files" | mailx -s "File exists" name@name.com
else
echo "$files" | mailx -s "File not exists" name@name.com
fi
date
中的 %e
假定 ls
returns 一个 space 填充的天数。如果您的系统使用零填充的天数,请尝试 %d
.
我有简单的脚本:
lftp user@server -e "cd dir && ls -ltr ;exit" > list.txt
if files=$(cat list.txt | grep "`date | awk '{print " "}'`") ; then
echo "$files" | mailx -s "File exists" name@name.com
else
echo "$files" | mailx -s "File not exists" name@name.com
end if
问题是因为这个来自文件的 grep 日期不能正常工作,有时是工作。
如果实际日期文件存在,有人可以告诉我什么是检查 ftp 服务器并给我发送电子邮件的更好方法吗?
我认为这里可能存在三个问题。第一个是 date | awk '{print " "}'
在天数的末尾包含一个逗号。第二个是天数由 ls
和 date
填充 space,但 awk
将去除填充。第三个是 bash
中 if
的终止符是 fi
而不是 end if
.
尝试
if files=$(grep "`date '+%b %e'`" list.txt); then
echo "$files" | mailx -s "File exists" name@name.com
else
echo "$files" | mailx -s "File not exists" name@name.com
fi
date
中的 %e
假定 ls
returns 一个 space 填充的天数。如果您的系统使用零填充的天数,请尝试 %d
.