第四次作业

1.自动增添用户

[root@desktop mnt]# cat useradd.sh

#!/bin/bash

NUMUSERS=`wc -l /mnt/username |cut -d " " -f 1`

NUMPASSWD=`wc -l /mnt/passwd |cut -d " " -f 1`

if

[ "$NUMUSERS" = "0" -o "$NUMPASSWD" = "0" ]

then

echo 文件为空

else

if

[ "$NUMUSERS" = "$NUMPASSWD" ]

then

echo 有 $NUMUSERS 用户名

echo 有 $NUMPASSWD 密码

for NUM in $(seq 1 $NUMUSERS)

do

USERNAME=`sed -n ${NUM}p /mnt/username`

PASSWD=`sed -n ${NUM}p /mnt/passwd`

id $USERNAME &>/dev/null

if

[ "$?" != "0" ]

then

useradd $USERNAME

echo $PASSWD | passwd --stdin $USERNAME

else

echo $USERNAME 该用户存在

fi

done

else

read -p "你的用户名文件与密码文件不想等是否继续(y/n)" SURE

if

[ "$SURE" = "y" -a "$NUMUSERS" -lt "$NUMPASSWD" ]

then

NUM1=$(($NUMPASSWD-$NUMUSERS))

echo 密码文件多了 $NUM1 个

elif

[ "$SURE" = "y" -a "$NUMUSERS" -gt "$NUMPASSWD" ]

then

NUM2=$(($NUMUSERS-$NUMPASSWD))

echo 用户名文件多了 $NUM2 个

else

echo 你可以确定下文件是否有错

fi

fi

fi

 

2.ssh自动连接

[root@desktop mnt]# cat ask.sh

#!/bin/bash

read -p 'username:' USER

read -p 'ip' IP

read -p 'password:' -s PWD

ssh $USER@$IP

[root@desktop mnt]# cat answer.exp

#!/usr/bin/expect

set USER [ lindex $argv 0 ]

set PWD [ lindex $argv 1 ]

set IP [ lindex $argv 2 ]

spawn /mnt/ask.sh

expect {

"Are you sure" {send "yes\r"; exp_continue}

"username" {send "$USER\r"; exp_continue}

"password" {send "$PWD\r"; exp_continue}

"ip" {send "$IP\r"; exp_continue}

}

interact

3.ddns

 

[root@localhost mnt]# cat ddns.sh

#!/bin/bash

#前期准备############OKOKOK

systemctl start named &>/dev/null

if

        [ "$?" = "0" ]

then

        echo you have DNS service

else

        echo i will install bind

        yum install bind -y

        systemctl start named &>/dev/null

        echo service is ok

fi

systemctl start dhcpd &>/dev/null

if

        [ "$?" = "0" ]

then

        echo you have DHCP service

else

        echo i will install DHCPD service

        yum install dhcp -y

fi

#over 

####用户信息提取######OKOKOK

read -p "yumingshi:" YUMING

read -p "加密文件:" NAME

read -p "请设置IP范围下限:" SMALL

read -p "请设置IP范围上限:" DIG

WANGDUAN=`ifconfig | sed -n 2p | cut -d " " -f 10|cut -d '.' -f 1-3`

IP=`ifconfig | sed -n 2p | cut -d " " -f 10`

NETMSK=`route | sed -n 3p | cut -d " " -f 14-15`

echo please input your client anything

dnssec-keygen -a HMAC-MD5 -b 128 -n HOST $NAME

MIMA=`cat /mnt/*.key | cut -d " " -f 7`

########################

cat >> /etc/named.rfc1912.zones << EOF

zone "$YUMING.com" IN {

type master;

file "$YUMING.com.zone";

allow-update { key $NAME; };

};

EOF

###########################

chmod 770 /var/named

touch /var/named/$YUMING.com.zone

#####################zone##########OKOKOKOK

cat >/var/named/ $YUMING.com.zone << EOF

$TTL 1D

@       IN SOA  dns.$YUMING.com. root.$YUMING.com. (

 0       ; serial

1D      ; refresh

1H      ; retry

     1W      ; expire

3H )    ; minimum

NS      dns.$YUMING.com.

dns     A       172.25.254.124

www     A       172.25.254.238

EOF

################################

##################################OKOKOK

cat >> /etc/named.conf <<EOF

key "$NAME" {

algorithm hmac-md5;

secret "$MIMA";

         };

EOF

echo include "/etc/$NAME.key"; >> /etc/named.conf

#########################################

###pei zhi DHCP###############################OKOKOK

cat > /etc/dhcp/dhcpd.conf << EOF

option domain-name "$YUMING.com";

option domain-name-servers $IP;

default-lease-time 600;

max-lease-time 7200;

ddns-update-style interim;

subnet $WANGDUAN.0 netmask $NETMSK {

range ${WANGDUAN}.${SMALL} ${WANGDUAN}.${DIG};

option routers $WANGDUAN.254;

}

key $NAME {

algorithm hmac-md5;

secret "$MIMA";

};

zone $YUMING.com. {

primary 127.0.0.1;

key $NAME;

}

EOF

systemctl restart dhcp

##########################################

sed s/127.0.0.1/any/ /etc/named.conf -i

sed s/"loaclhost;"/"any;"/ /etc/named.conf -i

systemctl restart named

setsebool -P named_write_master_zone 1

4.数据库备份

[root@desktop mnt]# cat databaes.sh

#!/bin/bash

read -p "请输入登陆使用的用户名:" USERNAME

read -p "用户密码:" -s PWD

mysql -u$USERNAME -p$PWD -e "show databases;" &>/dev/null

if

[ "$?" = "0" ]

then

read -p "备份路径:(/xxx/xxx)" LJ

mysql -u$USERNAME -p$PWD -e "SHOW DATABASES;"

read -p "您想备份上述那个数据库:" NAMEDATA

read -p "您确定备份 $NAMEDATA数据库吗?:(y/n)" SUER

if

[ "$SUER" = "y" ]

then

mysqldump -u$USERNAME -p$PWD  $NAMEDATA > $LJ/$NAMEDATA.sql

cat $NAMEDATA.sql &>/dev/null && echo 备份完毕 || echo 备份失败

else

echo 再见

fi

else

echo 您的用户名或密码出错请查正

fi

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值