'Can't start script via screen command

I have a script, and I want to make it work in background after boot. Therefore, I added the command below into rc.local. However, it doesn't work.

sudo -iu executerroot screen -dmS test bash -c "bash /home/pi/FileServer/Run; exec bash"

Also I've tried commands in https://askubuntu.com/questions/261899/run-a-screen-session-on-boot-from-rc-local site but no one worked for me. If I execute

sudo -iu executerroot screen -dmS test bash -c "bash /home/pi/FileServer/Run; exec bash"

I get this:

bash: /home/pi/FileServer/Run/: No such file or directory

while it doesn't work for real files. When I type "screen -r" I get just blank bash screen if a file exists.

I can't figure out why it doesn't work. Please explain why it happens and how can I solve this. Thanks...



Solution 1:[1]

After years, I got a similar problem today. This time I was trying to call the screen program inside crontab. I realized I needed absolute paths and correct bash version in crontab as well as in the script itself.

I think I had done a similar mistake 6 years ago. I wrote similar program today, probably, due to different environment variables, script didn't be able to find programs (in my case openvpn). Even program &> output.txt didn't work. The problem was the different bash version not supporting output redirection. I used /usr/sbin/bash -c "command" to cope with it. Also, openvpn is not in the path in that crontab environment, so I had to call it with absolute path (like /usr/sbin/openvpn). Then, it worked.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 F. Eser