我正在寻找任何方式来执行此任务:
Mac-mini:~ root# scp file peter@Mac-mini:file2
The authenticity of host 'mac-mini (192.168.1.105)' can't be established.
RSA key fingerprint is b6:12:3e:48:10:e6:d2:1f:8f:57:f4:01:2d:f3:23:89.
Are you sure you want to continue connecting (yes/no)? yes
Password: ********
并发出
crontab -l > crontab.src
答案 0 :(得分:0)
#!/usr/bin/expect
set machine0 "Mac-minimini"
set machine1 "Mac-mini"
set machine2 "Mac-pro"
...
set machine19 "Mac-air"
for {set i 1} {$i < 20} {incr i 1} {
eval spawn scp file peter@${machine${i}}:file2
expect "connecting (yes/no)?"
send "yes\r"
#use correct prompt
set prompt ":|#|\\\$"
interact -o -nobuffer -re $prompt return
send "password\r"
interact -o -nobuffer -re $prompt return
send "crontab -l > crontab.src\r"
interact
}
编辑:您可以使用循环变量为每台机器使用for循环和连接名称(例如Mac-mini0,Mac-mini1,... Mac-mini19)
Edit2:我不确定$ {machine $ {i}}是否有效但值得尝试..
答案 1 :(得分:0)
设置一个像这样的ssh键:
ssh-keygen -t rsa
将您的公钥放在远程计算机上(假设您在主目录中创建了一个名为id_rsa的密钥)
ssh-copy-id peter@Mac-mini
然后你就可以在不输入密码的情况下scp了。
autoexpect -f scp file peter@Mac-mini:file2
对于crontab部分,假设您在远程计算机上的意思。
autoexpect -f crontab ssh peter@Mac-mini "crontab -l > crontab.src"