Linux continuously execute multiple commands

Had previously been using a "shell + expect" combination。

Later in the course of,Expect more and more that this stuff is too far behind,The following reasons:

1. It has stopped issuing new official version;

2. Debug inefficient,In many cases the code to go with the way people think Mom。

then,It was later decided to use a scripting language python all done。

Practice has proved that,python development efficiency is very high,Indeed "rough fast fierce"。

stop,Digress。。。

In my Automation case in,You need to check whether a command is executed successfully (assuming command checklog,Successful return 0,Failure to return 1)。

Under normal circumstances,In the next sentence checklog,Direct "echo $?”,Judgment 0,1To。

but,Because the execution environment of the command prompt, 0 and 1,So pexpect not judge "echo $?"the result of。

later,Wondering wondering,My mind just emerge above knowledge points,I tried it,Fix the problem it is hereby Mark。

# Checklog expect the successful implementation
checklog && echo success
pexpect.expect(‘success’)

# Checklog execution failed expectations
checklog || echo failure
pexpect.expect(‘failure’)

Brush up the knowledge:
1. Command is the semicolon ";"Separated,These commands will be executed sequentially down;
2. Command is "&&"Separated,These commands will be executed sequentially down,Stop command execution encountered an error;
3. Commands are double pipe "||"Separated,These commands will be executed sequentially down,Stop command is successful encounter,All commands will not be executed later;

Comments are closed.