bash 尝试运行脚本时出现 SNMP“exec 格式错误”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20023658/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 08:39:10  来源:igfitidea点击:

SNMP "exec format error" when trying to run a script

bashsnmp

提问by wolf2600

I'm using SNMPD to run a script on a Raspberry Pi with net-snmp. I was able to get the same script running on my Slackware machine, but on the Pi, under extOutput.1, I'm getting "Exec format error".

我正在使用 SNMPD 在带有 net-snmp 的 Raspberry Pi 上运行脚本。我能够在我的 Slackware 机器上运行相同的脚本,但是在 Pi 上,在 extOutput.1 下,我收到“Exec 格式错误”。

The batch file being called is set to 777 and is:

被调用的批处理文件设置为 777 并且是:

#! /bin/bash
/sbin/reboot

Everything I've found about the error says that I would just need to include the #! at the beginning of the file and that would fix it, but it doesn't. I can run the script from the command prompt just fine, and /bin/bash obviously works also, but when called through SNMP (both snmpget and snmpwalk), the extOutput.1 line gives me that error.

我发现的关于错误的所有内容都表明我只需要包含 #! 在文件的开头,这会修复它,但它没有。我可以从命令提示符运行脚本就好了,而且 /bin/bash 显然也可以工作,但是当通过 SNMP(snmpget 和 snmpwalk)调用时,extOutput.1 行给了我那个错误。

回答by wolf2600

Ugh. I had a blank line at the top of the script before the #! line.

啊。我在#! 之前的脚本顶部有一个空行。线。