码迷,mamicode.com
首页 > 其他好文 > 详细

BASH 脚本制作简单 Workflow - 更新 2014/6/17 12:00

时间:2014-06-17 19:18:30      阅读:293      评论:0      收藏:0      [点我收藏+]

标签:linux   command   工作流   workflow   

因为需要,我创建了一个脚本叫 wf.sh (随意起什么名字),它可以读取当前目录下的 config.ini 配置文件来解析并执行工作流任务(Workflow)。


直接上代码:

config.ini

Workflow.Name = example
Workflow.Description = my work flow example \n and I know what's going on here.
#Workflow.StartJob = job1
Workflow.NextJobCounts = 1
Workflow.NextJob1.Name = job1

Job.job1.Command = echo "I am job1"; sleep 3;
Job.job1.NextJobCounts = 3
Job.job1.NextJob1.Name = job2
Job.job1.NextJob2.Name = job3
Job.job1.NextJob3.Name = job4

Job.job2.Command = echo "I am job2"; sleep 3;
Job.job2.NextJobCounts = 0

Job.job3.Command = echo "I am job3"; sleep 3;
Job.job3.NextJobCounts = 0

Job.job4.Command = echo "I am job4"; sleep 3;
Job.job4.NextJobCounts = 1
Job.job4.NextJob1.Name = job5

Job.job5.Command = echo "I am job5"; sleep 3;
Job.job5.NextJobCounts = 1
Job.job5.NextJob1.Name = job6

Job.job6.Command = echo "I am job6"; sleep 3;
Job.job6.NextJobCounts = 0



wf.sh

#!/bin/bash

CFGGet() {
  grep "^$1 = " config.ini | tail -1 | sed 's~^[^=]* = \(.*\)$~\1~g'
}

# Notify: make sure launch() is below library functions and dependencies.
launch() {
  local job="$1"
  local ret=0

  eval $(CFGGet Job.${job}.Command) || {
    ret=$?
    echo FAIL,$ret, command [$(CFGGet Job.${job}.Command)] is fail.
    exit $ret
  }

  local nextJobCounts=$(CFGGet Job.${job}.NextJobCounts)
  for ((i=1;i<=nextJobCounts;i++)); do
    eval launch $(CFGGet Job.${job}.NextJob${i}.Name) &
  done

  return 0
}

run() {
  local jobCounts=$(CFGGet Workflow.NextJobCounts)

  for ((i=1;i<=jobCounts;i++)); do
    launch $(CFGGet Workflow.NextJob${i}.Name) &
  done

  return 0
}

run



运行方式:

$ ./wf.sh


BASH 脚本制作简单 Workflow - 更新 2014/6/17 12:00,布布扣,bubuko.com

BASH 脚本制作简单 Workflow - 更新 2014/6/17 12:00

标签:linux   command   工作流   workflow   

原文地址:http://blog.csdn.net/wxqee/article/details/31745037

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!