0

i wrote an expect script to ssh remotely to multiple linux boxes and running this command chmod -R o-w /etc/ But i am getting an error expect: invalid option -- 'R'

Please find the script below

#!/bin/bash
username=$1
userpass=$2
rootpass=$3
cat server_list | while read host
do
expect -c "
set timeout 5
spawn ssh -o StrictHostKeyChecking=no -tq ${username}@${host} sudo su - root
expect "ssword" { send "${userpass}r" }
expect "ssword" { send "{rootpass}r" }
expect "#"
send "chmod -R o-w /etc"
expect "#" { send "exitr" }
expect eof"
done

i am running the script like this

./test1.sh test test@123 test@123

Kindly help

catchvenki
  • 35
  • 6
  • 1
    Your quoting is not consistent. Try to avoid using double quotes inside the expect command that is itself in double quotes. Not sure if this is the only issue here. – Dima Chubarov Mar 16 '17 at 05:45

1 Answers1

0

Use "--" flags in the send command which will force the next argument to be read as string.

send -- "chmod -R o-w /etc"

Read more in Expect manpage

Ashish
  • 266
  • 2
  • 9
  • hi ashish please find the output expect: invalid option -- 'R' issue is chmod is a linux command. seems like expect is trying to run it as an expect command – catchvenki Mar 16 '17 at 05:36