Programmatically restart Appium through script executed remotely

Hello Everyone!
I am trying to restart Appium periodically. I have 2 simple scripts (startAppium.sh and stopAppium.sh) on the box hosting Appium. Here is what the startAppium.sh script looks like:

echo “Starting Appium” /Applications/Appium.app/Contents/Resources/node_modules/appium/bin/appium.js --debug-log-spacing --nodeconfig “/Users/qaadmin/Documents/appium_node_config.json” --platform-version “9.2” --platform-name “iOS” --safari --browser-name “Safari” --full-reset --device-name “iPhone 6” --native-instruments-lib

This works great when I try to run the script on the box itself. However, when I do it remotely through the following command:
ssh [email protected] /Users/qaadmin/startAppium.sh
I get the following error: "env: node: No such file or directory"

I am puzzled as if I first ssh to the box with the same user and execute the script, all works well. What am I missing?

You are looking at a permissions issue. Users are by default not allowed to look in each other’s home directories and execute scripts. You may also be looking at file permissions issues. Here’s what to do:

  1. Put your executable into ‘/usr/local/bin’, and make sure that is on the $PATH (check by logging in as the user in question and issuing ‘echo $PATH’ on the command line). More info here:
  1. Make sure your user has permission to execute the file. You could probably just do a ‘chmod +x /usr/local/bin/startAppium.sh’ on the command line. More info here:

https://kb.iu.edu/d/abdb

I try to move the executable script and see if that solves the issue. Permissions are unlikely the culprit as I am able to execute the script when I first ssh with the same user and then execute the script (instead of doing both within the local script). Also, I have no issues remotely running stopAppium.sh that is in the same directory, with the same set of permissions. Here is the content of my stopAppium.sh:
echo “Attempting to stop Appium if already running.”
ps -ef | grep ‘appium.js’ | grep -v grep | awk ‘{print $2}’ | xargs kill

Moving the executable file to /usr/local/bin did not make a difference :frowning:

I figured it out. Looks like env variables are not loaded when I ssh to the remote host. I ended up adding node location to the startAppium.sh script and working fine now.