第一種:
ftp -v -n 192.168.0.1 21 <<!
user ftp ftp123
bay
!
第二種:
{ echo -e "\n" echo -e "ifconfig" }| telnet 0 1234
第三種:
ssh 192.168.0.2 '/etc/init.d/httpd start'
第一種方式最麻煩,比較喜歡第二種,第三種方式最簡單,你覺得呢?
如果覺得好就收藏吧! 如果還有其他方式,請留言告訴我,謝謝。
第四種:
#!/usr/bin/expect -f set port 22 set user root set host 192.168.0.1 set password root spawn ssh -D $port $user@$host
#root@192.168.0.1's password: expect "*assword:*" send "$password\n" spawn ifconfig interact expect eof
send:用於向進程發送字符串
expect:從進程接收字符串
spawn:啟動新的進程
interact:允許用戶交互
第四種交互方式怎么樣?如何從服務器A上ssh到服務器B上,然后執行服務器B上的命令?聽起來是不是很海派呢!
案例:(獲取服務器Bifconfig保存文件,scp到服務器A)
#!/usr/bin/expect -f set port 22 set user root set host 192.168.1.2 set password root set timeout -1 spawn ssh $user@$host expect { "*yes/no" { send "yes\r"; exp_continue} "*assword:" { send "$password\r" } } expect "*#*" send "ifconfig > /home/cfg \r" send "exit\r" interact spawn scp $host:/home/cfg ./ expect { "*yes/no" { send "yes\r"; exp_continue} "*assword:" { send "$password\r" } } expect eof
第五種:
sshpass -p root ssh 192.168.48.73 "w"
但需要安裝sshpass
下載:sshpass-1.05.tar.gz
百度去吧。