Executing if statement after certain output while waiting for script

Is there a way to execute an if statement if I see specific output? For example, when the console says "bad interpreter denied" permission, I want to run a command like "dos2unix filename"? So the logic would look like this:

if (output is "bad interpreter permission denied")
{
  send dos2unix file_name
}
fi

      

A script is expected.

Edit:

Hi guys, can I do something like this while waiting for the script?

if (grep -cim1 '^M$' lruload.sh) -eq 1; then
send dos2unix filename
fi

      

+3


source to share


2 answers


How about this logic / psuedo code?

export cmdText=`myCmd param1 param2 2>&1`
if ($cmdText is "bad interpreter permission denied")
{
    send dos2unix file_name
}
fi

      



The allowed text rejection is probably sent to stderr, not stdout, so the 2> and 1 redirection concatenates them together, making a simple test.

0


source


When you say you are executing commands, I hope you meant to execute the command in a shell. You can use the command for this purpose exec

.

I'm not sure where you are interacting. I mean telnet or ftp or bash. In any case, in any case, you will send a team and wait for an invitation.



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 a variable result

to store the output dos2unix

.

0


source







All Articles