简体   繁体   中英

linux expect command

I am using the linux 'expect' to automate passwords.

#!/usr/bin/expect
set password passwd 
spawn scp * root@ip_address:.
expect "password:" 
send "$password\r" 
expect eof
output :
spawn scp * root@ip_address:. 
root@ip_address's password: *: No such file or directory

Looks like the regular expression '*' is not recognized. I know of the ssh-key gen method to set up keys but 'expect' command is more suitable for my specific case.

* is not a valid regular expression, and in the context you're using it, it would be a wildcard. The spawn will interpret it literally and pass it as an argument to the program you're starting.

If you want the asterisk globbed, you'll have to get a shell to do it for you:

spawn sh -c "scp * root@foo"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM