标签:style 文件 io art ar 时间 new size
#!/bin/bash echo "fdisk success" -sed -i ‘/fdisk.sh/d‘ /etc/rc.d/rc.local +sed -i ‘s/fdisk.sh/reboot.sh/‘ /etc/rc.d/rc.local + reboot
主要是格式化磁盘,写在 /etc/rc.local 删除不彻底(/etc/rc.local 是links,用sed 修改文件时 把/etc/rc.local 变成regular file) 这个回头找个时间再看看sed实现原理,运行脚本是执行完后 从rc.d/rc.local 中去掉 /opt/fdisk.sh
#!/bin/bash -if [ ! -f /opt/fdisk ] -then - echo "fdisk not exist" - touch /opt/fdisk - echo "reboot" -else -echo "fdisk is exist" touch /opt/testNB sed -i ‘/reboot.sh/d‘ /etc/rc.d/rc.local -fi
这一步 先test -f /opt/fdisk 文件存在,则执行mkfs.ext4 等操作, 这个文件本身是不存在的,所以先利用这一点 创建fdisk 文件,再reboot, 启动后,会在执行这个脚本,由于文件fdisk 存在了,就开始执行下面的操作。
我是写了个/opt/testNB的文件,最后都搞定了,就需要把reboot.sh 这个脚本干掉。
[root@BJ-W-2101 opt]# cat /etc/rc.d/rc.local #!/bin/sh # # This script will be executed *after* all the other init scripts. # You can put your own initialization stuff in here if you don‘t # want to do the full Sys V style init stuff. touch /var/lock/subsys/local /opt/fdisk.sh -/opt/reboot.sh
下面是在开机把salt-minion id的 信息添加到/etc/salt/minion中
#!/bin/bash if [ -z `grep "^id:" /etc/salt/minion ` ] then echo "id is not found" ip=`cat /etc/sysconfig/network-scripts/ifcfg-eth0|awk -F"=" ‘/IPADDR/{print $2}‘|tr -d ‘"‘` echo "id: $ip" >> /etc/salt/minion /etc/init.d/salt-minion restart else echo "id is exist in file" fi sed -i ‘/salt.sh/d‘ /etc/rc.d/rc.local
格式化磁盘脚本 开机自动格式化磁盘,生成/dev/vda5 挂载到/export上
#!/bin/bash # script name fdisk.sh # create user: davis.ying@gmail.com fdisk -cu /dev/vda <<ESXU n e n w ESXU sed -i ‘s/fdisk.sh/new.sh/‘ /etc/rc.d/rc.local reboot
#!/bin/bash # script name: new.sh mkfs.ext4 /dev/vda5 #mount -t ext4 /dev/vda5 /export uuid=`blkid /dev/vda5|awk -F‘"‘ ‘{print $2}‘` echo "UUID=$uuid /export ext4 defaults 1 2" >>/etc/fstab mount -a sed -i ‘/new/d‘ /etc/rc.d/rc.local
[root@ export]# cat /etc/rc.local #!/bin/sh # # This script will be executed *after* all the other init scripts. # You can put your own initialization stuff in here if you don‘t # want to do the full Sys V style init stuff. touch /var/lock/subsys/local /opt/fdisk.sh
firstboot script 类似功能实现,布布扣,bubuko.com
标签:style 文件 io art ar 时间 new size
原文地址:http://my.oschina.net/davisqi/blog/295623