1.腳本名稱demo.shdocker
#!/bin/bashshell
yum -y install expectapi
expect -c "bash
spawn scp -r /Users/yunshuodeng/Work/mydocker/app/provider/power-dubbo-provider-1.0-SNAPSHOT.jar root@192.168.2.248:$1app
expect {ssh
\"*assword\" ide
{spa
set timeout 300; it
send \"hntx123456\r\";class
}
\"yes/no\"
{
send \"yes\r\"; exp_continue;}
}
expect eof"
expect -c "
spawn scp -r /Users/yunshuodeng/Work/mydocker/app/consumer/power-dubbo-consumer-1.0-SNAPSHOT.jar root@192.168.2.248:$1
expect {
\"*assword\"
{
set timeout 300;
send \"hntx123456\r\";
}
\"yes/no\"
{
send \"yes\r\"; exp_continue;}
}
expect eof"
expect -c "
spawn scp -r /Users/yunshuodeng/Work/mydocker/app/consumer/power-dubbo-api-1.0-SNAPSHOT.jar root@192.168.2.248:$1
expect {
\"*assword\"
{
set timeout 300;
send \"hntx123456\r\";
}
\"yes/no\"
{
send \"yes\r\"; exp_continue;}
}
expect eof"
expect -c "
spawn ssh root@192.168.2.248
expect {
\"*assword\"
{
set timeout 300;
send \"密碼\r\";
}
\"yes/no\"
{
send \"yes\r\"; exp_continue;
}
}
expect \"*#\"
send \"cd $1\r\"
expect \"*#\"
send \"./$2\r\"
expect \"*#\"
send \"exit\r\"
expect eof"
echo "success"
2.執行shell
./demo.sh /home/demo mymkdir.sh