#!/bin/bashecho "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
Format the disk and write it in/etc/rc. the local deletion is incomplete (/etc/rc. local is links. When you use sed to modify the file, set/etc/rc. local is changed to regular file.) Let's look back at the SED implementation principle and run the script from RC after execution. d/RC. remove/opt/fdisk from local. 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
In this step, if the test-F/opt/fdisk file exists, run mkfs. ext4 and other operations, the file itself does not exist, so first use this to create the fdisk file, and then reboot, after the startup, the script will be executed, because the file fdisk exists, start to perform the following operations.
I wrote a/opt/testnb file and finished all the work at last. I need to kill the reboot. Sh script.
[[email protected] 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
Add the information of Salt-Minion ID to/etc/salt/minion at startup.
#!/bin/bashif [ -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 restartelse echo "id is exist in file"fised -i ‘/salt.sh/d‘ /etc/rc.d/rc.local
Format the disk script to automatically format the disk at boot, and generate/dev/vda5 and mount it to/export.
#!/bin/bash# script name fdisk.sh# create user: [email protected]fdisk -cu /dev/vda <<ESXUn enwESXUsed -i ‘s/fdisk.sh/new.sh/‘ /etc/rc.d/rc.localreboot
#!/bin/bash# script name: new.shmkfs.ext4 /dev/vda5#mount -t ext4 /dev/vda5 /exportuuid=`blkid /dev/vda5|awk -F‘"‘ ‘{print $2}‘`echo "UUID=$uuid /export ext4 defaults 1 2" >>/etc/fstabmount -ased -i ‘/new/d‘ /etc/rc.d/rc.local
[[email protected] 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