Skip to content

Instantly share code, notes, and snippets.

@Luismcplopes
Created February 19, 2019 11:56
Show Gist options
  • Save Luismcplopes/e8272ecb23bfd4f70328838de270a630 to your computer and use it in GitHub Desktop.
Save Luismcplopes/e8272ecb23bfd4f70328838de270a630 to your computer and use it in GitHub Desktop.
#!/bin/bash
########################################
#
# This script notifies slack
# when this machine starts up
#
########################################
#This reads in the webhook URL from a file
#just replace it with you actual webhook URL
slack_url=`cat //usr/bin/slack_url`
start_text="Power is UP "
start_text+="Name : `hostname`"
start_text+="\n Internal-IP : `ip route get 8.8.8.8 | awk '{print $NF; exit}'`"
start_text+="\n External-IP : `curl ifconfig.co` \n"
start_text+="\n [+] for OK : `service --status-all | grep openvpn`"
start_text+="\n [+] for OK : `service --status-all | grep ssh` \n "
start_text+="\n `grep MemTotal /proc/meminfo` \n"
start_text+="\n Espaço nas Drives"
start_text+="\n `df -h | grep /dev/mmc | sed ':a;N;$!ba;s/\n/\\\n/g'`"
start_text+="\n `df -h | grep /dev/sd | sed ':a;N;$!ba;s/\n/\\\n/g'`"
curl -H "Content-type:application/json" \
-X POST -d \
'{
"channel":"#ll-osmc",
"username" : "RaspBerryPi",
"icon_emoji" : ":raspberrypi:",
"attachments" : [
{
"fallback": "OSMC is up and running!",
"color" : "good",
"fields" : [
{
"title" : "OSMC Starting Up!",
"value" : "'"$start_text"'",
"short" : "true"
}
]
}
]
}
' $slack_url
exit 0
@Luismcplopes
Copy link
Author

For this to work it is necessary to create a file slack_url on /usr/bin/ with slack-Hook in it or

sudo bash -c 'cat << EOF > /usr/bin/slack_url
https://hooks.slack.com/services/Your-hook-here
EOF'
sudo chmod +x /usr/bin/slack_url

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment