Operating System - HP-UX
1819805 Members
3166 Online
109607 Solutions
New Discussion юеВ

re-directing nohup to the terminal output instead of nohup.out

 
SOLVED
Go to solution
u856100
Frequent Advisor

re-directing nohup to the terminal output instead of nohup.out

Hi all,

bit emabarressed about asking this one.... I have gone completely blank.

how do you re-direct the output of the nohup command to the terminal (std.out) ?

nohup /scriptfile > ?????

thanks in advance

John
chicken or egg first?
12 REPLIES 12
harry d brown jr
Honored Contributor
Solution

Re: re-directing nohup to the terminal output instead of nohup.out


nohup scriptname 2>&1 | cat &

live free or die
harry
Live Free or Die

Re: re-directing nohup to the terminal output instead of nohup.out

Huh?

The whole point of nohup is that it keeps processes running when the tty disconnects (and sends a HUP signal to the process) If you are going to have your output going to the terminal the you shouldn't use nohup.

From the man page for nohup:

If output from nohup is redirected to a terminal, or is not redirected
at all, the output is sent to nohup.out.

What exactly are you trying to acheieve here?

HTH

Duncan

I am an HPE Employee
Accept or Kudo
Rodney Hills
Honored Contributor

Re: re-directing nohup to the terminal output instead of nohup.out

The very nature of "nohup" is to allow a process to execute detached from the terminal. The man page indicates if you attempt to redirct to the terminal, the output will still go to nohup.out.

If in a long running process you wish to follow the progress, you can do a-

tail -f outputfile

This will then display the output as it is generated.

-- Rod Hills
There be dragons...
PIYUSH D. PATEL
Honored Contributor

Re: re-directing nohup to the terminal output instead of nohup.out

Hi,

Nohup is meant to be run in background....why do you want to redirect it to a terminal. You can redirect it to a file instead.

piyush
Jeff Schussele
Honored Contributor

Re: re-directing nohup to the terminal output instead of nohup.out

By default std out goes to nohup.out
Try
nohup /scriptfile 1>/dev/ttydevice
1 is notation for std out.
You'll need to know just *which* tty to use - which could be problematic if run at odd times
/dev/console may be best bet to cover those situations.

But also note this entry in the man pages

"If output from nohup is redirected to a terminal, or is not redirected at all, the output is sent to nohup.out"

So you'll probably get the nohup.out files as well.

Rgds,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
Jeff Schussele
Honored Contributor

Re: re-directing nohup to the terminal output instead of nohup.out

Harry's answer works....somewhat.
You have to to get your prompt back.
Redirecting 1 alone does not work - the output will go to the file.

Rgds,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
harry d brown jr
Honored Contributor

Re: re-directing nohup to the terminal output instead of nohup.out

Jeff,

It's weird and I have never used it, prefering to use tail -f like someone mentioned to monitor the output, when and if I wish. Other wise you might as well forget the nohup and just use "&".

live free or die
harry
Live Free or Die
Carlos Fernandez Riera
Honored Contributor

Re: re-directing nohup to the terminal output instead of nohup.out

nohup is nohup...


if you whish your process dont hup... just trap HUP signal


trap "" HUP

yourprocess



unsupported
u856100
Frequent Advisor

Re: re-directing nohup to the terminal output instead of nohup.out

Thanks all,

the reason is just for running a script file and checking whether it is actually running when I log off. The script file generates lot of repetetive garbage so I wanted to have something visible that was scrolling to stdout as soon as I log in. Just a test though!

cheers

john
chicken or egg first?
Carlos Fernandez Riera
Honored Contributor

Re: re-directing nohup to the terminal output instead of nohup.out

HI man: Why N/A for me?
unsupported
Carlos Fernandez Riera
Honored Contributor

Re: re-directing nohup to the terminal output instead of nohup.out

If you close your session ( i.e /dev/pts/ta) and the sh says "still running jobs" then next man who loogin using /dev/pts/ta will find a lot of garbage so nohup 1>$LOGFILE 2>&1 is mandatory as weel as tail -f.

Rememeber that you cant choose what pseudo-terminal you want to use.

Regards.
unsupported
Jeff Schussele
Honored Contributor

Re: re-directing nohup to the terminal output instead of nohup.out

Harry,

Yea, that is weird.
Works just like a tail if the output is intermittent.
But you & Carlos are correct - tail -f on the output file should be used.

Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!