Nohup error

Hi,

I tried to run a script as a back end process and getting below error for nohup command in solaris10.

Any help will be great.

server1# nohup (time ./genrep) > genrep.log 2>&1
ksh: syntax error: `(' unexpected

Able to run genrep a standalone but getting error when i try with time using nohup.

Why are you trying to run the backend process in a sub-shell?

Doesn't the following (without the parentheses) do what you need to do?:

nohup time ./genrep > genrep.log 2>&1

Thanks Don.

when i execute that and logout the script gets disconnected. Am i missing anything here.

Idea is to execute the script in back end even though i logout my session. so trying to execute as below

nohup time ./genrep > genrep.log 2>&1 &

First, time is a shell builtin and likely won't work in that context. You might have to do something like ksh -c "time ./gengrep"

Also, I'm not sure if stdin is redirected.

Also, if you're using ksh, you should disown the process after you background it.

How about:

nohup ksh -c "./genrep" >/dev/null 2>/dev/null </dev/null & disown
1 Like

In ksh , time isn't just a shell built-in; it's a shell keyword. (I'm sure Corona688 understands the difference, but for other readers who may not, it matters when you want to time a pipeline consisting of more than one process. In a shell where time is a keyword:

time a | b | c

will give you timing results for the entire pipeline. In a shell were time is a built-in, that command will just give you timing results for the execution of a ; not the entire pipeline.) The POSIX standards allow time to be either a keyword or a built-in.

Note also that disown with no operands will disown all active background jobs started by the shell; not just the most recently started background job. If that isn't what you want, you might want to try something more like:

nohup ksh -c "time ./genrep" < /dev/null > genrep.log 2>&1 & disown $!
1 Like

Beware that the non POSIX "disown" utility is not available to the OP who is running Solaris 10. "disown" is only implemented in Solaris 11.

In any case, "disown" is not required here, being redundant. The "nohup" call is already disconnecting the launched process from the running session so there is no reason to try to do it twice.

1 Like