【发布时间】:2016-06-23 04:14:00
【问题描述】:
试图模拟一个小 shell 脚本.. 已经存在一个创建两个文件之一的进程(即 file1 或 file2)。我的目标是能够根据创建的文件发送电子邮件警报。
例如,如果 file1 存在,则向 John、David、Smith 发送电子邮件,说明 file1 已创建。如果 file2 存在,则向同一组人(John、David、Smith)发送一封电子邮件,说明 file2 已创建。
如果我编写一个简单的 if-else,它会起作用,但我需要重复一些我试图避免的代码部分。
#!/bin/bash
file="file1"
if [ -f "$file1" ]
then
send email to three people mentioned
else
send email to three people mentioned saying file2 was created since it always creates two files
fi
}
在这里,我正在尝试以更好的方式构建脚本,并且我不想重复三次“发送电子邮件...”命令,因为将来我可能需要将更多人添加到列表中。
请帮忙。提前致谢。
【问题讨论】:
-
虽然我无法说出任何名字,但已经有一些可用的软件包可以监视目录的更改并生成各种警报。您是否尝试过在 Internet 上搜索“目录监视器”?