I am trying to keep running of a command after logout from ssh. I used the commands nohup source a.sh > a.txt
and screen source a.sh > a.txt
. But both gives
nohup: failed to run command 'source': No such file or directory```
error. In one question, it is said that use the absolute path of command but I couldn't find the exact location of source command. But I can use nohup directly with other commands such as cp. How can I solve this issue or are there better alternatives?
source
there? It means to execute the named script in the same shell, but since you're starting an external command (screen
ornohup
) anyway...source
is not an external command. It is a shell built-in, and nohup needs an external command to run. Ifa.sh
is on your PATH list, is executable, and has a shebang, that by itself is the command, likenohup a.sh
. That is the proper way to do it. Otherwise,nohup bash a.sh
will runa.sh
even if it is not executable, and will ignore any shebang. Ifa.sh
is not in PATH, you will need to run it as./a.sh
or add whatever full pathname it is on. Note thatnohup
does not mean anything useful unless you also run it in background.