从 /etc/init.d 运行时出错
sudo /etc/init.d/openconnect start
* Starting open connect xxx.somedomain.com openconnect
start-stop-daemon: unable to start /usr/local/bin/op_connect.sh (Exec format error)
...fail!
直接执行脚本就可以了
该脚本是 /etc/init.d 中“skeleton”示例的副本(仅更改了以下部分)
#!/bin/sh
### BEGIN INIT INFO
# Provides: skeleton
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Example initscript
# Description: This file should be used to construct scripts to be
# placed in /etc/init.d.
### END INIT INFO
# Author: Foo Bar <[email protected]>
#
# Please remove the "Author" lines above and replace them
# with your own name if you copy and modify this script.
# Do NOT "set -e"
# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
DESC="open connect XXXXXXX"
NAME=op_connect.sh
DAEMON=/usr/local/bin/$NAME
DAEMON_ARGS="--options args"
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
# Exit if
下面的脚本
#!/bin/sh
echo '<passwd>' | sudo openconnect [email protected] --passwd-on-stdin https://xxxx.somedomain.com
答案1
文件开头的 ( ) 实际上是魔术数字的人类可读版本,它允许函数确定shebang
文件的性质,#!
exec
IE该文件是可执行二进制文件还是纯脚本。
因此,错误消息Exec format error
意味着exec
函数无法确定您的脚本op_connect.sh
是脚本还是二进制文件。这通常是因为 拼写shebang
错误,包括存在不可打印的字符。对您来说,最简单的方法是重新输入脚本,并确保它是可执行的,如果不是这样,这就可以解释该exec
功能的难解之处。