liunx用户环境初始化脚本
编写生成脚本基本格式,包括作者,联系方式,版本,时间,描述等
[root@magedu ~]# vim .vimrc set ignorecase set cursorline set autoindent autocmd BufNewFile *.sh exec ":call SetTitle()" func SetTitle() if expand("%:e") == 'sh' call setline(1,"#!/bin/bash") call setline(2,"#") call setline(3,"#********************************************************************") call setline(4,"#Author: w") call setline(5,"#QQ: 1****") call setline(6,"#Date: ".strftime("%Y-%m-%d"))
call setline(7,"#FileName: ".expand("%")) call setline(8,"#URL: http://www.magedu.com") call setline(9,"#Description: The test script") call setline(10,"#Copyright (C): ".strftime("%Y")." All rights reserved") call setline(11,"#********************************************************************") call setline(12,"") endif endfunc autocmd BufNewFile * normal G
编写用户的环境初始化脚本reset.sh,包括别名,登录提示符, vim的设置,环境变量,取OS版本号,网卡名更改,seliunx关闭等:
[09:26:08 root@centos ~]#vim reset.sh
1 #!/bin/bash
2 #
3 #****************************************************************
4 #Author: yangtao
5 #QQ: 1060351846
6 #Date: 2019-10-10
7 #FileName: reset.sh
8 #URL: https://www.cnblogs.com/www233ii/
9 #Description: The test script
10 #Copyright (C): 2019 All rights reserved
11 #***************************************************************
12 CS="\033[1;$[RANDOM%7+31]m"
13 CE="\033[0m"
这儿是定义了一些别名登陆时自动启用的,还有就是登陆提示符。
14 cat > /etc/profile.d/env.sh << EOF
15 alias cdnet="cd /etc/sysconfig/network-scripts"
16 alias editnet="vim /etc/sysconfig/network-scripts/ifcfg-ens33"
17 export PS1="[\[\e[32m\]\u\[\e[36m\]@\h_v7\[\e[31m\]\[\e[0m\] \w]\\$ "
18 export PATH=/app/bin:$PATH
19 EOF
20
21 cat > ~/.vimrc << EOF
22 set nu
23 EOF
24 #取os版本号
25 VER=`sed -rn 's@^.* ([0-9]+)\..*@\1@p' /etc/redhat-release`
26 #修改centos7,8网卡名为传统网卡名
27 if [ $VER -ge 7 ];then
28 sed -ir '/GRUB_CMDLINE_LINUX/s@"$@ net.ifnames=0"@' /etc/default/grub
29 grub2-mkconfig -o /etc/grub2.cfg
30 fi
这个是更改selinux启用和关闭
31 #Disable selinux
32 sed -i 's@^SELINUX=enforcing@SELINUX=disabled@p' /etc/selinux/config