检查 file.html 是否存在的脚本,如果存在,则运行另一个脚本,否则会死掉?
所以我有一个 cron 作业,偶尔会生成一个 html 文件到某个目录。它每小时运行一次此过程。我正在寻找一个脚本,我可以在此脚本之后运行该脚本来检查该文件是否存在,如果存在,则将其通过电子邮件发送到电子邮件地址(即我的手机)以进行监控。有什么想法吗?谢谢!
So i have a cron job that occaisonally produces a html file to a certain directory. It runs this process once an hour. Im after a script that i can run after this one to check for the existance of this file and if it exists, emails it to a email address (namely my phone) for monitoring purposes. Any ideas? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
多种方法之一是使用
test
。等效:
[]
=>test
上面的行意味着如果
test
成功,则执行&&
之后指定的操作,否则不执行。在这种情况下,-f
意味着测试文件是否存在,如果名为filename
的文件退出,则执行后续指定的操作&&
< br>将
filename
替换为要检查的文件 (file.html) 的绝对路径,后跟要在后面运行的命令或脚本&&
希望这有帮助!
One of the many ways would be to use
test
.equivalent:
[]
=>test
The above line implies that if the
test
succeeds then perform the operation specified after&&
, not otherwise. In this case,-f
implies testing for file existence, if file by the namefilename
exits perform the operation specified succeeding&&
Replace
filename
with absolute path of the file (file.html) you want to check for, followed by command or script you want to run succeeding&&
Hope this helps!
这是一个 bash 脚本,可能会让您朝着正确的方向前进:
复制代码,将其保存在以 .sh 结尾的文件夹中,并确保它是可执行的......然后在 shell 中运行......
高级 Bash 脚本
Here is a bash script that might get you going in the right direction:
copy the code, save it in a folder with .sh as the ending, and make sure it is executable... then run in the shell..
Advanced Bash Scripting