I expect the script that I need to log in to the remote system and execute the commands. This script works except for providing a root account password. The root password contains a dollar sign, which I can't seem to work. Here is the code
#!/usr/bin/expect set timeout 3 set username "root" set password "Pas$word" set hostname [lindex $argv 0] log_user 0 send_user "\n#####\n# $hostname\n#####\n" spawn ssh -q -o StrictHostKeyChecking=no $username@ $hostname expect { timeout { send_user "\nFailed to get password prompt\n"; exit 1 } eof { send_user "\nSSH failure for $hostname\n"; exit 1 } "*assword" } send "$password\r" expect { timeout { send_user "\nLogin failed. Password incorrect.\n"; exit 1} "*\$ " } send_user "\nPassword is correct\n" expect "$ " { send "ls" }
I confirmed that this works when providing credentials whose passwords do not contain a dollar sign, but I cannot get it to work with the root account. It always throws a Login failed. Password incorrect timeout error Login failed. Password incorrect Login failed. Password incorrect . Changing a password is not an option. I tried to provide the escape character \ in the password definition like this:
set password "Pas\$word"
And I get the same results ... any ideas on what I am doing wrong?
thanks
EDIT Like I said. I already tried to escape the $ character. But for clarification, I added a print statement for the password when the script runs to check that the variable contains the password correctly ... Here is the change:
set password "Pas\$word" ... send_user "\n#####\n# $hostname\n#####\n" send_user "Using password: $password\n" ...
Here is the console output:
njozwiak@ubuntu :~$ ./ssh_ls.sh 192.168.5.93
source share