拓扑,配置,事务,任务都生成好了,需要一个下载文件来描述。
针对每一个任务,有两项足以描述:
第一:要下载的配置信息,其实也就是一个任务的事务中的配置列表,当然是有序的,以及每一个配置节点的信息。
第二:要下载给的对象,给谁下载,也就是主机-群组列表
配置用polist来描述
设备用device来描述
每个任务的目录下有两个文件,就足以表征这任务了。
比如:
- tree data/download/1*
- data/download/18
- |-- device
- `-- polist
- data/download/19
- |-- device
- `-- polist
这样描述了ID为18和19的两个任务的所有信息。
其中,配置信息为:
- cat data/download/18/polist
- [general]
- name=app1
- group=3
- time=1_2011-07-04_00_00
- transid=46
- [idex_0]
- polid=75
- index=1
- depend=1
还有主机列表为:
- cat data/download/18/device
- [dev_0]
- group=3
- devname=214vm
- devid=1
- devip=3591643146
- [dev_1]
- group=3
- devname=vmlinux14
- devid=4
- devip=241573898
每个任务目录下的文件格式都是一样的。
拥有这两个文件,就能完成每个任务的发送工作。
下面是生成脚本:
ge_app.sh
- mkdir -pv "data/download" > /dev/null 2>&1
- tmpfile="data/`echo $$`.txt"
- unlink "$tmpfile" > /dev/null 2>&1
- touch "$tmpfile"
- # the code below is used to export all application list
- # the result is saved in "data/download/XXX" XX is the id of each application
- #
- ls data/application | while read appid
- do
- tdir="data/application/$appid"
- adir="data/download/$appid"
- tfile="$adir/polist"
- mkdir -pv "$adir" > /dev/null 2>&1
- unlink "$tfile" > /dev/null 2>&1
- touch "$tfile" > /dev/null 2>&1
- #check file "group"
- if ! [ -f "$tdir/group" ]
- then
- echo "can not find file 'group' in directory '$tdir'"
- continue;
- fi
- group=`cat "$tdir/group"`
-
- #save group list to get device list
- echo "$appid $group" >> "$tmpfile"
- #check file "name"
- if ! [ -f "$tdir/name" ]
- then
- echo "can not find file 'name' in directory '$tdir'"
- continue;
- fi
- name=`cat "$tdir/name"`
- #check file "time"
- if ! [ -f "$tdir/time" ]
- then
- echo "can not find file 'time' in directory '$tdir'"
- continue;
- fi
- tm=`cat "$tdir/time"`
- #check file "transid"
- if ! [ -f "$tdir/transid" ]
- then
- echo "can not find file 'transid' in directory '$tdir'"
- continue;
- fi
- transid=`cat "$tdir/transid"`
-
- #check file "polist"
- if ! [ -f "$tdir/polist" ]
- then
- echo "can not find file 'polist' in directory '$tdir'"
- continue;
- fi
- #print header of this application
- echo "[general]" > "$tfile"
- echo "name=$name" >> "$tfile"
- echo "group=$group" >> "$tfile"
- echo "time=$tm" >> "$tfile"
- echo "transid=$transid" >> "$tfile"
- echo "" >> "$tfile"
- idx=0
-
- cat "$tdir/polist" | while read polid index depd
- do
- echo "[idex_$idx]" >> "$tfile"
- echo "polid=$polid" >> "$tfile"
- echo "index=$index" >> "$tfile"
- echo "depend=$depd" >> "$tfile"
- echo "" >> "$tfile"
- idx=`expr $idx + 1`
- done
- echo "" >> "$tfile"
- done
- #the code below is used to get all device list of each application
- #
- #
- #sed 's/-/ /g' "$tmpfile"
- cat "$tmpfile" | while read appid group
- do
- ff="data/download/$appid/device"
- unlink "$ff" > /dev/null 2>&1
- touch "$ff" > /dev/null 2>&1
- nn=0
- #getting device of each group
- for grpid in `echo "$group" | sed 's/-/ /g'`;
- do
- ndir="data/dev/$grpid/devlist"
- for host in `ls "$ndir/"`;
- do
- hid="$host"
- #check host name file
- if ! [ -f "$ndir/$host/name" ]
- then
- continue;
- fi
- #check ip file
- if ! [ -f "$ndir/$host/ip" ]
- then
- continue;
- fi
- hname=`cat "$ndir/$host/name"`
- hip=`cat "$ndir/$host/ip"`
- #echo "grp=$grpid,id=$hid,name=$hname,ip=$hip"
- echo "[dev_$nn]" >> "$ff"
- echo "group=$grpid" >> "$ff"
- echo "devname=$hname" >> "$ff"
- echo "devid=$hid" >> "$ff"
- echo "devip=$hip" >> "$ff"
- echo "" >> "$ff"
- nn=`expr $nn + 1`
- done
- done
- #echo "========================"
- #echo "$appid $time"
- done
- unlink "$tmpfile" > /dev/null 2>&1