I am attempting to send a password to a remote server using a bash
script. This worked fine until we were required to change the passwords to more complex passwords and one of the new passwords included a $
character (i.e. P@$sw0rd
).
I have included the snippet that is no longer working:
password="'P@$sw0rd'"
spawn ssh "$deviceType@$device"
expect {
"*no)?" {send "yes\r"}
"*assword:" {send "$password\r"}
"*assword:" {send "$password\r"}
}
Every time it sends the password, the remote system attempts to find the variable $sw0rd
.
I know the problem is with the $
character in the password itself, but is there a way to do this without changing this one password on all of our remote servers to one that does not include the $
character?
I have tried different ways to store the $
character:
password='P@$sw0rd'
password=P@$sw0rd
password="'P@\$sw0rd'"
password="P@\$sw0rd"
password='P@\$sw0rd'
password=P@\$sw0rd
None of these have worked.
Please, help.