shell - Expect command asks for password again in Linux -
shell - Expect command asks for password again in Linux -
i new linux shell scripting.i need execute shell script gets username, password, host-name, command-to-be-executed 1,2,3,4 parameters respectively. used expect command prompts password again.the main theme of script execute command remote server. password security issues not problem. main issue must not prompted password input. have run 80 servers, cant provide password each , every time. please help me solving this.
my script:
echo username = $1 echo password = $2 echo host-name = $3 echo command executed = $4 expect -c "spawn ssh -ostricthostkeychecking=no -ocheckhostip=no $1@$3 $4; expect \"*assword:*\"; send "$2"; interact #expect eof "
my output:
username = root password = root@123 host-name = host-name command executed = ls spawn ssh -ostricthostkeychecking=no -ocheckhostip=no root@host-name ls root@host-name's password: ~
first index start @ 0 not 1 username = $0
also need set variables so: (this expect script utilize on sever hundred nodes)
#!/usr/bin/expect set user [lindex $argv 0] set password [lindex $argv 2] set ip [lindex $argv 2] set command [lindex $argv 3] spawn ssh -o stricthostkeychecking=no "$user\@$ip" expect "assword:" send "$password\r"; expect "$ " send "$command\r" expect "$ " send "exit\r"
linux shell redhat
Comments
Post a Comment