zoukankan      html  css  js  c++  java
  • nohup 使用


    2020/7/29 10:11:07

    arguments    n.    争论; 争吵; 争辩; 辩论; 论据; 理由; 论点;


    语法

    nohup command arguments
    或者
    nohup options

    nohup --help   查看帮助

    nohup --version   查看版本

    使用nohup

    nohup commnd  当程序运行起来,其log会被输出记录在nohup.out文件中,这个文件会被存储在家目录或者当前目录


    nohup --version
    [root@samba nohup]# nohup --version
    nohup (GNU coreutils) 8.22
    Copyright (C) 2013 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.

    Written by Jim Meyering.


    [root@samba nohup]# nohup ping -c 10 172.20.90.114
    nohup: ignoring input and appending output to ‘nohup.out’
    [root@samba nohup]# cat nohup.out 
    PING 172.20.90.114 (172.20.90.114) 56(84) bytes of data.
    64 bytes from 172.20.90.114: icmp_seq=1 ttl=126 time=0.194 ms
    64 bytes from 172.20.90.114: icmp_seq=2 ttl=126 time=0.220 ms
    64 bytes from 172.20.90.114: icmp_seq=3 ttl=126 time=0.225 ms
    64 bytes from 172.20.90.114: icmp_seq=4 ttl=126 time=0.219 ms
    64 bytes from 172.20.90.114: icmp_seq=5 ttl=126 time=0.225 ms
    64 bytes from 172.20.90.114: icmp_seq=6 ttl=126 time=0.221 ms
    64 bytes from 172.20.90.114: icmp_seq=7 ttl=126 time=0.221 ms
    64 bytes from 172.20.90.114: icmp_seq=8 ttl=126 time=0.238 ms
    64 bytes from 172.20.90.114: icmp_seq=9 ttl=126 time=0.220 ms
    64 bytes from 172.20.90.114: icmp_seq=10 ttl=126 time=0.224 ms

    --- 172.20.90.114 ping statistics ---
    10 packets transmitted, 10 received, 0% packet loss, time 9000ms
    rtt min/avg/max/mdev = 0.194/0.220/0.238/0.020 ms

    重定向程序输出

    [root@samba nohup]# nohup ping -c 10 172.20.90.114 >./result1525.txt
    nohup: ignoring input and redirecting stderr to stdout
    [root@samba nohup]# ls
    nohup.out  result1525.txt
    [root@samba nohup]# cat result1525.txt 
    PING 172.20.90.114 (172.20.90.114) 56(84) bytes of data.
    64 bytes from 172.20.90.114: icmp_seq=1 ttl=126 time=0.178 ms
    64 bytes from 172.20.90.114: icmp_seq=2 ttl=126 time=0.232 ms
    64 bytes from 172.20.90.114: icmp_seq=3 ttl=126 time=0.228 ms
    64 bytes from 172.20.90.114: icmp_seq=4 ttl=126 time=0.228 ms
    64 bytes from 172.20.90.114: icmp_seq=5 ttl=126 time=0.220 ms
    64 bytes from 172.20.90.114: icmp_seq=6 ttl=126 time=0.219 ms
    64 bytes from 172.20.90.114: icmp_seq=7 ttl=126 time=0.226 ms
    64 bytes from 172.20.90.114: icmp_seq=8 ttl=126 time=0.228 ms
    64 bytes from 172.20.90.114: icmp_seq=9 ttl=126 time=0.224 ms
    64 bytes from 172.20.90.114: icmp_seq=10 ttl=126 time=0.225 ms

    --- 172.20.90.114 ping statistics ---
    10 packets transmitted, 10 received, 0% packet loss, time 8999ms
    rtt min/avg/max/mdev = 0.178/0.220/0.232/0.023 ms

    让程序在后台运行

    & 表示让程序在后台运行
     nohup ping -c 100 172.20.90.114 > ./result1529.txt &

    让程序跟几个命令一起执行
     nohup ping -c 10 172.20.59.163 > ./result1534.txt && touch a.txt &


    去除提示     2>&1

    默认情况下会有一个提示  nohup: ignoring input and redirecting stderr to stdout
    可以使用2>&1 去除
    [root@samba nohup]# nohup ping -c 9 172.20.3.1 > ./result3-1.txt 2>&1 &
    [1] 4903

    前提是命令要有输出文件 此处指的就是  ./result.txt


    综上所述,目前应该是这种语法采用的较多一些


  • 相关阅读:
    敏捷开发来源
    android学习笔记(3)Button控件的学习
    JavaScript你所不知道的困惑(2)
    JavaScript你所不知道的困惑(1)
    Android菜鸟的成长笔记(27)——SurfaceView的使用
    小强的HTML5移动开发之路(53)——jQueryMobile页面间参数传递
    小强的HTML5移动开发之路(52)——jquerymobile中的触控交互
    小强的HTML5移动开发之路(51)——jquerymobile中改善页面访问速度
    小强的HTML5移动开发之路(50)——jquerymobile页面初始化过程
    Thinking in UML 学习笔记(四)——UML核心视图之活动图
  • 原文地址:https://www.cnblogs.com/nodchen/p/13397860.html
Copyright © 2011-2022 走看看