系统环境:

# uname -r
2.6.-.el6.x86_64
# cat /etc/redhat-release
CentOS release 6.5 (Final)

对服务器状态监控的一段脚本中使用了查询进程信息的几句代码:

server="srs"
care_pid=`pgrep -f $server`
#echo "$server pid =" $care_pid
care_ps=`ps aux | grep $server | grep -v "grep"`
#echo $care_ps

直接命令行执行脚本,输入信息如下:

srs pid =
root 1.4 0.0 ? S Jun22 : ./objs/srs -c ./conf/srs.conf

设置定时器crontab 自动执行脚本,输出信息如下::

srs pid =
root 1.4 0.0 ? S Jun22 : ./objs/srs -c ./conf/srs.conf
root 1.0 0.0 ? Ss : : /bin/sh -c /usr/local/srs/video_server_monitor.sh >> /usr/local/srs/monitor.log
root 0.0 0.0 ? S : : /bin/sh -c /usr/local/srs/video_server_monitor.sh >> /usr/local/srs/monitor.log
root 0.0 0.0 ? S : : /bin/sh -c /usr/local/srs/video_server_monitor.sh >> /usr/local/srs/monitor.log

目前尚不知道什么缘故,暂时更改脚本解决了问题。具体的原因还需要下次查询。
换个写法定时执行得到正确结果,更改如下:

server="srs"
care_pid=`pgrep -n $server`
#echo "$server pid =" $care_pid
care_ps=`ps p $care_pid u`
#echo $care_ps

linux脚本遇到的一点问题的更多相关文章

  1. linux 脚本编写基础(一)

    1. Linux 脚本编写基础 1.1 语法基本介绍 1.1.1 开头 程序必须以下面的行开始(必须方在文件的第一行): #!/bin/sh 符号#!用来告诉系统它后面的参数是用来执行该文件的程序.在 ...

  2. Linux脚本入门(1)

    1. Linux 脚本编写基础1.1 语法基本介绍1.1.1 开头程序必须以下面的行开始(必须方在文件的第一行): #!/bin/sh 符号#!用来告诉系统它后面的参数是用来执行该文件的程序.在这个例 ...

  3. Linux 脚本编写基础

    txt去重    http://man.linuxde.net/sort Linux 脚本编写基础 http://www.cnblogs.com/linn/archive/2007/03/05/664 ...

  4. 【转】【整理】将Linux脚本中的正常输出,警告,错误等信息输出到文件中

     本文来自:http://blog.csdn.net/woshinia/article/details/18040063   很早以前  编译的时候 就在用 2>&1,但是一直没有生成一 ...

  5. linux脚本编程(shell)浅介 (转载)

    linux脚本(shell)编程 啊,昨天上网看到一篇讲 linux/unix shell 的文章,想想自己最后写这东西也是一年前的事了,想想都快忘光了. 还是整理一下,做一次回顾,以后说不定还用得上 ...

  6. linux脚本编程技术

    linux脚本编程技术 一.什么是脚本 脚本是一个包含一系列命令序列的可执行(777)文本文件.当运行这个脚本文件时,文件中包含的命令序列将得到自动执行. 二.脚本编程 #!/bin/sh 首行固定格 ...

  7. Linux脚本执行过程重定向

    Linux脚本执行过程重定向 一.bash调试脚本,并将执行过程重定向到指定文件 bash –x  shell.sh 2>&1 | tee shell.log

  8. linux脚本初体验

    前言 第一次写linux脚本,有点紧张. 1. 写一个寻找特定用户的脚本文件? #! /bin/sh who | grep $1 其中脚本第一行用来告诉kernel去使用/bin/sh来解释这个脚本: ...

  9. Linux脚本shell字符串处理

    Linux脚本shell字符串处理,基本都有了,看着搜吧 TLDP教堂 shell中if条件字符串.数字比对,[[ ]]和[ ]区别 Linux 之 shell 比较运算符 Linux Shell编程 ...

随机推荐

  1. 四 Mixer

    Mixer在应用程序和基础架构后端之间提供通过中介层.它的设计将策略决策移出应用层,用运维人员能够控制的配置取而代之. Mixer的设计目的是改变层次之间的边界,以此降低总体复杂性.从服务代码中剔除策 ...

  2. 解决webpack因新版本打包失败问题--ERROR in multi ./src/main.js ./dist/bundle.js

    最近在学习webpack打包过程中遇到的一个问题向大家分享下! 创建了一个webpacksty的目录,目录下放着dist,src子目录,然后通过node环境下,npm init -y 初始化项目出现p ...

  3. The Commercial Open-Source Monitoring Landscape

    As enterprises have adopted open-source monitoring tools, there is growing market demand by enterpri ...

  4. Python No module named pkg_resources

    好记性不如烂笔头. I encountered the same ImportError today while trying to use pip. Somehow the setuptools p ...

  5. 将Windows下磁盘出现黑色为分配区域变成绿色区域

    在windows下不知什么原因, 有一块磁盘空间F盘就变成了黑色为分配区域. 黑色区域无法用来安装双系统, 网上查阅资料后, 找到了如何将他重新变回绿色区域的2个方法(方法二是自己无意操作成功的). ...

  6. Delphi IOS (二)

    1.Mac 中 simulator模拟器Home快捷键:command(Win键盘,Ctrl与Alt之间的键)+shift+h来代替,也可以点击菜单>HardWare>Home 2.iPh ...

  7. DAY11-MYSQL数据备份、pymysql模块

    一 IDE工具介绍 生产环境还是推荐使用mysql命令行,但为了方便我们测试,可以使用IDE工具 下载链接:https://pan.baidu.com/s/1bpo5mqj 掌握: #1. 测试+链接 ...

  8. intellij idea 设置Live Template快速生成自定义代码块

    一.设置 类似于宏,话不多少,上步骤 File----->Setting 选择Live Template 新建触发规则 新建触发key 输入模版text 选择在哪个环境触发 选java 如果是其 ...

  9. 查看hdfs各目录分别占用多少空间

    之前在网上搜索到的全部单位好像都是byte的,看起来很麻烦,然后自己看了下 hadoop fs -help [hadoop@slave3 java]$ hadoop fs -help Usage: h ...

  10. filter(函数,可以迭代的对象)

    #!/usr/bin/env python #filter(函数,可以迭代的对象) def f1(x): if x > 22: return True else: return False re ...