Chinaunix首页 | 论坛 | 博客
  • 博客访问: 269992
  • 博文数量: 42
  • 博客积分: 2718
  • 博客等级: 少校
  • 技术积分: 467
  • 用 户 组: 普通用户
  • 注册时间: 2006-03-19 10:23
个人简介

青 田 酒 店 服 务 小 姐 价 格 186-6531-7773

文章分类

全部博文(42)

文章存档

2011年(36)

2010年(6)

分类: LINUX

2011-07-06 16:33:08

拓扑,配置,事务,任务都生成好了,需要一个下载文件来描述。
针对每一个任务,有两项足以描述:
第一:要下载的配置信息,其实也就是一个任务的事务中的配置列表,当然是有序的,以及每一个配置节点的信息。
第二:要下载给的对象,给谁下载,也就是主机-群组列表
 
配置用polist来描述
设备用device来描述
 
每个任务的目录下有两个文件,就足以表征这任务了。
比如:
  1. tree data/download/1*
  2. data/download/18
  3. |-- device
  4. `-- polist
  5. data/download/19
  6. |-- device
  7. `-- polist

这样描述了ID为18和19的两个任务的所有信息。

其中,配置信息为:

 

  1. cat data/download/18/polist
  2. [general]
  3. name=app1
  4. group=3
  5. time=1_2011-07-04_00_00
  6. transid=46

  7. [idex_0]
  8. polid=75
  9. index=1
  10. depend=1

还有主机列表为:

 

  1. cat data/download/18/device
  2. [dev_0]
  3. group=3
  4. devname=214vm
  5. devid=1
  6. devip=3591643146

  7. [dev_1]
  8. group=3
  9. devname=vmlinux14
  10. devid=4
  11. devip=241573898

每个任务目录下的文件格式都是一样的。

拥有这两个文件,就能完成每个任务的发送工作。

下面是生成脚本:

ge_app.sh

 

  1. mkdir -pv "data/download" > /dev/null 2>&1
  2. tmpfile="data/`echo $$`.txt"
  3. unlink "$tmpfile" > /dev/null 2>&1
  4. touch "$tmpfile"

  5. # the code below is used to export all application list
  6. # the result is saved in "data/download/XXX" XX is the id of each application
  7. #
  8. ls data/application | while read appid
  9. do
  10.     tdir="data/application/$appid"
  11.     adir="data/download/$appid"
  12.     tfile="$adir/polist"
  13.     mkdir -pv "$adir" > /dev/null 2>&1    
  14.     unlink "$tfile" > /dev/null 2>&1
  15.     touch "$tfile" > /dev/null 2>&1
  16.     #check file "group"
  17.     if ! [ -f "$tdir/group" ]
  18.     then
  19.         echo "can not find file 'group' in directory '$tdir'"
  20.         continue;
  21.     fi
  22.     group=`cat "$tdir/group"`
  23.     
  24.     #save group list to get device list
  25.     echo "$appid $group" >> "$tmpfile"

  26.     #check file "name"
  27.     if ! [ -f "$tdir/name" ]
  28.     then
  29.         echo "can not find file 'name' in directory '$tdir'"
  30.         continue;
  31.     fi
  32.     name=`cat "$tdir/name"`

  33.     #check file "time"
  34.     if ! [ -f "$tdir/time" ]
  35.     then
  36.         echo "can not find file 'time' in directory '$tdir'"
  37.         continue;
  38.     fi
  39.     tm=`cat "$tdir/time"`

  40.     #check file "transid"
  41.     if ! [ -f "$tdir/transid" ]
  42.     then
  43.         echo "can not find file 'transid' in directory '$tdir'"
  44.         continue;
  45.     fi
  46.     transid=`cat "$tdir/transid"`
  47.     
  48.     #check file "polist"
  49.     if ! [ -f "$tdir/polist" ]
  50.     then
  51.         echo "can not find file 'polist' in directory '$tdir'"
  52.         continue;
  53.     fi

  54.     #print header of this application
  55.     echo "[general]" > "$tfile"
  56.     echo "name=$name" >> "$tfile"
  57.     echo "group=$group" >> "$tfile"
  58.     echo "time=$tm" >> "$tfile"
  59.     echo "transid=$transid" >> "$tfile"
  60.     echo "" >> "$tfile"

  61.     idx=0
  62.     
  63.     cat "$tdir/polist" | while read polid index depd
  64.     do
  65.         echo "[idex_$idx]" >> "$tfile"
  66.         echo "polid=$polid" >> "$tfile"
  67.         echo "index=$index" >> "$tfile"
  68.         echo "depend=$depd" >> "$tfile"
  69.         echo ""     >> "$tfile"
  70.         idx=`expr $idx + 1`
  71.     done
  72.     echo "" >> "$tfile"
  73. done

  74. #the code below is used to get all device list of each application
  75. #
  76. #
  77. #sed 's/-/ /g' "$tmpfile"
  78. cat "$tmpfile" | while read appid group
  79. do
  80.     ff="data/download/$appid/device"
  81.     unlink "$ff" > /dev/null 2>&1
  82.     touch "$ff" > /dev/null 2>&1
  83.     nn=0    
  84.     #getting device of each group
  85.     for grpid in `echo "$group" | sed 's/-/ /g'`;
  86.     do
  87.         ndir="data/dev/$grpid/devlist"
  88.         for host in `ls "$ndir/"`;
  89.         do
  90.             hid="$host"
  91.             #check host name file
  92.             if ! [ -f "$ndir/$host/name" ]
  93.             then
  94.                 continue;
  95.             fi
  96.             #check ip file
  97.             if ! [ -f "$ndir/$host/ip" ]
  98.             then
  99.                 continue;
  100.             fi
  101.             hname=`cat "$ndir/$host/name"`
  102.             hip=`cat "$ndir/$host/ip"`
  103.             #echo "grp=$grpid,id=$hid,name=$hname,ip=$hip"
  104.             echo "[dev_$nn]" >> "$ff"
  105.             echo "group=$grpid" >> "$ff"
  106.             echo "devname=$hname" >> "$ff"
  107.             echo "devid=$hid" >> "$ff"
  108.             echo "devip=$hip" >> "$ff"
  109.             echo "" >> "$ff"
  110.             nn=`expr $nn + 1`
  111.         done
  112.     done
  113.     #echo "========================"
  114.     #echo "$appid $time"
  115. done
  116. unlink "$tmpfile" > /dev/null 2>&1
阅读(4855) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~