脚本编程示例

来源:互联网 发布:始祖鸟淘宝谁家靠谱 编辑:程序博客网 时间:2024/06/05 09:36

#!/bin/shps -C NewXScada > /tmp/stop_tmpif [ "$?" -ne 0 ]thenecho "NewXScada not running!"rm -f /tmp/stop_tmpexit -1firm -f /tmp/stop_tmpkillall NewXScadaif [ "$?" -eq 0 ]thenecho "NewXScada stoped sucess!"elseecho "NewXScada stoped fail!"fiexit 0
开始程序的一个脚本示例 linux下

#!/bin/bash## Startup script for the pmagent## chkconfig: 345 99 02# description: Run the Scada INITLOG_ARGS=""prog="Scada"progname="Scada"RETVAL=0# Edit the following to indicate the 'bin' directory for your installationMDIR=/home/zchx/ScadaExif [ ! -d "$MDIR" ]thenecho "Invalid directory $MDIR"exit 1fistart(){cp -f /home/zchx/ScadaEx/Scada.log /var/log/Scada.logecho "Starting $progname"cd $MDIRnohup sh start.sh >/var/log/Scada.log 2>&1 &RETVAL=$?echo[ $RETVAL = 0 ] && touch /var/lock/Scada }stop(){echo "Stopping $progname"cd $MDIRsh stop.sh >>/var/log/Scada.log 2>&1}case "$1" instart)start;;stop)stop;;*)echo "Usage: $prog {start|stop}"exit 1;;esacexit $RETVAL
开机启动示例
#!/bin/shps -C NewXScada > /tmp/start_tmpif [ "$?" -eq 0 ]thenecho "NewXScada aready started!"rm -f /tmp/start_tmpexit -1elseecho "NewXScada hasn't run!"firm -f /tmp/start_tmp./NewXScadaif [ "$?" -eq 0 ]thenecho "NewXScada start success!"elseecho "NewXScada start fail!"fiexit 0
结束程序示例 

弹出窗口新执行程序的一个示例


#!/bin/shPROGRAM="Create CenterController Init"BASHNAME=InitCenterController.shSHPATH=$0BINPATH=./exec/BINNAME=./CenterControllerLDPATH=${PWD}${SHPATH/$BASHNAME/"/lib/"}echo "$PROGRAM"################################################### Start target##################################################echo "Entering dir $BINPATH"cd ${SHPATH/$BASHNAME/"./"}cd $BINPATHecho ${PWD}gnome-terminal -x bash -c "export LD_LIBRARY_PATH=$LDPATH;$BINNAME;read"if [ "$?" -eq 0 ]thenecho "$BINNAME start success!"echo "$BINNAME executed at another terminal "exit 0elseecho "$BINNAME start fail!"exit -1fi

条件判断进程控制脚本,简单修改集成至自己工程:


#!/bin/sh/if [ "$1" = "start" ]; thenps -e | grep OceanStarif [ "$?" -eq 0 ]; thenecho "already started type:\"ps -e | grep OceanStar\" to check "exit 1elseecho "starting"cd /opt/OceanStarMediaServerHumen/ ;nohup ./OceanStarMediaServer&ps -e | grep OceanStarif [ "$?" -eq 0 ]; thenecho "started "elseecho "start error type:\"ps -e | grep OceanStar\" to check"fifielif [ "$1" = "stop" ]; thenps -e | grep OceanStarif [ "$?" -eq 0 ]; thenecho "stoping"killall OceanStarMediaServerps -e | grep OceanStarif [ "$?" -eq 0 ]; thenecho "stop error type:\"ps -e | grep OceanStar\" to check "elseecho "stoped "fielseecho "no process running type:\"ps -e | grep OceanStar\" to check "exit 1fielif [ "$1" = "restart" ]; thenecho "restarting"killall OceanStarMediaServercd /opt/OceanStarMediaServerHumen/ ;nohup ./OceanStarMediaServer&ps -e | grep OceanStarif [ "$?" -eq 0 ]; thenecho "restart OK! type:\"ps -e | grep OceanStar\" to check "exit 1elseecho "restarting Error type:\"ps -e | grep OceanStar\" to check"fielseecho "Invalid CMD"fiexit 0





















原创粉丝点击