1

It errors when run from /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!

Executing the script directly works fine

The script is a copy of the 'skeleton' example in /etc/init.d (only changed the below section)

#!/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 <foobar@baz.org>
#
# 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

Script below

#!/bin/sh
echo '<passwd>' | sudo openconnect --user=aname@somedomain.com --passwd-on-stdin https://xxxx.somedomain.com
  • Make sure that #! are the first two bytes in the file (no spaces/new lines before it) – skarface Apr 5 '16 at 15:52
  • Thanks, checked and no space or line breaks above the #! , I have also run update-rc.d, changed permissions to 755 and root:root owner without success – Conor Apr 5 '16 at 16:27
  • share the output of file /usr/local/bin/op_connect.sh – sureshraju Apr 5 '16 at 17:31
  • Sorry I cannot share the output as its a corporate box so I have to be extra careful in what I share but it opens the openconnect connection and keeps it alive – Conor Apr 5 '16 at 19:09
  • What did you use to write the script? Any chance that the #! is some unicode variant? – skarface Apr 5 '16 at 19:39
1

The shebang (#!) found at the beginning of files is actually the human-readable version of a magic number, which allows the exec function to establish the nature of the file, i.e. whether the file is an executable binary or a plain script.

Hence the error message Exec format error means that the exec function could not establish whether your script, op_connect.sh, is a script or a binary. This generally occurs because the shebang is somehow misspelled, including the presence of non-printable characters. The easiest thing is for you is to re-type the script, and to make sure that it is executable, which, if it were not so, would explain the puzzlement of the exec function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.