I want to make a delayed background execution, for delay I use sleep [anyseconds] && [execution]
for background I use nohup
Simple example of nohup
alone:
nohup date &>> out.log &
And of course you can find print out of the execution of date
in out.log
.
But I want to delay the execution, like 15 seconds, so a little combination:
nohup sleep 15 && date &>> out.log &
This time it does not work properly, sleep 15
got executed while the date
will not always do – If you shut down the terminal, it will not execute anything after the &&
.
What is wrong with nohup
? It surrenders to &&
??
Best Answer
I assume you are in bash, where
nohup
is a command of the system (coreutils).In bash the
&&
mark the end of a commandline. In your case thenohup
gets from the shell only the parameterssleep 15
. All the rest is the next command for the shell.As
nohup
is not a shell, you can not use parenthesis to "extend" the parameters tonohup
, becausenohup
can not interpret it and does not know what to do with it.One solution would be to create a script (e.g.
sleepdate
) which containssleep 15 && date
and use this as parameter tonohup
:or use the bash (which can interpret
&&
) as parameter tonohup