I would like to download and run a script in the background so the task is independent of the shell and its exit. Moreover this script should be run as
echo MY_PWD | sudo -u MY_USER -S ...
So it just needs a single line of code in my SSH-Session, which does the authentication and creates the background task including multiple lines. Furthermore the setup-script should be removed after the successful or unsuccessful execution of the NEW_SCRIPT_NAME.sh The lines of code are:
wget https://URL_TO_SCRIPT.sh -O NEW_SCRIPT_NAME.sh sed -i 's/\\r$//' NEW_SCRIPT_NAME.sh chmod +x NEW_SCRIPT_NAME.sh sudo nohup NEW_SCRIPT_NAME.sh & rm NEW_SCRIPT_NAME.sh
I tried to this:
echo raspberry | sudo -u pi -S wget https://URL_TO_SCRIPT.sh -O NEW_SCRIPT_NAME.sh && sed -i 's/\\r$//' NEW_SCRIPT_NAME.sh && chmod +x NEW_SCRIPT_NAME.sh && nohup ./NEW_SCRIPT_NAME.sh & && rm NEW_SCRIPT_NAME.sh
This causes the following error:
-bash: syntax error near unexpected token `&&'
Which can be fixed by removing the & in the
nohup line, but this will cause the script to be executed in foreground not in background, which is necessary for my purposes.