Networking

Unix and Linux network configuration. Multiple network interfaces. Bridged NICs. High-availability network configurations.

Applications

Reviews of latest Unix and Linux software. Helpful tips for application support admins. Automating application support.

Data

Disk partitioning, filesystems, directories, and files. Volume management, logical volumes, HA filesystems. Backups and disaster recovery.

Monitoring

Distributed server monitoring. Server performance and capacity planning. Monitoring applications, network status and user activity.

Commands & Shells

Cool Unix shell commands and options. Command-line tools and application. Things every Unix sysadmin needs to know.

Home » Commands & Shells

Nohup Without Nohup.out

Submitted by on July 13, 2016 – 12:55 am

This is a common question: how can I run nohup without creating the annoying nohup.out ? And the common answer is: you can’t. But this is not exactly true.

Some people have a dreadful habit of starting their applications using nohup with debug sent to stdout. The nohup.out will never be “rotated”, like a log file. It will keep growing until it consumes all available space. Even if you delete it or empty it out, the filesystem space will not be released, until the process wring to the file is terminated.

And so without further ado, lo and behold: running nohup without creating nohup.out:

nohup your_command </dev/null >/dev/null 2>&1 &

And here’s a little example. First, I rsync /etc to /etc_mirror using nohup to keep it running in the background:
[root@ncc1701 tmp]# mkdir /etc_mirror
[root@ncc1701 tmp]# nohup rsync -av /etc/ /etc_mirror/ &
[2] 56919
[root@ncc1701 tmp]# nohup: ignoring input and appending output to `nohup.out'
[root@ncc1701 tmp]#
[root@ncc1701 tmp]#
[2]-  Done                    nohup rsync -av /etc/ /etc_mirror/
[root@ncc1701 tmp]# du -sh /etc /etc_mirror
118M    /etc
118M    /etc_mirror
[root@ncc1701 tmp]# wc -l nohup.out
3565 nohup.out
[root@ncc1701 tmp]# rm nohup.out
[root@ncc1701 tmp]# rm -r /etc_mirror

Here I repeat the same process with the </dev/null addition:
[root@ncc1701 tmp]# mkdir /etc_mirror
[root@ncc1701 tmp]# nohup rsync -av /etc/ /etc_mirror/ </dev/null >/dev/null 2>&1 &
[2] 61837
[root@ncc1701 tmp]#
[root@ncc1701 tmp]#
[2]-  Done                    nohup rsync -av /etc/ /etc_mirror/ < /dev/null > /dev/null 2>&1
[root@ncc1701 tmp]# du -sh /etc /etc_mirror
118M    /etc
118M    /etc_mirror
[root@ncc1701 tmp]# wc -l nohup.out
wc: nohup.out: No such file or directory
[root@ncc1701 tmp]# rm -r /etc_mirror

Hooray.

Print Friendly, PDF & Email

Leave a Reply