检查 file.html 是否存在的脚本,如果存在,则运行另一个脚本,否则会死掉?

发布于 2024-12-07 17:10:54 字数 136 浏览 2 评论 0原文

所以我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

和我恋爱吧 2024-12-14 17:10:54

多种方法之一是使用test

#!/bin/bash
test -f filename && script/command_to_be_executed

等效:[] => test

#!/bin/bash
[ -f filename ] && script/command_to_be_executed

上面的行意味着如果 test 成功,则执行 && 之后指定的操作,否则不执行。在这种情况下,-f 意味着测试文件是否存在,如果名为 filename 的文件退出,则执行后续指定的操作 &&< br>
filename 替换为要检查的文件 (file.html) 的绝对路径,后跟要在后面运行的命令或脚本 &&
希望这有帮助!

One of the many ways would be to use test.

#!/bin/bash
test -f filename && script/command_to_be_executed

equivalent: [] => test

#!/bin/bash
[ -f filename ] && script/command_to_be_executed

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 name filename 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!

转身泪倾城 2024-12-14 17:10:54

这是一个 bash 脚本,可能会让您朝着正确的方向前进:

#!/bin/bash
FileYouWantToTest='/directory/filename.ext'
echo -n "Verifying if $FileYouWantToTest exist..."
if [ -f $FileYouWantToTest ]
    then
        echo  "OK"
    else
        echo  "FAIL"
fi
exit 0

复制代码,将其保存在以 .sh 结尾的文件夹中,并确保它是可执行的......然后在 shell 中运行......
高级 Bash 脚本

Here is a bash script that might get you going in the right direction:

#!/bin/bash
FileYouWantToTest='/directory/filename.ext'
echo -n "Verifying if $FileYouWantToTest exist..."
if [ -f $FileYouWantToTest ]
    then
        echo  "OK"
    else
        echo  "FAIL"
fi
exit 0

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文