How do I use the nohup command without getting nohup.out?

前端 未结 8 2155
情书的邮戳
情书的邮戳 2020-11-27 08:34

I have a problem with the nohup command.

When I run my job, I have a lot of data. The output nohup.out becomes too large and my process slows down. How can I run thi

相关标签:
8条回答
  • 2020-11-27 09:13
    sudo bash -c "nohup /opt/viptel/viptel_bin/log.sh $* &> /dev/null"  &
    

    Redirecting the output of sudo causes sudo to reask for the password, thus an awkward mechanism is needed to do this variant.

    0 讨论(0)
  • 2020-11-27 09:14
    nohup some_command > /dev/null 2>&1&
    

    That's all you need to do!

    0 讨论(0)
  • 2020-11-27 09:16

    If you have a BASH shell on your mac/linux in-front of you, you try out the below steps to understand the redirection practically :

    Create a 2 line script called zz.sh

    #!/bin/bash
    echo "Hello. This is a proper command"
    junk_errorcommand
    
    • The echo command's output goes into STDOUT filestream (file descriptor 1).
    • The error command's output goes into STDERR filestream (file descriptor 2)

    Currently, simply executing the script sends both STDOUT and STDERR to the screen.

    ./zz.sh
    

    Now start with the standard redirection :

    zz.sh > zfile.txt
    

    In the above, "echo" (STDOUT) goes into the zfile.txt. Whereas "error" (STDERR) is displayed on the screen.

    The above is the same as :

    zz.sh 1> zfile.txt
    

    Now you can try the opposite, and redirect "error" STDERR into the file. The STDOUT from "echo" command goes to the screen.

    zz.sh 2> zfile.txt
    

    Combining the above two, you get:

    zz.sh 1> zfile.txt 2>&1
    

    Explanation:

    • FIRST, send STDOUT 1 to zfile.txt
    • THEN, send STDERR 2 to STDOUT 1 itself (by using &1 pointer).
    • Therefore, both 1 and 2 goes into the same file (zfile.txt)

    Eventually, you can pack the whole thing inside nohup command & to run it in the background:

    nohup zz.sh 1> zfile.txt 2>&1&
    
    0 讨论(0)
  • 2020-11-27 09:22

    Following command will let you run something in the background without getting nohup.out:

    nohup command |tee &
    

    In this way, you will be able to get console output while running script on the remote server:

    0 讨论(0)
  • 2020-11-27 09:27

    You can run the below command.

    nohup <your command> & >  <outputfile> 2>&1 &
    

    e.g. I have a nohup command inside script

    ./Runjob.sh > sparkConcuurent.out 2>&1
    
    0 讨论(0)
  • 2020-11-27 09:28

    You might want to use the detach program. You use it like nohup but it doesn't produce an output log unless you tell it to. Here is the man page:

    NAME
           detach - run a command after detaching from the terminal
    
    SYNOPSIS
           detach [options] [--] command [args]
    
           Forks  a  new process, detaches is from the terminal, and executes com‐
           mand with the specified arguments.
    
    OPTIONS
           detach recognizes a couple of options, which are discussed below.   The
           special  option -- is used to signal that the rest of the arguments are
           the command and args to be passed to it.
    
           -e file
                  Connect file to the standard error of the command.
    
           -f     Run in the foreground (do not fork).
    
           -i file
                  Connect file to the standard input of the command.
    
           -o file
                  Connect file to the standard output of the command.
    
           -p file
                  Write the pid of the detached process to file.
    
    EXAMPLE
           detach xterm
    
           Start an xterm that will not be closed when the current shell exits.
    
    AUTHOR
           detach was written by Robbert Haarman.  See  http://inglorion.net/  for
           contact information.
    

    Note I have no affiliation with the author of the program. I'm only a satisfied user of the program.

    0 讨论(0)
提交回复
热议问题