免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12
最近访问板块 发新帖
楼主: george16
打印 上一主题 下一主题

有数十个脚本,想他们按照顺序执行下去 [复制链接]

论坛徽章:
0
11 [报告]
发表于 2008-11-26 11:07 |只看该作者

回复 #9 golotv 的帖子

谢谢,都说了,这个我也想过,问题是我的脚本很多参数(10个左右),会不会把这个搞的很长呢?

论坛徽章:
0
12 [报告]
发表于 2008-11-26 12:01 |只看该作者
command arg1 arg2 ... &&
command arg1 arg2 ... &&
command arg1 arg2 ... &&
...
command arg1 arg2 ...

论坛徽章:
0
13 [报告]
发表于 2008-11-26 12:08 |只看该作者
修改一下

filelist= 'script1 arg1 arg2
script2 arg1 arg2
script3 arg1 arg2
scriptx  arg1 arg2
'

set -e
while read cmd
do
  $cmd
done <<<"$filelist"

论坛徽章:
0
14 [报告]
发表于 2008-11-26 13:34 |只看该作者
command1;command2 ..

论坛徽章:
0
15 [报告]
发表于 2008-11-27 11:04 |只看该作者
原帖由 bitterness 于 2008-11-26 13:34 发表
command1;command2 ..


这个不可以,前面的命令执行不成功,后面还会继续执行下去,只能用&&间隔。

论坛徽章:
0
16 [报告]
发表于 2008-11-28 00:57 |只看该作者

I finished it, it works.........

#!/bin/ksh
#Function: Run a chain of jobs sequently, when one job is aborded, quit it and send out notification
#By George16Nov. 26th. 2008

#Define the commnad list need to be run.
CMD_LIST=/home/george16/test.list

#Define the email variable
MAIL_L="george16@chinaunix.com"
MAILFILE=/tmp/dependency.log
MAIL_S="Dependency job aborded!!!"

while read cmd
  do
    $cmd
    RC=$?
    if [ "$RC" -eq "0" ]
    then
      echo run $cmd successfully!!!!!!!!!!! return code is $RC
    else
      echo return code $RC
      echo Job $cmd failed!!! Please investigate!!! Reture code is $RC > $MAILFILE
      MAIL_S="$Dependency job $cmd ABORDED!!!"
      mail -s "${MAIL_S}" ${MAIL_L} < ${MAILFILE}
      exit
    fi
  done < $CMD_LIST

[ 本帖最后由 george16 于 2008-11-28 00:58 编辑 ]
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP