生成rundeck的resources文件的shell脚本

这里选择json格式的文件,首先是一个模板文件叫tl.json

"_ALLIP": {
    "username": "ffsa",
    "hostname": "_IP",
    "nodename": "_ALLIP",
    "adminip": "_ADMINIP",
    "idracmac": "_IDRACMAC",
    "mod": "_MOD",
    "sn": "_SN",
    "appname": "_APPNAME",
    "master": "_MASTER"
},

脚本如下,cmdb_pserver.list文件是从CMDB数据库中查询出来的服务器信息列表

#!/bin/bash

echo "{" > resources_pserver.json
cat cmdb_pserver.list |\
while read line;do
    ALLIP=`echo $line |awk '{print $1}'`
    IP=`echo $line |awk '{print $1}'|awk -F '|' '{print $1}'`
        ADMINIP=`echo $line |awk '{print $2}'`
    IDRACMAC=`echo $line |awk '{print $3}'`
    MOD=`echo $line |awk '{print $5}'`
    SN=`echo $line |awk  '{print $4}'`
        APPNAME=`echo $line |awk '{print $6}'`
        MASTER=`echo $line |awk '{print $7}'`

    #echo "===================================="
        #echo allip: $ALLIP
    #echo ip: $IP
    #echo adminip: $ADMINIP
    #echo idracmac: $IDRACMAC
    #echo mod: $MOD
    #echo sn: $SN
    #echo appname: $APPNAME
    #echo master: $MASTER

    cat tl.json |sed -e "s/_ALLIP/$ALLIP/g" -e "s/_IP/$IP/g" -e "s/_ADMINIP/$ADMINIP/g" -e "s/_IDRACMAC/$IDRACMAC/g" -e "s/_MOD/$MOD/g" -e "s/_SN/$SN/g" -e "s/_APPN
AME/$APPNAME/g" -e "s/_MASTER/$MASTER/g" >> resources_pserver.json

done

sed -i '$s/,$//' resources_pserver.json
echo "}" >> resources_pserver.json

 

发表评论

电子邮件地址不会被公开。 必填项已用*标注