> /dev/null fi x=0 while [ $x -lt $lunNumber ] do y=`expr $x % 2` if [ $y -eq 0 ] then echo "create logicalDrive array=$arrayNumber userLabel="$。利用 UNIX 脚本来管理 DS4000 磁盘阵列系统( 三 )。" />

利用 UNIX 脚本来管理 DS4000 磁盘阵列系统( 三 )


if [ -f crtlun.cmd ]
then
rm crtlun.cmd
else
echo "OK" >> /dev/null
fi
x=0
while [ $x -lt $lunNumber ]
do
y=`expr $x % 2`
if [ $y -eq 0 ]
then
echo "create logicalDrive array=$arrayNumber userLabel="${lunName}_${x}"
capacity=$capacity owner=a;" >> crtlun.cmd
else
echo "create logicalDrive array=$arrayNumber userLabel="${lunName}_${x}"
capacity=$capacity owner=b;" >> crtlun.cmd
fi
x=`expr $x1`
done
# 创建 IBM storage manager 使用的脚本中创建 host group,host 和 host port 的部分,并保存为 crthost.cmd 。
if [ -f crthost.cmd ]
then
rm crthost.cmd
else
echo "OK" >> /dev/null
fi
echo "create hostGroup userLabel="$hostGroupName";" >>crthost.cmd
echo "create host userLabel = "$hostName" hostGroup = "$hostGroupName";" >>crthost.cmd
echo "create hostPort identifIEr = "$port0" userLabel = "${hostName}_hba0"
host = "$hostName" hostType = $hostType;" >>crthost.cmd
echo "create hostPort identifier = "$port1" userLabel = "${hostName}_hba1"
host = "$hostName" hostType = $hostType;" >>crthost.cmd
# 创建 IBM storage manager 使用的脚本中映射 Lun 的部分,并保存为 maplun.cmd 。
if [ -f maplun.cmd ]
then
rm maplun.cmd
else
echo "OK" >> /dev/null
fi
x=0
while [ $x -lt $lunNumber ]
do
echo "set logicalDrive ["${lunName}_${x}"] logicalUnitNumber=$x
hostGroup="$hostGroupName";" >>maplun.cmd
x=`expr $x1`
done
# 创建 IBM storage manager 使用的脚本中删除 Lun 映射的部分,并保存为 delmap.cmd 。
if [ -f delmap.cmd ]
then
rm delmap.cmd
else
echo "OK" >> /dev/null
fi
x=0
while [ $x -lt $lunNumber ]
do
echo "remove logicalDrive ["${lunName}_${x}"] lunMapping
hostGroup="$hostGroupName";" >>delmap.cmd
x=`expr $x1`
done
# 创建 IBM storage manager 使用的脚本中删除 Lun 的部分,并保存为 dellun.cmd 。
if [ -f dellun.cmd ]
then
rm dellun.cmd
else
echo "OK" >> /dev/null
fi
x=0
while [ $x -lt $lunNumber ]
do
echo "delete logicalDrive ["${lunName}_${x}"];" >>dellun.cmd
x=`expr $x1`
done
# 创建 IBM storage manager 使用的脚本中删除 host port 的部分,并保存为 delhost.cmd 。
if [ -f delhost.cmd ]
then
rm delhost.cmd
else
echo "OK" >> /dev/null
fi
echo "delete hostPort ["$port0"];" >>delhost.cmd
echo "delete hostPort ["$port1"];" >>delhost.cmd
echo "delete host ["$hostName"];" >>delhost.cmd
echo "delete hostGroup ["$hostGroupName"];" >>delhost.cmd
# 创建 IBM storage manager 使用的 2 个功能集合脚本,并分别保存为 setup.cmd 和 destroy.cmd 。
if [ -f setup.cmd ]
then
rm setup.cmd
else
echo "OK" >> /dev/null
fi
cat crtlun.cmd >>setup.cmd
cat crthost.cmd >>setup.cmd
cat maplun.cmd >>setup.cmd
if [ -f destroy.cmd ]
then
rm destroy.cmd
else
echo "OK" >> /dev/null
fi
cat delmap.cmd >>destroy.cmd
cat delhost.cmd >>destroy.cmd
cat dellun.cmd >>destroy.cmd
总结
从上面可以看出,整个脚本使用的技术不是很复杂,主要是利用 SED 编辑器通过模式匹配从配置文件中提取出所需要的部分,然后从新组织起来,形成一定的符合 IBM storage manager 使用的格式 。其中还利用了一些简单的正则表达式,这在很多系统管理的脚本中很常见,可见功能的实效性 。当然,作为 SED 这个强大的编辑器,功能远远不止这些,这里也是希望能通过我的一些实践和大家分享一些使用脚本的心得 。最终的目的还是提高工作的效率,哪一个管理员或是相关的工程师也不希望总是做一些没有技术含量而且重复性很大的工作,所以脚本以及 SED 编辑器,Awk 等工具都是各位很好的帮手 。下面看一下所生成的两个功能集合脚本的内容,体验一下成果的滋味 。

推荐阅读