首先,我是一个Windows用户,但现在正在接受Linux的任务。我正在使用incrontab
来观看Oracle Linux服务器上的目录。Incrontab不处理IF语句
我试图修改它,以便如果它看到文件F078311
它将回声测试到日志文件。否则,它将检查文件是否匹配第二种格式并执行该回声。
它正在运行第二个IF并将日期回显到日志中,但未将测试回显到日志。我的语法有什么问题吗?
它正在看着目录/export
。和$1
将/export/F073811
incrontab -l
/export IN_MODIFY,IN_CLOSE_WRITE,IN_MOVED_TO /usr/local/scripts/EXPrename.sh [email protected]/$#
shell脚本:
#!/bin/bash
# This file is invoked using incron and will rename the file with the current date.
# Set newdate as current date, YYYYMMDD-HHMMSS
newdate="$(date +%Y%m%d-%H%M%S)"
#Sets the filename as the filename_YYYYMMDD-HHMMSS
filename="A$newdate.txt"
joblog="/logs/joblog.log"
[[ ($1 =~ F073811$) ]] && echo Test >> /logs/joblog.log
#checks to file format to see if it looks like name_YYYYMMDD-HHMMSS. If it does not then it renames the file to that format.
[[ ! ($1 =~ A[0-9]{8}-[0-9]{6}\.txt$) ]] && echo ---- `date` ------ >> "$joblog"
你能打印'$ 1'吗? –
'/ export/F073811' – Travis