免费注册 查看新帖 |

Chinaunix

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

[数值计算] 请教一个简单的shell 脚本问题,打印出来的和计算出来的不一致 [复制链接]

论坛徽章:
2
操作系统版块每日发帖之星
日期:2015-08-06 06:20:00IT运维版块每日发帖之星
日期:2015-08-15 06:20:00
发表于 2016-10-07 22:02 |显示全部楼层
如题,一个简单的shell 脚本问题,打印出来的和计算出来的不一致

脚本如下
[root@DBServer1 tmp]# cat install_db_test2.sh
chown oracleinstall /etc/oraInst.loc
su - oracle << EOF
/tmp/database/runInstaller -silent -force -noconsole -noconfig \
oracle.install.responseFileVersion=/oracle/install/rspfmt_dbinstall_response_schema_v11_2_0 \
oracle.install.option=INSTALL_DB_SWONLY \
DECLINE_SECURITY_UPDATES=true \
UNIX_GROUP_NAME=oinstall \
INVENTORY_LOCATION=$INVENTORY_LOCATION \
SELECTED_LANGUAGES=en,zh_CN,zh_TW \
ORACLE_HOME=$ORACLE_HOME \
ORACLE_BASE=$ORACLE_BASE \
oracle.install.db.InstallEdition=EE \
oracle.install.db.isCustomInstall=false \
oracle.install.db.DBA_GROUP=dba \
oracle.install.db.OPER_GROUP=oper
sleep 30s
while [ 1 ]
do
    echo `date +'%F %T'` >> /tmp/ps.txt
    ps aux | grep oracle | grep -v bash | grep -v grep | grep -v 'su - oracle' | grep -v 'ps aux' | grep -v sleep >> /tmp/ps.txt

    declare -i procCount=$(ps aux | grep oracle | grep -v bash | grep -v grep | grep -v 'su - oracle' | grep -v 'ps aux' | grep -v sleep | wc -l)
    echo "procCount=\$procCount"
    if [[ \$procCount -eq 0 ]]; then
        echo "install database software finished,exiting..."
        break;
    else
        echo "installing database software,sleep 3s..."
        sleep 3s
    fi

done
exit
EOF
$ORACLE_HOME/root.sh
[root@DBServer1 tmp]#

执行结果
[root@DBServer1 tmp]# ./install_db_test2.sh
正在启动 Oracle Universal Installer...
检查临时空间: 必须大于 120 MB。   实际为 1571 MB    通过
检查交换空间: 必须大于 150 MB。   实际为 1539 MB    通过
准备从以下地址启动 Oracle Universal Installer /tmp/OraInstall2016-10-07_09-02-07PM. 请稍候...procCount=0
install database software finished,exiting...

[root@DBServer1 tmp]#

