脚本

##########用户创建的脚本##########

 

#!/bin/bash

if

[ -z "$*" ]

then

          echo "ERROR,Please give userfile and passwdfile"

  exit 1

fi

 

if

[ ! -f /mnt/userfile ] || [ ! -f /mnt/passwdfile ]

then

echo "ERROR,Please check your userfile and passwdfile"

exit 1

fi

 

 MAXLINE1=`wc -l /mnt/userfile | cut -d " " -f 1`

 MAXLINE2=`wc -l /mnt/passwdfile | cut -d " " -f 1`

 

 

if

[ ! "$MAXLINE1" -eq "$MAXLINE2" ]

then

         echo "the two files are not match"

 exit 1

fi

 

 

for NUM in $( seq 1 $MAXLINE1 )

        do

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

                        PASSWORD=`sed -n ${NUM}p /mnt/passwdfile`

                        useradd $USERNAME &>/dev/null

                        echo $PASSWORD | passwd --stdin $USERNAME

done

 

###########ssh脚本####################

#!/usr/bin/expect

set NAME       [ lindex $argv 0 ]

set PASSWD     [ lindex $argv 2 ]

set IPADDR     [ lindex $argv 1 ]

 

spawn ssh $NAME@$IPADDR

 

expect {

"yes/no"    { send "yes\r"; exp_continue }

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

interact

}

#########数据备份############

#!/bin/bash

##database copy

##2017-3-10

 

read -p "need to back all data: " yn

read -p "please input your database passwd : " password

if

[ "$yn" = "y" -o "$yn" = "Y" ]

then

mysqldump -uroot -p$password --all-databases > backup.dump

else

     read -p "Please input need backup database name: " NAME

mysqldump -uroot -p$password $NAME >$NAME.dump

fi

 

#########数据恢复############

#!/bin/bash

#recover database

#2017-3-10

 

read -p "Please input database password : " passwd

read -p "Please input recovered database name: " NAME

 

mysqladmin -uroot -p$passwd create $NAME

read -p "please input your bakcup name : " NAME1

mysql -uroot -p$passwd $NAME < $NAME1.dump

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值