Conditionals

Intercom can execute commands conditionally based on the exit-code of a shell command. This is done with the if command. It borrows much of its syntax from shell though it is much more limited. The syntax of if is as follows.

if <shell-command> <intercom-command> [else <else-command>]

The if command will execute <intercom-command> if the exit status of <shell-command> is 0; otherwise, <else-command> is executed.

Note

The else clause in an if command can be omitted.

If can further be extended to check for a specific exit-code using operators such as =, <, and >. These will test the exit-code against the value specified. The valid operators are = (equal to), != (not equal), < (less than), > (greater than), <= (less than or equal to), and >= (greater or equal to). For example, to execute the hangup command if the exit-code of testprog.sh was greater than 1, you would enter the following.

intercom: If testprog.sh '>' 1 hangup