nohup - Not printing all logs - linux

I am running two scripts
# Script 1
nohup sh {command} &
and the nohup.out is having all logs in details (for script 1)
# Script 2
nohup sh {command} > {log_path} 2>&1 &
But nohup.out having only limited log as listed below (for script 2),
## Script2 output
Shutdown message has been posted to the server.
Server shutdown may take a while - check logfiles for completion
How can i generate all logs by using script 2 format in nohup.out itself .

If you want to have both files (nohup.out and {log_path}) you can try:
((nohup {command}) > >(tee {log_path}) 2> >(tee {log_path}))>> nohup.out
the first part of the command line is explained here.
After this, you only have to redirect (append) output to nohup.out.

Related

While writing shell script after nohup command script is stuck

I am writing a shell script
After the execution of nohup command it is not going to next line
Just getting stuck indefinitely after execution of nohup
I am giving following command in script
nohup ./myscript.sh & sleep 30s && tail -30f nohup.out | grep -i "my desired output"
What I am trying to do is
Running the script using nohup command
Sleep 30s
tail from nohup.out file
Then using the output from nohup.out file to find the string I want
after the execution of this command
It prints the desired string perfectly from the nohup.out file but
Afte the execution of this line it does not move forward
Please suggest a way to execute lines after this command

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

nohup command not working in chef resources

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 &

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