Is there a way to execute an if statement if I see a specific output? For example, when the console says "bad interpreter permission denied" I want to execute a command like "dos2unix file_name"?
So the logic will be like the following,
if (output is "bad interpreter permission denied")
{
send dos2unix file_name
}
fi
This is an expect script.
Edit:
Could I do something like this in an expect script?
if (grep -cim1 '^M$' lruload.sh) -eq 1; then
send dos2unix filename
fi
When you say execute the commands, I hope you meant to execute the command in the shell. You can use exec command for this purpose.
I'm not sure where you are interacting. I mean like telnet or ftp or bash. Anyway, under any case, you will be sending a command and expecting a prompt.
send "command 1"
expect "prompt"
send "command 2"
expect {
timeout { puts "timeout happened"}
"bad interpreter per mission denied" {
set result [exec dos2unix <filename>]
}
}
# if need to intact with three application, further use 'send' and 'expect'
You have the result variable to store the dos2unix output.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With