I have this script to check if a file exists. The first "if" statement just makes sure that the file was entered in the command line. That works fine. Where it fails is the next step. I call the "ls" command just to find the file. That works if the file was there. It would show this:
# expect pass_manager.exp /etc/hosts
/etc/hosts
Now when I put a file that doesn't exist into the command line, I'm expecting to see the "does not exist" line to show. But I only get this:
# expect pass_manager.exp hosts
ls: cannot access hosts: No such file or directory
Is there something that I'm missing? What I'm really looking for is a way to expect script a way to check if a file exists. And there are not many good tutorials out there that I can find.
Code:
set hostFile [lindex $argv 0]
if {$hostFile == ""} {
send_user "Usage: expect pass_manager \[FILE\]\n"
send_user " \[FILE\] file containing list of hosts\n"
exit
}
set timeout 3
spawn -noecho ls $hostFile
expect {
"No such file or directory" {
send "does not exist\n"
}
}