Created
May 25, 2012 11:59
-
-
Save eins78/2787610 to your computer and use it in GitHub Desktop.
Shell Script: Check if the Maschinenraum is Closed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# script to get open/closed status of MR | |
## use manually: $ sh mr-closed.sh | |
## use in scripts: ./mr-closed.sh && ./do_this_when_closed.sh || ./do_this_when_open.sh | |
# logic | |
## 1. `curl` latest tweet from @MR_door_status | |
## 2. `grep` for 'MR is open' | |
## 3a. if MR is open, echo it and exit 1 | |
## 3b. if MR is closed, echo it and exit 0 | |
if curl -silent twitter.com/users/show/mr_door_status.json | grep "der maschinenraum ist offen No" &>/dev/null; then echo "MR is open"; exit 1; else echo "MR is closed"; exit 0; fi |
&& und || ist doch if/else, oder etwa nicht?
Schon, lässt sich aber nicht so gut lesen ;)
da hatter recht. Habs mal geändert, portabilität von scripts ist wichtig, und ausser an shells sollte man da auch an die menschen denken :)
warum eigentlich grep "der maschinenraum ist offen No"
und nicht grep "offen"
? Hat das eine bestimmte Bewandtnis? :)
ja, der text kommt ja eh auch aus der Maschine und wird deswegen sicherheitshalber so gegrept. das 'No' ist drin weil hinten immer ne zufallszahl drankommt, wiederum damit twitter nicht denkt wir spammen.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Wie wär's mit
if
/else
?One-liner:
bzw. mit
exit
One-liner: