0

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?
3
  • Why are you using source there? It means to execute the named script in the same shell, but since you're starting an external command (screen or nohup) anyway... Commented May 24, 2023 at 20:08
  • What can I use instead of source Commented May 24, 2023 at 20:54
  • 2
    source is not an external command. It is a shell built-in, and nohup needs an external command to run. If a.sh is on your PATH list, is executable, and has a shebang, that by itself is the command, like nohup a.sh. That is the proper way to do it. Otherwise, nohup bash a.sh will run a.sh even if it is not executable, and will ignore any shebang. If a.sh is not in PATH, you will need to run it as ./a.sh or add whatever full pathname it is on. Note that nohup does not mean anything useful unless you also run it in background. Commented May 24, 2023 at 21:45

1 Answer 1

0

Why are you using "source?" Just do this...

chmod 700 a.sh
nohup ./a.sh > a.txt & 

In a.sh, be sure you've specified the shell it should use as it's interpreter. (ie. #!/bin/sh)

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.