提问人:Selvakumar Ponnusamy 提问时间:2/16/2012 最后编辑:tripleeeSelvakumar Ponnusamy 更新时间:12/3/2019 访问量:37435
如何从另一个 sh 文件运行 sh 文件
How to run sh file from another sh file
问:
我有一个用于监视我的应用程序的 shell 脚本文件,通过设置 cron 作业,此脚本将每 10 分钟执行一次。
我想再做一些与监控相关的脚本文件,这些文件应该与主文件一起执行。所以我想将我的脚本包含在主文件中。如何从主 sh 文件运行这些 sh 文件
答:
15赞
Behnam Safari
2/16/2012
#1
看看这个。如果要运行脚本,可以使用:
./yourscript.sh
如果脚本有循环,请使用:
./yourscript.sh&
如果要在启动脚本后获取控制台,并且不想看到它的输出,请使用:
./yourscript.sh > /dev/null 2>&1 &
因此,在主文件中,您将拥有:
./yourscript1.sh > /dev/null 2>&1 &
./yourscript2.sh > /dev/null 2>&1 &
./yourscript3.sh > /dev/null 2>&1 &
他们将一起开始。
评论
2赞
tripleee
2/16/2012
您应该避免重定向,至少在您知道自己在做什么之前。当您故意丢弃所有诊断程序时,调试故障是一场噩梦。
5赞
Kundan
12/3/2019
#2
创建 file1.sh
#! /bin/sh
echo "Hello World"
创建 file2.sh
#! /bin/sh
details = `./file1.sh`
echo $details
授予执行权限
chmod +x file1.sh
chmod +x file2.sh
现在运行您的文件
./file2.sh
输出
Hello World
评论