【发布时间】:2016-10-17 21:07:40
【问题描述】:
首先我是一个 Windows 人,但现在要负责 Linux。我正在使用 incrontab 监视 Oracle Linux 服务器上的目录。
我正在尝试修改它,以便如果它看到文件F078311,它会将测试回显到日志文件。否则它将检查文件是否匹配第二种格式并执行该回显。
它正在运行第二个 IF 并将日期回显到日志中,但没有将测试回显到日志中。我的语法有问题吗?
它正在监视/export 目录。和$1 将是/export/F073811
incrontab -l
/export IN_MODIFY,IN_CLOSE_WRITE,IN_MOVED_TO /usr/local/scripts/EXPrename.sh $@/$#
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