go exec 命令到许多打开的文件
我创建了一个 cron 来每 1 分钟检查一次服务器是否关闭。如果关闭,代码将执行 run myfile.sh
命令。在 myfile.sh
内部,我放置了用于执行 modvendor
和 build main.go
的代码,
if isDown == true {
rescmd, reserror := exec.Command("/bin/sh","-c","sudo MY/PATH/MYFILE.SH").Output()
if reserror != nil{
fmt.Println("error %s", reserror)
}
}
上面的代码对我来说工作得很好。但有时会出现错误对许多打开的文件
。
当发生如上所述的错误时,我尝试使用 sudo MY/PATH/myfile.sh 运行我的 .sh 文件手册并且服务器成功执行,但是当我使用>exec.Command(等待我的 cron 每 1 分钟运行一次)服务器将显示错误到许多打开的文件
代码有问题吗?
I create a cron to check if server is down or not for every 1 minutes. and if down the code will execute command for run myfile.sh
. Inside myfile.sh
I put code for execute mod vendor
and build main.go
if isDown == true {
rescmd, reserror := exec.Command("/bin/sh","-c","sudo MY/PATH/MYFILE.SH").Output()
if reserror != nil{
fmt.Println("error %s", reserror)
}
}
above code working fine for me. But sometimes error says to many open files
.
when an error occurs as above I try to run my .sh
file manual using sudo MY/PATH/myfile.sh
and server success to execute, but when I use exec.Command
(waiting my cron for every 1 minutes to run it) server will display error to many open files
Is there something wrong with the code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论