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

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.

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

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 &

Can we save the execution log when we run a command using PuTTY/Plink

I am using Plink to run a command on remote machine. In order to fully automate the process I
need to save the execution log somewhere. I am using a bat file:
C:\Ptty\plink.exe root#<IP> -pw <password> -m C:\Ptty\LaunchFile.txt
The C:\Ptty\LaunchFile.txt contains my command that i want to run.
./Launch.sh jobName=<job name> restart.mode=false
Is there a way to save the execution log so that I can monitor it later... ?
The plink is a console application. Actually that's probably it's only purpose. As such, its output can be redirected to a file as with any other command-line command/tool.
Following example redirects both standard and error output to a file output.log:
plink.exe -m script.txt username#example.com > output.log 2>&1
See also Redirect Windows cmd stdout and stderr to a single file.
This is the one of my way to log everything when I use putty.exe on Windows.

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

how to send output of ssh to /dev/null

I have a command that wants to connect remote server with ssh.My command is
"ssh -o PasswordAuthentication=no $REMOTE_HOST_IP > /dev/null 2>&1"
When this works the true message comes "Permission denied".It is the true message but i dont want to see message on console so i redirected it to /dev/null.But is still comes.What is the problem
Edit:
I tried as you say and taking 2&1 before /dev/null but still it does not work.But it is strange that it works on my friends computer
SOLVED:Problem is that I assigned the command to a variable and the run it as $command.But when it is set between "" redirection does not work
Look at -n option
-n Redirects stdin from /dev/null (actually, prevents reading from
stdin). This must be used when ssh is run in the background. A
common trick is to use this to run X11 programs on a remote
machine. For example, ssh -n shadows.cs.hut.fi emacs & will
start an emacs on shadows.cs.hut.fi, and the X11 connection will
be automatically forwarded over an encrypted channel. The ssh
program will be put in the background. (This does not work if
ssh needs to ask for a password or passphrase; see also the -f
option.)
Or even on -N
-N Do not execute a remote command. This is useful for just for‐
warding ports (protocol version 2 only).
Try
ssh -o PasswordAuthentication=no $REMOTE_HOST_IP &>/dev/null
ssh -o PasswordAuthentication=no $REMOTE_HOST_IP 2> /dev/null
Try this instead (moving the 2>&1 redirecting stderr before sending it to /dev/null):
"ssh -o PasswordAuthentication=no $REMOTE_HOST_IP 2>&1 > /dev/null"
Note that you are redirecting stderr to stdout with your 2>&1. If you just want to redirect stderr to /dev/null then simply use 2> /dev/null.
Good information about IO Redirection here.

Resources