Dear members, The following expect script connects to remote node and check for the file "authorized_keys" in directory /root/.ssh in remote node. However the result is always found even if the file exist or doesn't exist.
expect {
"$fname" {
send_user "found\n"
}
Any idea what is causing this issue and how to fix it please ?
Note how we need to do one expect for "YES\r" first to capture the echo back from the sent string. The second expect is looking for any output from the command. You could also do this with one expect looking for "YES\r\nYES"
Thanks for your input. I tried your suggested code to check the presence of file and I can see the remote node throwing the following error and appears that usage "-f" option to check filename has got issues in send command.
invalid command name "-f"
while executing
"-f "
invoked from within
"send "[ -f ] && echo YES\r""
My recollection is that TCL does command substitution when it encounters [ ... ] so perhaps a test command needs to be used within the brackets (which may look very strange to shell scriptors).