Advertisement
dale3h

[Home Assistant] Command Line Utility

Jun 17th, 2016
842
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.35 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # To install, run the following command:
  4. #
  5. # wget http://pastebin.com/raw/CwXh0vfN -O- | tr -d '\r' | sudo tee /usr/local/bin/hassctl > /dev/null && sudo chown pi:pi /usr/local/bin/hassctl && chmod +x /usr/local/bin/hassctl
  6. #
  7. # Now you can control hass using:
  8. #   hassctl start
  9. #   hassctl stop
  10. #   hassctl restart
  11. #   hassctl kill
  12. #   hassctl log -f
  13. #   hassctl error
  14. #   hassctl config
  15. #   hassctl update
  16.  
  17. HASS_SERVICE="home-assistant*"
  18.  
  19. if [ "$1" = "log" ]; then
  20.     clear && sudo journalctl ${@:2} -u "$HASS_SERVICE" | grep --color=always -iP '.*(error|errno|warning|exception|failure|failed|warn|except|fail).*|$'
  21. elif [ "$1" = "error" ]; then
  22.     clear && sudo journalctl ${@:2} --no-pager -f -u "$HASS_SERVICE" | grep --color=always -iP '^--.*--$|^(?!.*Current job from).*(error|errno|warning|exception|failure|failed|warn|except|fail).*'
  23. elif [ "$1" = "kill" ]; then
  24.     ps aux | grep 'python' | grep 'hass' | grep -vE 'grep' | awk '{print $2}' | xargs kill -9
  25. elif [ "$1" = "config" ]; then
  26.     $(which hass) --script check_config
  27. elif [ "$1" = "update" ]; then
  28.     wget -q http://pastebin.com/raw/CwXh0vfN -O- | tr -d '\r' | sudo tee /usr/local/bin/hassctl > /dev/null
  29.     sudo chown pi:pi /usr/local/bin/hassctl
  30.     chmod +x /usr/local/bin/hassctl
  31.     echo "hassctl has been updated."
  32. else
  33.     sudo systemctl $@ "$HASS_SERVICE"
  34. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement