I'm trying to run an expect script that SSHs to another local device to install and run a python script. All variables are defined outside of the script:
set prompt "$SSHuser@$SSHname:~$"
spawn ssh -o \"StrictHostKeyChecking no\" $SSHuser@$SSHhost
expect
{
"*assword"
{
send "$SSHpassword\r"
exp_continue
}
"$prompt"
{
send "sudo su"
expect
{
"*assword"
{
send "$SSHpassword\r"
exp_continue
}
"$prompt"
{
send "apt update && apt upgrade -y && apt install net-tools -y && apt install python3-pip -y"
expect "$prompt"
{
send "wget -O script.py https://SOMEURL"
}
}
}
}
}
However, I keep getting the following output/error:
missing close-brace
while executing
"{"
couldn't read file "sur
expect
{
*assword
{
send REDACTEDPASSWORD
exp_continue
}
{
send -- apt": no such file or directory
spawn ssh -o StrictHostKeyChecking no USERNAME@192.168.1.173
USERNAME@192.168.1.173's password:
I have counted the brackets and used highlighting tools and I do not see any missing brackets. I also do not understand why it keeps reading "send "sudo su\r" as "sur". My exposure to expect is still pretty limited. I would really appreciate any help in understanding what has gone wrong here.