0

I ran the following command

nohup conda activate shuffle_pair_end_reads && python3 shuffle_pair_end_reads.py \
    fastp-filtered-merged4racon/merge_R1.fq.gz \
    fastp-filtered-merged4racon/merge_R2.fq.gz \
    >fastp-filtered-merged4racon/merged_R1_R2.fa \
    2>merged_R1_R2.log &

but unfortunately, I got this after I pressed the second time enter

 nohup: ignoring input and appending output to 'nohup.out'

[1]+  Exit 1                  nohup conda activate shuffle_pair_end_reads && python3 shuffle_pair_end_reads.py fastp-filtered-merged4racon/merge_R1.fq.gz fastp-filtered-merged4racon/merge_R2.fq.gz > fastp-filtered-merged4racon/merged_R1_R2.fa 2> merged_R1_R2.log

What did I miss?

Thank you in advance,

  • You should at least know that the command after && has nothing to do with nohup and nohup knows nothing about them. – Weijun Zhou Mar 15 '19 at 16:19

1 Answers1

1
$ type -a nohup
nohup is /usr/bin/nohup

Nohup is not part of the shell syntax. It is just an executable, which means you cannot just type arbitrary command and prefix it with nohup to expect it to be executed with SIGHUP ignored. In the case of

nohup conda activate shuffle_pair_end_reads && python3 shuffle_pair_end_reads.py \
    fastp-filtered-merged4racon/merge_R1.fq.gz \
    fastp-filtered-merged4racon/merge_R2.fq.gz \
    >fastp-filtered-merged4racon/merged_R1_R2.fa \
    2>merged_R1_R2.log &

nohup is executed with the arguments conda, activate and shuffle_pair_end_reads. Everything after the first && is another simple command. nohup knows nothing about it and cannot control the behavior of it.

As it is written, it means executing conda activate shuffle_pair_end_reads with SIGHUP ignored, then if nohup succeeds, process to the python script.

As for the redirection of stdin and stdout, the man page has stated clearly about it.

If standard input is a terminal, redirect it from /dev/null. If standard output is a terminal, append output to 'nohup.out' if possible, '$HOME/nohup.out' otherwise. If standard error is a terminal, redirect it to standard output. To save output to FILE, use 'nohup COMMAND > FILE'.

In your case, the input of your command is not redirected, so nohup redirects it for you from /dev/null. Similarly, nohup redirects the standard output to nohup.out for you, issuing a warning (note this is just a warning) "ignoring input and appending output to 'nohup.out'" and writing the warning to stderr.

As for the exit status of nohup, this question explains it well. You need to check by yourself why the command nohup conda activate shuffle_end_reads is issuing an exit status of 1.

Using nohup as though it were part of the bash syntax can lead to funny errors. One of the simplest,

nohup cd myfolder && ./script.sh &

will fail with the following message written to stderr:

nohup: ignoring input and appending output to 'nohup.out'

nohup: failed to run command 'cd': No such file or directory

The first line is just a warning. The second line explains the error. nohup just tries to invoke its $1 as an executable and cd is never a standalone executable.

When I need to combine multiple commands for nohup, I usually use the syntax

nohup bash -c "long command" &

There may be better ways but that's what I use. In the example above, if there is really a reason that you cannot cd before nohup, I will do

nohup bash -c "cd myfolder && ./script.sh` &

One last thing to keep in mind is that your program may install its own signal handlers that makes nohup useless. As shown in this question.

Weijun Zhou
  • 3,368