编写属于自己的初始化脚本

  当我们新装好虚拟机时我们需要用户环境设置成我们常用的环境。比如别名,提示符,设置vim编写脚本时自动添加信息注释。但是加入我们每装一台机器都自己手动设置那么就会浪费我们的时间,所以就需要我们编写脚本。

#!/bin/bash
#
#***********************************************
#Filename:      reset.sh
#Author:        D Y
#Description:   Initialize user environment
#Create:        2019-08-01 13:54:31
#***********************************************
vr='.vimrc'
[ ! -e $vr ] && touch $vr
echo "set tabstop=4" >> $vr
echo "set cul" >> $vr
echo 'autocmd BufNewFIle *.sh exec " call Setfilehead()" ' >> $vr
echo 'func Setfilehead()' >> $vr
echo 'if expand("%:e") == "sh" ' >> $vr
echo '    call setline(1,"#/bin/bash")' >> $vr
echo "    call setline(2, '#')" >> $vr
echo "    call setline(3, '#***********************************************')" >> $vr
echo '    call setline(4, "#Filename:      ".expand("%"))' >>$vr
echo "    call setline(5, '#Author:        D Y')" >> $vr
echo "    call setline(6, '#Description:   ---')" >> $vr
echo "    call setline(7, '#QQ:            2841184943')" >> $vr
echo "    call setline(8, '#Create:        '.strftime('%Y-%m-%d %H:%M:%S'))" >> $vr
echo "    call setline(9, '#***********************************************')" >> $vr
echo "        endif" >> $vr
echo "endfunc" >> $vr
#PS1
echo "PS1=\e[1;31m[\u@\h \W]\\$\e[0m" >> .bashrc && . .bashrc
#touch /etc/profile.d/env.sh
if [ ! -f /etc/profile.d/env.sh ]; then
	touch /etc/profile.d/env.sh
	echo "echo -e '\e[1;31mHi,you need to think the impact of your opearation\e[0m'" >> /etc/profile.d/env.sh
fi
#close SELINUX
sed -r 's/(^SELINUX=)enforcing/\1disabled/' /etc/selinux/config                
#owner alias
echo "alias cdnet='cd /etc/sysconfig/network-scripts/'" >> .bashrc
echo "alias cp='cp -i'" >> .bashrc
echo "alias editnet1='vim /etc/sysconfig/network-scripts/ifcfg-eth0'" >> .bashrc
echo "alias editnet2='vim /etc/sysconfig/network-scripts/ifcfg-eth1'" >> .bashrc

  PS:由于目前在初步接触linux,所以这个初始化脚本还不是很完善,以后我会不断添加新内容,或者优化此脚本。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值