#!/bin/bash
#Yuan Scott Yang version 1.0
#use sshpass transfer file or directory to another host
#需要登陆远程服务器的linux account 的密码
password=$1
#需要登陆远程服务器的ssh服务宽口
ssh_port=$2
#需要登陆远程服务器的linux account 的名称
linux_account=$3
#需要登陆远程服务器的ip地址或FQDN
host_name=$4
#使用ssh登录远程服务器,并在$linux_account用户的 "~/.ssh/known_hosts" 加入当前机器的地址,皮面以后登录该远程服务器 还要 进行 密钥询问“yes”,“no”
password_verify=`nohup sshpass -p $password ssh -p $ssh_port $linux_account@$host_name -o StrictHostKeychecking=no >/dev/null 2>&1 &`
$password_verify
if [ $# -eq 4 ];
then
$password_verify
if [ $? -eq 0 ];
then
echo "verify password success!"
if [ -d /root/oracle_script ]
then
#使用scp传递文件
nohup sshpass -p $password scp -P $ssh_port -r /root/oracle_script $linux_account@$host_name:/home/oracle >/dev/null 2>&1 &
echo "the script has transfer success!"
#建立ssh 互信
nohup sshpass -p $password ssh-copy-id -i ~/.ssh/id_rsa.pub -p $ssh_port $linux_account@$host_name >/dev/null 2>&1 &
#这个休眠对程序很关键,主要作用处理ssh互信的时差问题。休眠0.5秒。
sleep 0.5
echo "the ssh has connect success!"
else
echo "transfer failed!please connect Administrator to upload oracle_script file to servers."
exit
fi
else
echo "verify password failed!"
exit
fi
else
echo "please execute this script. eg: $0 password ssh_port linux_account host_name "
exit 0
fi
#这个休眠对程序很关键,主要作用处理ssh互信的时差问题。休眠0.5秒。
sleep 0.5
sshpass_免密码提示_ssh互信_scp脚本
最新推荐文章于 2024-05-14 23:37:46 发布