I want to execute a script remotely with expect and a for loop:
#!/usr/bin/expect
set timeout 10
spawn ssh [email protected]
expect "password: "
send "pass\n"
expect "$ "
send "for i in `ls` ;\n"
send "do\n"
send " STRLENGTH=$(echo -n $i | wc -m);\n"
send " if [ $STRLENGTH -ge 35 ];\n"
send " then echo ok \"$i\";\n"
send " fi\n"
send "done\n"
But it gives me this error:
can't read "i": no such variable
while executing
"send " STRLENGTH=$(echo -n $i | wc -m);\n""
(file "./script.sh" line 10)
Any help is appreciated, thanks!