Skip to content

Instantly share code, notes, and snippets.

@eins78
Created May 25, 2012 11:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eins78/2787610 to your computer and use it in GitHub Desktop.
Save eins78/2787610 to your computer and use it in GitHub Desktop.
Shell Script: Check if the Maschinenraum is Closed
#!/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
@padde
Copy link

padde commented Jul 14, 2012

Wie wär's mit if/else?

if curl -silent twitter.com/users/show/mr_door_status.json | grep "offen" &>/dev/null
then
  echo "MR is open"
else
  echo "MR is closed"
fi

One-liner:

if curl -silent twitter.com/users/show/mr_door_status.json | grep "offen" &>/dev/null; then echo "MR is open"; else echo "MR is closed"; fi

bzw. mit exit

if curl -silent twitter.com/users/show/mr_door_status.json | grep "offen" &>/dev/null
then
  echo "MR is open"
  exit 1
else
  echo "MR is closed"
  exit 0
fi

One-liner:

if curl -silent twitter.com/users/show/mr_door_status.json | grep "offen" &>/dev/null; then echo "MR is open"; exit 1; else echo "MR is closed"; exit 0; fi

@eins78
Copy link
Author

eins78 commented Jul 14, 2012

&& und || ist doch if/else, oder etwa nicht?

@padde
Copy link

padde commented Jul 14, 2012

Schon, lässt sich aber nicht so gut lesen ;)

@eins78
Copy link
Author

eins78 commented Jul 14, 2012

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 :)

@padde
Copy link

padde commented Jul 14, 2012

warum eigentlich grep "der maschinenraum ist offen No" und nicht grep "offen"? Hat das eine bestimmte Bewandtnis? :)

@eins78
Copy link
Author

eins78 commented Jul 14, 2012

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