1、修改Apache服务器端口
编写脚本,实现对于Apache服务器的端口修改,默认需要输入端口号,假设Selinux未开启
8 #!/bin/bash
9 [ -z "$1" ] && {
10 echo "Error: not port number Please input following scipt"
11 exit
12 }
13
14 [ -z "`netstat -antlupe | grep $1`" ] ||{
15 echo "Error: $1 is uaed by system proto !!"
16 }
17
18 [ -e "/etc/httpd/conf/httpd.conf" ] || {
19 yum install httpd -y &> /dev/null || {
20 echo "Error: apache not install and yum repo is not avaliable"
21 exit
22 }
23 }
24
25 sed " /^Listen/c Listen $1" -i /etc/httpd/conf/httpd.conf
26 systemctl restart httpd > /dev/null && {
27 echo "Confiure port sucessful !!"
28 }||{
29 echo "Error: can't up sevice"
30 }
2、从网卡获取IP地址
8 #!/bin/bash
9 ifconfig enp1s0|head -n2|tail -n1|cut -d ' ' -f10
8 ifconfig enp1s0|awk -F '[ ]' 'NR==2{print $10}'
3、su切换用户的用户数量统计
编写脚本,输出系统中家目录不在Home目录下,但能够su切换用户的用户数量
awk -F : 'BGEIN{N=0}$6!~/^\/home/&&/bash$|sh$/{N++}END{print N}' /etc/passwd
3、倒计时脚本
#!/bin/bash
read -p "Please input M:" M
read -p "Please input S:" S
t=$((M*60+S))
for ((t;t>0;t--))
do
M=$((t/60))
S=$((t%60))
echo "$M:$S"
sleep 1
clear
done
4、创建用户脚本
编写users_create.sh,执行sh users_create.sh userlist passlist建立userlist用户列表中的用户,设定userlist列表中的密码为passlist列表中的密码,当执行脚本时脚本后跟的文件个数不足两个时报错,当userlist用户列表文件行数(用户数量)和passlist列表文件行数(对应密码数量)不一致时报错,当文件不存在时报错,当用户存在时报错。
8 #!/bin/bash
9 if [ "$USER" != "root" ]
10 then
11 echo "Error: $USER is not root !!"
12 elif [ "$#" -lt "2" ]
13 then
14 echo "Error: Please input userlist and passwdlist $#"
15 elif [ ! -e "$1" ]
16 then
17 echo "Error: $1 is not exist !!!"
18 elif [ ! -e "$2" ]
19 then
20 echo "Error: $2 is not exist !!!"
21 else
22 USER_LINE=`awk 'END{print NR}' $1`
23 PASS_LINE=`awk 'END{print NR}' $2`
24 if [ "$USER_LINE" = "$PASS_LINE" ]
25 then
26 for LINE in `seq 1 $USER_LINE`
27 do
28 USERNAME=`sed -n ${LINE}p $1`
29 USPASSWD=`sed -n ${LINE}P $2`
30 useradd $USERNAME &> /dev/null && {
31 echo $USPASSWD | passwd --stdin $USERNAME &> /dev/null && echo "$USERNAME is created !!"
32 }||{
33 echo "Error: $USERNAME is exist !!"
34 }
35 done
36 else
37 echo "Error: $1's lines is different from $2 !!"
38 fi
39 fi
5、系统资源使用统计脚本
编写check_upload.sh脚本,统计系统中CPU和内存的使用总量
9 echo "MEM: `ps -x -o %mem | awk 'BEGIN{MEM=0.0} {MEM+=$1}END{print MEM}'`%"
10 echo "CPU: `ps -x -o %cpu | awk 'BEGIN{CPU=0.0} {CPU+=$1}END{print CPU}'`%"
6、swap分区自动创建脚本
用脚本在当前系统中添加一个swap分区,swap分区大小为500M并在开机时自动激活此分区。
7、每日生成一个文件
按照xxxx-xx-xx的格式每天生成一个文件,并把磁盘使用情况写到这个文件中,并一年一次覆盖
#!/bin/bash
T=`date +%F`
dir=/date/log
if [ ! -d $dir ]
then
mkdir -p $dir
fi
df -h > $T.log
find $dir -stime +365 | xargs rm