mysql的导出数据库的自动化脚本中怎么实现免人工输入密码
1个回答
2017-01-02 · 做真实的自己 用良心做教育
千锋教育
千锋教育专注HTML5大前端、JavaEE、Python、人工智能、UI&UE、云计算、全栈软件测试、大数据、物联网+嵌入式、Unity游戏开发、网络安全、互联网营销、Go语言等培训教育。
向TA提问
关注
展开全部
同步数据库自动化脚本
#!/bin/sh
read -p "Please keyin your ssh host:" -t 30 host_ipread -p "Please keyin your ssh user:" -t 30 usernameread -p "Please keyin your ssh pass:" -t 30 passwordread -p "Please keyin your sync table list,separated by spaces:" -t 30 table_listdatetime=`date +%Y%m%d%H%M%S`
src_file="/tmp/data_$datetime.sql"
tar_file="/tmp/data_$datetime.tar.gz"
mysqldump -h127.0.0.1 -uroot -ppass database_name $table_list > $src_filetar czvf $tar_file $src_file
./expect_scp.sh $host_ip $username $password $tar_fileexpect_scp.sh代码
#!/tools/bin/expect
set timeout 10
set host [lindex $argv 0]
set username [lindex $argv 1]
set password [lindex $argv 2]
set src_file [lindex $argv 3]
#set dest_file [lindex $argv 4]
spawn scp $src_file $username@$host:/home/$usernameexpect {
"(yes/no)?"
{
send "yes\n"
expect "*assword:" { send "$password\n"}
}
"*assword:"
{
send "$password\n"
}
}
expect "100%"
expect eof
#!/bin/sh
read -p "Please keyin your ssh host:" -t 30 host_ipread -p "Please keyin your ssh user:" -t 30 usernameread -p "Please keyin your ssh pass:" -t 30 passwordread -p "Please keyin your sync table list,separated by spaces:" -t 30 table_listdatetime=`date +%Y%m%d%H%M%S`
src_file="/tmp/data_$datetime.sql"
tar_file="/tmp/data_$datetime.tar.gz"
mysqldump -h127.0.0.1 -uroot -ppass database_name $table_list > $src_filetar czvf $tar_file $src_file
./expect_scp.sh $host_ip $username $password $tar_fileexpect_scp.sh代码
#!/tools/bin/expect
set timeout 10
set host [lindex $argv 0]
set username [lindex $argv 1]
set password [lindex $argv 2]
set src_file [lindex $argv 3]
#set dest_file [lindex $argv 4]
spawn scp $src_file $username@$host:/home/$usernameexpect {
"(yes/no)?"
{
send "yes\n"
expect "*assword:" { send "$password\n"}
}
"*assword:"
{
send "$password\n"
}
}
expect "100%"
expect eof
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |