免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1389 | 回复: 8

菜鳥請教shell scripts [复制链接]

论坛徽章:
0
发表于 2012-03-08 13:56 |显示全部楼层

#!/bin/bash

local='ps -ef|grep LOCAL=YES|grep -v "grep LOCAL=YES"|wc -l'

if [ "$local" = "0" ]; then

        "/u1/ORA/bk.conf"

else
        echo "LOCAL IS RUNNING!"

fi

怎么無法判斷?

论坛徽章:
3
CU十二周年纪念徽章
日期:2013-10-24 15:41:34狮子座
日期:2014-03-27 15:44:382015年辞旧岁徽章
日期:2015-03-03 16:54:15
发表于 2012-03-08 14:04 |显示全部楼层
'换成` 第一行

论坛徽章:
0
发表于 2012-03-08 14:06 |显示全部楼层
回复 2# cu_little_bird


    請問怎么換,卡卡西老師

论坛徽章:
3
CU十二周年纪念徽章
日期:2013-10-24 15:41:34狮子座
日期:2014-03-27 15:44:382015年辞旧岁徽章
日期:2015-03-03 16:54:15
发表于 2012-03-08 14:11 |显示全部楼层
回复 3# LXM995


    local=`ps -ef|grep LOCAL=YES|grep -v "grep LOCAL=YES"|wc -l`

论坛徽章:
0
发表于 2012-03-08 14:18 |显示全部楼层
本帖最后由 LXM995 于 2012-03-08 15:01 编辑

回复 4# cu_little_bird

還是不行:

local='ps -ef|grep LOCAL=YES|grep -v "grep LOCAL=YES"|wc -l'

if [ "$local" = "0" ]; then

        "/u1/ORA/bk.conf"

else
        echo "LOCAL IS RUNNING!"

fi
~
"monitor_rman01.sh" [New] 10L, 160C written           

[lenlvt@oracleAP ~]$ bash monitor_rman01.sh
LOCAL IS RUNNING!
[lenlvt@oracleAP ~]$ ps -ef|grep LOCAL=YES|grep -v "grep LOCAL=YES"|wc -l
1
[lenlvt@oracleAP ~]$ ps -ef|grep LOCAL=YES|grep -v "grep LOCAL=YES"|wc -l
0
[lenlvt@oracleAP ~]$ bash monitor_rman01.sh
LOCAL IS RUNNING!

论坛徽章:
3
CU十二周年纪念徽章
日期:2013-10-24 15:41:34狮子座
日期:2014-03-27 15:44:382015年辞旧岁徽章
日期:2015-03-03 16:54:15
发表于 2012-03-08 14:40 |显示全部楼层
回复 5# LXM995


    ps 那行不是单引号,你还是用的单引号。是反引号。注意区别。
     ` '是有区别的   你换没有?

论坛徽章:
0
发表于 2012-03-08 14:51 |显示全部楼层
本帖最后由 LXM995 于 2012-03-08 14:57 编辑

回复 6# cu_little_bird


    反引號的意義知道了,腳本還不行,在網上找了另外一個試了可以用。謝謝你,卡卡西老師!

#!/bin/bash
if test $( ps -ef|grep LOCAL=YES|grep -v "grep LOCAL=YES"|wc -l ) -eq 0
then
        "/u1/ORA/bk.conf"
else

        echo "RMAN IS RUNNING!"

fi

论坛徽章:
3
CU十二周年纪念徽章
日期:2013-10-24 15:41:34狮子座
日期:2014-03-27 15:44:382015年辞旧岁徽章
日期:2015-03-03 16:54:15
发表于 2012-03-08 15:08 |显示全部楼层
回复 7# LXM995


    在shell 脚本里面 test命令和[] 其实是一样的。但为什么换成反引号也不行 这个你可以把值打出来 debug一下。

论坛徽章:
0
发表于 2012-03-08 15:44 |显示全部楼层
#!/bin/bash
local=`ps -ef | grep LOCAL=YES | grep -v "grep LOCAL=YES" | wc -l`
if [ $local = "0" ] ; then
    "/u1/ORA/bk.conf"
else
   echo "LOCAL IS RUNNING!"
fi
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP