nohup command not working in chef resources - linux

I am trying to execute
>nohup.out
nohup ./example.sh &
which comes under my main.sh file. I am calling the main.sh from my bash resource in Chef. However, the STDERR is thrown when I run the chef-client. Shouldn't it go to nohup.out ?

From nohup manual:
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.
So to have stderr redirected to nohup.out you should first redirect it to stdout:
nohup 2>&1 ./example.sh &

Related

Where will be nohup file created/stored

On executing below given command within a script file:
Command :
nohup /usr/hp/ism/jboss-3.2.8.SP1/bin/run.sh &
Where will the nohup.out file be created, assuming that script is running in root directory ?
Could you check home directory.
also you can redirect as below;
nohup /usr/hp/ism/jboss-3.2.8.SP1/bin/run.sh &> /tmp/nohup.out
man nohup ;
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'.
Running a python code using nohup and & the nohub.out was in the same directory as the command was run from
pwd output:
/home/dv/project7
command run:
nohup python3 /home/dv/project7/test_code_v3.1.py &
ls -l output:
test_code_v3.1.py
nohup.out
I think a better way is so that your program outputs to your own error log file vs. stdout thgerefore to nohub.out

can't see nohup command's output when used with ssh

I am trying to run a jar onto a different server. So, in my current script I do ssh on that server, and then run the jar using nohup. But, nohup.out is not getting created on the new server. So, I am not able to catch errors.
If, I log into that server manually and then fire the jar, nohup.out gets created. Can someone please help with this?
Below is the command that I've written in my script:
sshpass -p $node_pwd ssh -n root#$node "sh -c 'cd mydir;nohup java -jar NodeStarter.jar config.properties > /dev/null 2>&1 &'"
Here, node is the server I am logging into.
node_pwd is the variable containing the password for that server.
nohup java -jar blah.jar > /dev/null 2>&1
In this example, you are redirecting your output from stderr to stdout, but you have already redirected your output from stdout to /dev/null.
The result is that you are piping both stdout and stderr to /dev/null
Output only goes to nohup.out if it has not already been redirected.
It is likely you are not using the same redirection parameters when running the command from the shell.

huponexit off and ampersand inputted - but program still close

[oracle#centos1 ~]$ shopt | grep hupon
huponexit off
[oracle#centos1 ~] sqldeveloper & -- program is being ran
With the above, it is already stated that there will be no hup signal sent on exit. But when I close the shell, the program still gets closed.
Why ?
It's probably because sqldeveloper is attached to the terminal. nohup works because it detaches the command automatically — see this excerpt from nohup(1):
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'.
It should work without nohup if you do it by hand — try for example:
sqldeveloper < /dev/null &> /dev/null &

How can I 'nohup' a command and log the output of 'time'

I want to time a long running script, and log the output of the time command to a log file, like so:
(time php mylongcommand.php) &> dump
This works, but what if I want to nohup the command so I can check the logs later. The following code does not work:
nohup (time php mylongcommand.php) &>dump &
Any suggestions?
(time php mylongcommand.php) &> dump < /dev/null &
Should also do the trick. By redirecting input from /dev/null and using & to put the process into the background, the same effect is obtained as if you used nohup. You should be able to exit your shell session without any stopped jobs error, and the process will continue to run.
Remove the brackets:
nohup time php mylongcommand.php &> dump &

Linux: Daemon and Daemon output to be logged in a file

I am using the below command to run my python code as a daemon on the server.
nohup python mycode.py >> log.txt 2>&1 &
For some reason unknown to me only few lines are getting written to the file.
Thanks in advance
nohup itself writing output in nohup.out so no need to redirect output to log.txt,bydefault all output will be redirected to nohup.out

Resources