脚本中有问题部分,在红色字体那里。/tmp/ps.txt的内容如下
2016-10-07 19:21:36
oracle   23983 54.2 17.4 998488 183968 pts/0   Sl+  19:21   0:16 /tmp/OraInstall2016-10-07_07-21-36PM/jdk/jre/bin/java -Doracle.installer.library_loc=/tmp/OraInstall2016-10-07_07-21-36PM/oui/lib/linux64 -Doracle.installer.oui_loc=/tmp/OraInstall2016-10-07_07-21-36PM/oui -Doracle.installer.bootstrap=TRUE -Doracle.installer.startup_location=/tmp/database/install -Doracle.installer.jre_loc=/tmp/OraInstall2016-10-07_07-21-36PM/jdk/jre -Doracle.installer.custom_inventory=/opt/app/oraInventory -Doracle.installer.nlsEnabled="TRUE" -Doracle.installer.prereqConfigLoc=  -Doracle.installer.unixVersion=3.8.13-16.2.1.el6uek.x86_64 -mx150m -cp /tmp/OraInstall2016-10-07_07-21-36PM::/tmp/OraInstall2016-10-07_07-21-36PM/ext/jlib/orai18n-utility.jar:/tmp/OraInstall2016-10-07_07-21-36PM/ext/jlib/emagentSDK.jar:/tmp/OraInstall2016-10-07_07-21-36PM/ext/jlib/cvu.jar:/tmp/OraInstall2016-10-07_07-21-36PM/ext/jlib/orai18n-mapping.jar:/tmp/OraInstall2016-10-07_07-21-36PM/ext/jlib/instcommon.jar:/tmp/OraInstall2016-10-07_07-21-36PM/ext/jlib/remoteinterfaces.jar:/tmp/OraInstall2016-10-07_07-21-36PM/ext/jlib/ssh.jar:/tmp/OraInstall2016-10-07_07-21-36PM/ext/jlib/prov_fixup.jar:/tmp/OraInstall2016-10-07_07-21-36PM/ext/jlib/installcommons_1.0.0b.jar:/tmp/OraInstall2016-10-07_07-21-36PM/ext/jlib/jsch.jar:/tmp/OraInstall2016-10-07_07-21-36PM/ext/jlib/OraPrereqChecks.jar:/tmp/OraInstall2016-10-07_07-21-36PM/ext/jlib/emConfigInstall.jar:/tmp/OraInstall2016-10-07_07-21-36PM/ext/jlib/ojdbc5.jar:/tmp/OraInstall2016-10-07_07-21-36PM/ext/jlib/OraPrereq.jar:/tmp/OraInstall2016-10-07_07-21-36PM/ext/jlib/log4j-core.jar:/tmp/OraInstall2016-10-07_07-21-36PM/ext/jlib/instdb.jar:/tmp/OraInstall2016-10-07_07-21-36PM/oui/jlib/OraInstaller.jar:/tmp/OraInstall2016-10-07_07-21-36PM/oui/jlib/oneclick.jar:/tmp/OraInstall2016-10-07_07-21-36PM/oui/jlib/xmlparserv2.jar:/tmp/OraInstall2016-10-07_07-21-36PM/oui/jlib/share.jar:/tmp/OraInstall2016-10-07_07-21-36PM/oui/jlib/OraInstallerNet.jar:/tmp/OraInstall2016-10-07_07-21-36PM/oui/jlib/emCfg.jar:/tmp/OraInstall2016-10-07_07-21-36PM/oui/jlib/emocmutl.jar:/tmp/OraInstall2016-10-07_07-21-36PM/oui/jlib/OraPrereq.jar:/tmp/OraInstall2016-10-07_07-21-36PM/oui/jlib/jsch.jar:/tmp/OraInstall2016-10-07_07-21-36PM/oui/jlib/ssh.jar:/tmp/OraInstall2016-10-07_07-21-36PM/oui/jlib/remoteinterfaces.jar:/tmp/OraInstall2016-10-07_07-21-36PM/oui/jlib/http_client.jar:/tmp/OraInstall2016-10-07_07-21-36PM/oui/jlib/OraSuiteInstaller.jar:../stage/Components/oracle.swd.opatch/11.2.0.4.0/1/DataFiles/jlib/opatch.jar:../stage/Components/oracle.swd.opatch/11.2.0.4.0/1/DataFiles/jlib/opatchactions.jar:../stage/Components/oracle.swd.opatch/11.2.0.4.0/1/DataFiles/jlib/opatchprereq.jar:../stage/Components/oracle.swd.opatch/11.2.0.4.0/1/DataFiles/jlib/opatchutil.jar:/tmp/OraInstall2016-10-07_07-21-36PM/oui/jlib/OraCheckPoint.jar:/tmp/OraInstall2016-10-07_07-21-36PM/oui/jlib/InstImages.jar:/tmp/OraInstall2016-10-07_07-21-36PM/oui/jlib/InstHelp.jar:/tmp/OraInstall2016-10-07_07-21-36PM/oui/jlib/InstHelp_de.jar:/tmp/OraInstall2016-10-07_07-21-36PM/oui/jlib/InstHelp_es.jar:/tmp/OraInstall2016-10-07_07-21-36PM/oui/jlib/InstHelp_fr.jar:/tmp/OraInstall2016-10-07_07-21-36PM/oui/jlib/InstHelp_it.jar:/tmp/OraInstall2016-10-07_07-21-36PM/oui/jlib/InstHelp_ja.jar:/tmp/OraInstall2016-10-07_07-21-36PM/oui/jlib/InstHelp_ko.jar:/tmp/OraInstall2016-10-07_07-21-36PM/oui/jlib/InstHelp_pt_BR.jar:/tmp/OraInstall2016-10-07_07-21-36PM/oui/jlib/InstHelp_zh_CN.jar:/tmp/OraInstall2016-10-07_07-21-36PM/oui/jlib/InstHelp_zh_TW.jar:/tmp/OraInstall2016-10-07_07-21-36PM/oui/jlib/oracle_ice.jar:/tmp/OraInstall2016-10-07_07-21-36PM/oui/jlib/help4.jar:/tmp/OraInstall2016-10-07_07-21-36PM/oui/jlib/help4-nls.jar:/tmp/OraInstall2016-10-07_07-21-36PM/oui/jlib/ewt3.jar:/tmp/OraInstall2016-10-07_07-21-36PM/oui/jlib/ewt3-swingaccess.jar:/tmp/OraInstall2016-10-07_07-21-36PM/oui/jlib/ewt3-nls.jar:/tmp/OraInstall2016-10-07_07-21-36PM/oui/jlib/swingaccess.jar::/tmp/OraInstall2016-10-07_07-21-36PM/oui/jlib/jewt4.jar:/tmp/OraInstall2016-10-07_07-21-36PM/oui/jlib/jewt4-nls.jar:/tmp/OraInstall2016-10-07_07-21-36PM/oui/jlib/orai18n-collation.jar:/tmp/OraInstall2016-10-07_07-21-3
2016-10-07 21:02:06
oracle   10912 56.2 16.5 998400 174036 pts/0   Sl+  21:02   0:16 /tmp/OraInstall2016-10-07_09-02-07PM/jdk/jre/bin/java -Doracle.installer.library_loc=/tmp/OraInstall2016-10-07_09-02-07PM/oui/lib/linux64 -Doracle.installer.oui_loc=/tmp/OraInstall2016-10-07_09-02-07PM/oui -Doracle.installer.bootstrap=TRUE -Doracle.installer.startup_location=/tmp/database/install -Doracle.installer.jre_loc=/tmp/OraInstall2016-10-07_09-02-07PM/jdk/jre -Doracle.installer.custom_inventory=/opt/app/oraInventory -Doracle.installer.nlsEnabled="TRUE" -Doracle.installer.prereqConfigLoc=  -Doracle.installer.unixVersion=3.8.13-16.2.1.el6uek.x86_64 -mx150m -cp /tmp/OraInstall2016-10-07_09-02-07PM::/tmp/OraInstall2016-10-07_09-02-07PM/ext/jlib/orai18n-utility.jar:/tmp/OraInstall2016-10-07_09-02-07PM/ext/jlib/emagentSDK.jar:/tmp/OraInstall2016-10-07_09-02-07PM/ext/jlib/cvu.jar:/tmp/OraInstall2016-10-07_09-02-07PM/ext/jlib/orai18n-mapping.jar:/tmp/OraInstall2016-10-07_09-02-07PM/ext/jlib/instcommon.jar:/tmp/OraInstall2016-10-07_09-02-07PM/ext/jlib/remoteinterfaces.jar:/tmp/OraInstall2016-10-07_09-02-07PM/ext/jlib/ssh.jar:/tmp/OraInstall2016-10-07_09-02-07PM/ext/jlib/prov_fixup.jar:/tmp/OraInstall2016-10-07_09-02-07PM/ext/jlib/installcommons_1.0.0b.jar:/tmp/OraInstall2016-10-07_09-02-07PM/ext/jlib/jsch.jar:/tmp/OraInstall2016-10-07_09-02-07PM/ext/jlib/OraPrereqChecks.jar:/tmp/OraInstall2016-10-07_09-02-07PM/ext/jlib/emConfigInstall.jar:/tmp/OraInstall2016-10-07_09-02-07PM/ext/jlib/ojdbc5.jar:/tmp/OraInstall2016-10-07_09-02-07PM/ext/jlib/OraPrereq.jar:/tmp/OraInstall2016-10-07_09-02-07PM/ext/jlib/log4j-core.jar:/tmp/OraInstall2016-10-07_09-02-07PM/ext/jlib/instdb.jar:/tmp/OraInstall2016-10-07_09-02-07PM/oui/jlib/OraInstaller.jar:/tmp/OraInstall2016-10-07_09-02-07PM/oui/jlib/oneclick.jar:/tmp/OraInstall2016-10-07_09-02-07PM/oui/jlib/xmlparserv2.jar:/tmp/OraInstall2016-10-07_09-02-07PM/oui/jlib/share.jar:/tmp/OraInstall2016-10-07_09-02-07PM/oui/jlib/OraInstallerNet.jar:/tmp/OraInstall2016-10-07_09-02-07PM/oui/jlib/emCfg.jar:/tmp/OraInstall2016-10-07_09-02-07PM/oui/jlib/emocmutl.jar:/tmp/OraInstall2016-10-07_09-02-07PM/oui/jlib/OraPrereq.jar:/tmp/OraInstall2016-10-07_09-02-07PM/oui/jlib/jsch.jar:/tmp/OraInstall2016-10-07_09-02-07PM/oui/jlib/ssh.jar:/tmp/OraInstall2016-10-07_09-02-07PM/oui/jlib/remoteinterfaces.jar:/tmp/OraInstall2016-10-07_09-02-07PM/oui/jlib/http_client.jar:/tmp/OraInstall2016-10-07_09-02-07PM/oui/jlib/OraSuiteInstaller.jar:../stage/Components/oracle.swd.opatch/11.2.0.4.0/1/DataFiles/jlib/opatch.jar:../stage/Components/oracle.swd.opatch/11.2.0.4.0/1/DataFiles/jlib/opatchactions.jar:../stage/Components/oracle.swd.opatch/11.2.0.4.0/1/DataFiles/jlib/opatchprereq.jar:../stage/Components/oracle.swd.opatch/11.2.0.4.0/1/DataFiles/jlib/opatchutil.jar:/tmp/OraInstall2016-10-07_09-02-07PM/oui/jlib/OraCheckPoint.jar:/tmp/OraInstall2016-10-07_09-02-07PM/oui/jlib/InstImages.jar:/tmp/OraInstall2016-10-07_09-02-07PM/oui/jlib/InstHelp.jar:/tmp/OraInstall2016-10-07_09-02-07PM/oui/jlib/InstHelp_de.jar:/tmp/OraInstall2016-10-07_09-02-07PM/oui/jlib/InstHelp_es.jar:/tmp/OraInstall2016-10-07_09-02-07PM/oui/jlib/InstHelp_fr.jar:/tmp/OraInstall2016-10-07_09-02-07PM/oui/jlib/InstHelp_it.jar:/tmp/OraInstall2016-10-07_09-02-07PM/oui/jlib/InstHelp_ja.jar:/tmp/OraInstall2016-10-07_09-02-07PM/oui/jlib/InstHelp_ko.jar:/tmp/OraInstall2016-10-07_09-02-07PM/oui/jlib/InstHelp_pt_BR.jar:/tmp/OraInstall2016-10-07_09-02-07PM/oui/jlib/InstHelp_zh_CN.jar:/tmp/OraInstall2016-10-07_09-02-07PM/oui/jlib/InstHelp_zh_TW.jar:/tmp/OraInstall2016-10-07_09-02-07PM/oui/jlib/oracle_ice.jar:/tmp/OraInstall2016-10-07_09-02-07PM/oui/jlib/help4.jar:/tmp/OraInstall2016-10-07_09-02-07PM/oui/jlib/help4-nls.jar:/tmp/OraInstall2016-10-07_09-02-07PM/oui/jlib/ewt3.jar:/tmp/OraInstall2016-10-07_09-02-07PM/oui/jlib/ewt3-swingaccess.jar:/tmp/OraInstall2016-10-07_09-02-07PM/oui/jlib/ewt3-nls.jar:/tmp/OraInstall2016-10-07_09-02-07PM/oui/jlib/swingaccess.jar::/tmp/OraInstall2016-10-07_09-02-07PM/oui/jlib/jewt4.jar:/tmp/OraInstall2016-10-07_09-02-07PM/oui/jlib/jewt4-nls.jar:/tmp/OraInstall2016-10-07_09-02-07PM/oui/jlib/orai18n-collation.jar:/tmp/OraInstall2016-10-07_09-02-0

