1、通过两个文件passwd username建立用户:
#!/bin/bash
USERNUM=$(wc -l /jiaoben/username | cut -d " " -f 1)
PASSNUM=$(wc -l /jiaoben/password | cut -d " " -f 1)
UNUM=$(wc -l /etc/passwd | cut -d " " -f 1)
count=0
if [ $USERNUM -le $PASSNUM ]
then
for NUM in $(seq 1 $USERNUM)
do
USER=`sed-n ${NUM}p /jiaoben/username`
PASSWD=`sed-n ${NUM}p /jiaoben/password`
id $USER &> /dev/null
if [ "$?" ="0" ]
then
echo"${USER}已经存在"
else
useradd $USER -p $PASSWD&> /dev/null
count=$((count+1))
fi
done
else
for NUM in $(seq 1 $PASSNUM)
do
USER=`sed -n ${NUM}p/jiaoben/username`
PASSWD=`sed -n ${NUM}p/jiaoben/password`
id $USER &>/dev/null
if [ "$?" ="0" ]
then
echo "${USER}已经存在"
else
useradd $USER -p$PASSWD &> /dev/null
count=$((count+1))
fi
done
fi
echo "共建立了${count}个用户"
#!/bin/bash
read -p "请输入要登陆的用户名:" USER
read -p "请输入登陆密码:" -s PASSWD
mysql -u$USER -p$PASSWD -e "SHOW DATABASES;" &>/dev/null
if [ "$?" != "0" ]
then
echo -e "\n您输入的用户名或密码有误。"
exit
else
mysql -u$USER -p$PASSWD -e "SHOWDATABASES;"
read -p "请输入要备份的数据库:" DBNAME
read -p "请输入要备份的路径(/XXX/XXX.sql):" PP
mysqldump -u$USER -p$PASSWD $DBNAME > $PP
fi
if [ "$?" = "0" ]
then
echo "备份完成。"
else
echo "备份失败。"
fi
**********
ssh.sh:
*********
#!/bin/bash
read -p "Please input ip:" IP
read -p "Please input user:" USER
read -p "Please input password:" PASSWD
ssh $USER@$IP
ssh.exp:
**************
#!/usr/bin/expect
set IP [ lindex $argv 0 ]
set USER [ lindex $argv 1 ]
set PASSWD [ lindex $argv 2 ]
spawn ./ssh.sh
expect {
"continue connecting(yes/no)?"
{ send"yes\n";
exp_continue
}
"ip:"
{ send"$IP\n";
exp_continue
}
"user:"
{
send"$USER\n";
exp_continue
}
"password:"
{ send"$PASSWD\n";
exp_continue
}
expect eof
}
interact
#!/bin/bash
yum install bind -y
systemctl start named
###修改防火墙
firewall-cmd --permanent --add-service=dns
firewall-cmd --reload
rm -fr Kwestos.*
##生成密钥名字为westos
dnssec-keygen -a HMAC-MD5 -b 128 -n HOST westos
KEY=`sed -n 1p Kwestos.*.key | cut -d " " -f 7`
##修改dns配置文件
#############################
sed s/127.0.0.1/any/ /etc/named.conf -i
sed s/localhost/any/ /etc/named.conf -i
cat >> /etc/named.conf <<END
key "westos" {
algorithm hmac-md5;
secret"$KEY";
};
END
###############################
##配置正向解析文件 westoslinux.com.zone
##################################################
cat > /var/named/westoslinux.com.zone <<END
\$TTL 1D
@ IN SOA dns.westoslinux.com. root.westoslinux.com.(
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS dns.westoslinux.com.
dns A 172.25.254.112
www A 172.25.254.222
END
#############################################
##配置named.rfc1912.zones
###############################################
cat >> /etc/named.rfc1912.zones <<END
zone "westoslinux.com" IN {
type master;
file"westoslinux.com.zone";
allow-update { keywestos; };
allow-transfer {172.25.254.212;};
also-notify {172.25.254.212;};
};
END
###############################################
setsebool -P named_write_master_zones 1
chmod 770 /var/named
systemctl restart named
yum install dhcp -y &> /dev/null
##修改dhcp配置文件
###########################################
cat > /etc/dhcp/dhcpd.conf <<END
option domain-name "westoslinux.com";
option domain-name-servers 172.25.254.212;
default-lease-time 600;
max-lease-time 7200;
ddns-update-style interim;
log-facility local7;
subnet 172.25.254.0 netmask 255.255.255.0 {
range 172.25.254.13172.25.254.99;
option routers 172.25.254.212;
}
key westos {
algorithm hmac-md5;
secret "$KEY";
};
zone westoslinux.com. {
primary 127.0.0.1;
key westos;
}
END
###########################################
systemctl restart dhcpd