• 时间写入文件名 nohup 原理 Command In Background your shell may have its own version of nohup


    echo 123 > `date +%Y-%m-%d-%H.tmp`

    echo 123 > /home/`date +%Y-%m-%d-%H.tmp`


    nohup --help

    [root@Today data]# nohup --help
    Usage: nohup COMMAND [ARG]...
    or: nohup OPTION
    Run COMMAND, ignoring hangup signals.

    --help display this help and exit
    --version output version information and exit

    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'.

    NOTE: your shell may have its own version of nohup, which usually supersedes
    the version described here. Please refer to your shell's documentation
    for details about the options it supports.

    GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
    For complete documentation, run: info coreutils 'nohup invocation'
    [root@Today data]# nohup --help


    nohup python /root/path/Biz.py start >> /data/log/Biz/`date +%Y-%m-%d-%H.nohup.out`

    nohup: ignoring input and redirecting stderr to stdout

    始终在内存?

     批量写入?

    nohup python /home/ctGO/goEchopublic/t.py  > /var/`date +%Y-%m-%d-%H.nohup.out`

     Unix Nohup: Run a Command or Shell-Script Even after You Logout https://linux.101hacks.com/unix/nohup-command/

    Unix Nohup: Run a Command or Shell-Script Even after You Logout

    When you execute a Unix job in the background ( using &, bg command), and logout from the session, your process will get killed. You can avoid this using several methods — executing the job with nohup, or making it as batch job using at, batch or cron command.

    This quick tip is for beginners. If you’ve been using nohup for a while, leave us a comment and tell us under what situations you use nohup.

    In this quick tip, let us review how to make your process running even after you logout, using nohup.

    Nohup stands for no hang up, which can be executed as shown below.

    nohup syntax:

    # nohup command-with-options &
    

    Nohup is very helpful when you have to execute a shell-script or command that take a long time to finish. In that case, you don’t want to be connected to the shell and waiting for the command to complete. Instead, execute it with nohup, exit the shell and continue with your other work.

    Explanation about nohup.out file

    By default, the standard output will be redirected to nohup.out file in the current directory. And the standard error will be redirected to stdout, thus it will also go to nohup.out. So, your nohup.out will contain both standard output and error messages from the script that you’ve executed using nohup command.

    Instead of using nohup.out, you can also redirect the output to a file using the normal shell redirections.

    Example: Printing lines to both standard output & standard error

    while(true)
    do
    echo "standard output"
    echo "standard error" 1>&2 
    sleep 1;
    done
    

    Execute the script without redirection

    $ nohup sh custom-script.sh &
    [1] 12034
    $ nohup: ignoring input and appending output to `nohup.out'
    
    $ tail -f nohup.out
    standard output
    standard error
    standard output
    standard error
    ..
    

    Execute the script with redirection

    $ nohup sh custom-script.sh > custom-out.log &
    [1] 11069
    $ nohup: ignoring input and redirecting stderr to stdout
    
    $ tail -f custom-out.log
    standard output
    standard error
    standard output
    standard error
    ..
    

    If you log-out of the shell and login again, you’ll still see the custom-script.sh running in the background.

    $ ps aux | grep sathiya 
    sathiya  12034  0.0  0.1   4912  1080 pts/2    S    14:10   0:00 sh custom-script.sh




    Linux: Start Command In Background - nixCraft https://www.cyberciti.biz/faq/linux-command-line-run-in-background/

    Linux: Start Command In Background

    last updated February 13, 2014 in Categories
    Iam a new Linux command line user. How do I start or run command in the background so that I can access command prompt immediately?

    A command that has been scheduled nonsequentially is called background process. You can not see the background processes on screen. For example, Apache httpd server runs in background to serve web pages. You can put your shell script or any command in background.

    Syntax

    You can put a task (such as command or script) in a background by appending a & at the end of the command line. The & operator puts command in the background and free up your terminal. The command which runs in background is called a job. You can type other command while background command is running. The syntax is:

    command &
    script-name &
    /path/to/command arg1 arg2 &
    command-1 | command-2 arg1 &
    command-1 | command-2 -arg1 -arg2 >/path/to/output &

    Examples

    Put the ls command in the background, enter:
    $ ls *.py > output.txt &
    Put the following find command in a background by putting a ‘&’ at the end of the command line:

    find . -iname "*.mp3" > myplaylist.txt &

    Sample outputs:

    Fig.01: Linux background job in action (click to enlarge)Fig.01: Linux background job in action (click to enlarge)

    How do I see jobs running in the background?

    Type the following command:
    jobs
    Sample outputs:

    [1]-  Running                 find / -iname "*.c" 2> /dev/null > /tmp/output.txt &
    [2]+  Running                 grep -R "hostNamed" / 2> /dev/null > /tmp/grep.txt &

    Where,

    • [1] and [2] are job IDS.

    To see process IDs for JOB IDs in addition to the normal information pass the -loption:
    jobs -l
    Sample outputs:

    [1]-  7307 Running                 find / -iname "*.c" 2> /dev/null > /tmp/output.txt &
    [2]+  7324 Running                 grep -R "hostNamed" / 2> /dev/null > /tmp/grep.txt &

    To see process IDs only, enter:
    jobs -p
    Sample outputs:

    7307
    7324

    How do I kill the jobs running in the background?

    Use the kill command to kill process either gracefully or forcefully. The syntax is:

    kill PID
    kill -15 PID
    kill -9 PID
    killall process-Name-Here
    killall -15 process-Name-Here
    killall -9 process-Name-Here
    

    See how to use killall command under Linux operating system for more information.

    How do I bring process running in the background to the foreground?

    The syntax is:
    %JOB-ID
    OR
    fg JOB-ID
    First, list the current jobs with jobs command, enter:
    jobs -l
    Sample outputs:

    [1]-  7307 Running                 find / -iname "*.c" 2> /dev/null > /tmp/output.txt &
    [2]+  7324 Running                 grep -R "hostNamed" / 2> /dev/null > /tmp/grep.txt &

    To bring the job id #2 to the foreground, enter:
    %2
    OR use fg command:
    fg 2
    Sample outputs:

    grep -R "hostNamed" / 2> /dev/null > /tmp/grep.txt

    To send back this job in the background hit CTRL-Z i.e. while holding the CTRL key, press z key. This will suspend the current foreground job. Type the following command to send back the job in the background:
    %2 &
    OR use bg command:
    bg
    The grep command job is now running in the background.

    Summary of all useful commands

    DescriptionCommand
    To see which jobs are still running jobs jobs
    jobs -l
    ps aux
    To put a command / script to the background command &
    /path/to/command &
    /path/to/script arg1 &
    To bring a background job to the foreground fg n
    %n
    To send a job to the background without canceling it bg n
    %n &

    Note: n == Job id (use jobs command to see job id)..

    See also:

    nohup(1) - Linux man page https://linux.die.net/man/1/nohup


    输出哪种信息:py-print、ctrl终止 :需要实际测试 环境


    Name

    nohup - run a command immune to hangups, with output to a non-tty

    Synopsis

    nohup COMMAND [ARG]...
    nohup OPTION

    Description

     

    Run COMMAND, ignoring hangup signals.

    --help
    display this help and exit
    --version
    output version information and exit

    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'.

    NOTE: your shell may have its own version of nohup, which usually supersedes the version described here. Please refer to your shell's documentation for details about the options it supports.

    cat t.py
    while 2>1:
    print(2)

    out中写入了print信息
    nohup python /data/log/directAd/t.py >> /data/log/directAd/`date +%Y-%m-%d-%H.nohupT.out
    传入参数,虽然脚本正常执行,但是out中没有写入print信息
    nohup python /root/tools/trunk/bin/DirectServer.py start >> /data/log/directAd/`date +%Y-%m-%d-%H.nohup.out`







  • 相关阅读:
    flex做页面。用来做视频的后台服务器是fms
    indows下PHP通过ffmpeg给上传的视频截图详解
    PHP上传视频
    解决IE6浏览器下position:fixed固定定位问题
    PHP获取 当前页面名称、主机名、URL完整地址、URL参数、获取IP
    产品经理需要输出哪些文档?
    python三种回收机制
    数据库管理用户权限
    数据库6范式,一般来说,数据库满足前三范式即可
    递归迭代
  • 原文地址:https://www.cnblogs.com/rsapaper/p/9634102.html
Copyright © 2020-2023  润新知