Linux-ls-If语句
我在找一个if语句。所以,当我运行脚本时,它会给我一个带有日期的备份列表。if语句用于,如果最近2天没有备份,则回显“无最近备份” 对于当I ls-lrth时: -rw-r--r--。1 nfsnobody nfsnobody 1.5G 8月15日12:02 -rw-r--r--。1 nfsnobody nfsnobody 1.5G 8月16日01:30 如果日期早于2天,则返回“” 要获取过去2天的备份列表,请使用:Linux-ls-If语句,linux,shell,date,if-statement,ls,Linux,Shell,Date,If Statement,Ls,我在找一个if语句。所以,当我运行脚本时,它会给我一个带有日期的备份列表。if语句用于,如果最近2天没有备份,则回显“无最近备份” 对于当I ls-lrth时: -rw-r--r--。1 nfsnobody nfsnobody 1.5G 8月15日12:02 -rw-r--r--。1 nfsnobody nfsnobody 1.5G 8月16日01:30 如果日期早于2天,则返回“” 要获取过去2天的备份列表,请使用: find“$BACKUP\u DIRECTORY”-maxdepth 1-t
find“$BACKUP\u DIRECTORY”-maxdepth 1-type f-mtime-2-ls
。指定深度目录travesal。我们不希望在子目录中向下移动超过1级李>-maxdepth 1
表示只会找到文件(没有目录)李>-type f
表示文件的期限小于2天-mtime-2
wc-l
使用-mtime
和-name
BACKUP_DIRECTORY="basename" #basename of the directory
MATCHES=$(find "$BACKUP_DIRECTORY" -maxdepth 1 -type f -mtime -2 -ls | wc -l)
if [ $MATCHES -eq 0 ]; then
echo "CRITICAL: No files older than 2 days yet in directory $*"
exit 2
else
echo "OK: Found $MATCHES file(s) of the last 2 days in ${BACKUP_DIRECTORY}"
exit 0
fi