说明执行
ps aux | grep oracle | grep -v bash | grep -v grep | grep -v 'su - oracle' | grep -v 'ps aux' | grep -v sleep
是没有问题的,是有内容的,按道理

declare -i procCount=$(ps aux | grep oracle | grep -v bash | grep -v grep | grep -v 'su - oracle' | grep -v 'ps aux' | grep -v sleep | wc -l)
是有数据的,但

echo "procCount=\$procCount"
的计算结果,$procCount却等于0

问题出在哪里呢,还请大家指教。

初学,谢谢。



论坛徽章:
1
15-16赛季CBA联赛之同曦
日期:2017-03-19 09:57:50
发表于 2016-10-08 11:47 |显示全部楼层
手动执行 ps aux | grep oracle | grep -v bash | grep -v grep | grep -v 'su - oracle' | grep -v 'ps aux' | grep -v sleep | wc -l 这句话看看
另外echo "procCount=\$procCount" 和 if [[ \$procCount -eq 0 ]] 为啥要使用跳脱符号呀,表示不解
如果还不行,使用sh -x执行脚本看看
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

SACC2019中国系统架构师大会

【数字转型 架构演进】SACC2019中国系统架构师大会,7折限时优惠重磅来袭!
2019年10月31日~11月2日第11届中国系统架构师大会(SACC2019)将在北京隆重召开。四大主线并行的演讲模式,1个主会场、20个技术专场、超千人参与的会议规模,100+来自互联网、金融、制造业、电商等领域的嘉宾阵容,将为广大参会者提供一场最具价值的技术交流盛会。

限时七折期:2019年8月31日前


----------------------------------------

大会官网>>
  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP