Run script on startup

Options
Thomas
Thomas New Member Posts: 18
edited April 2017 in UP Board Linux
Hello,
I would like to run the following simple script each time the up-board starts up

#!/bin/sh -
ifconfig wlan1 up
iwconfig wlan1 mode ad-hoc
iwconfig wlan1 essid "drone"
ifconfig wlan1 192.168.1.3 netmask 255.255.255.0

I put the following adhoc.service file in /lib/systemd/system and ran "systemctl daemon-reload" and "systemctl enable adhoc.service"

[Unit]
Description=SKYNET
After=

[Service]
ExecStart=/adhoc.sh
Restart=always
RestartSec=5s
Environment=NODE_ENV=production

[Install]
WantedBy=multi-user.target

When I reboot or start the script with "systemctl start adhoc.service" the status shows

Process: 4225 ExecStart=/adhoc.sh (code=exited, status=203/EXEC)

and the script never executes. I have made sure it is executable and it runs fine if I simply do ./adhoc.sh but using systemctl isn't working for some reason.

Can anyone see what might be going wrong? I would greatly appreciate anyones help with this!

Thanks,

Thomas

Comments

  • Dan O'Donovan
    Dan O'Donovan Administrator, Moderator, Emutex Posts: 241 admin
    Options
    A common problem with scripts that run fine from your interactive shell, but fail when run from a start-up script, is that environment variables such as $PATH may have different values or are not set at all within the start-up environment.

    I suggest, for example, using full absolute paths for the commands (e.g. 'iwconfig', etc.) you're running in your script. Or, alternatively, you can set a PATH variable at the top of your script for a similar effect.
  • Thomas
    Thomas New Member Posts: 18
    Options
    Thanks Dan! I put the script int /usr/bin/ since that is part of the $PATH and it works.

    Much appreciated,

    -Thomas