开发调试ssh远程或者scp拷贝到远程,每次收到操作比较麻烦,写个自动脚本
#/bin/bash
user='root'
port=22
host='192.168.100.25'
psaaword='123456'
host_next=''
path='/root/hslong'
path_next='/opt/bin'
#0:终端默认设置 1:高亮显示 4:使用下划线 5:闪烁 7:反白显示 8:不可见
RED="echo -en \\E[4;31m"
GREEN="echo -en \\E[7;32m"
YELLOW="echo -en \\E[1;33m"
RESET="echo -en \\E[0;39m"
case $1 in
test1|test2)
host_next='192.168.160.4'
;;
test3|test4)
host_next='192.168.160.5'
;;
*)
$RED && echo "Usage: $0 {server name} SER_NAME" && $RESET
;;
esac
echo "Test server: $1 --> $host_next"
if [ ! -f "$1" ]; then
echo "Not fin $1"
exit
fi
$YELLOW && echo "rm $1 by $host" && $RESET
sshpass -p $psaaword ssh -p $port $user@$host "cd $path && rm $1"
$YELLOW && echo "scp $1 to $host" && $RESET
sshpass -p $psaaword scp -P $port $1 $user@$host:$path
sshpass -p $psaaword ssh -p $port $user@$host "cd $path && ls $1 -hal"
$YELLOW && echo "rm $1 to $host_next" && $RESET
sshpass -p $psaaword ssh -p $port $user@$host "ssh $host_next 'cd $path_next && pwd && ls $1 -hal && rm $1'"
$YELLOW && echo "scp $1 to $host_next" && $RESET
sshpass -p $psaaword ssh -p $port $user@$host "cd $path && scp $1 $user@$host_next:$path_next"
$YELLOW && echo "pkill $1" && $RESET
sshpass -p $psaaword ssh -p $port $user@$host "ssh $host_next 'cd $path_next && ls $1 -hal && ps -ef | grep $1 && pkill $1'"
$YELLOW && echo "start $1" && $RESET
sshpass -p $psaaword ssh -p $port $user@$host "ssh $host_next 'cd $path_next && /opt/bin/$1 && ps -ef | grep $1'"