I'm trying to send a Slack notification of a server's IP address on startup. I'm running Ubuntu 18.04. The script works fine when ran from command line (creates a log file & send the Slack message). It's placed at /etc/init.d/iptoslack.sh
, and I've set chmod 755
and run
sudo update-rc.d iptoslack.sh defaults
and added a delay to the script so the internet connection would have time to establish. However, even the log file doesn't get created on boot. Scripts in init.d
shouldn't require login either, right? Can this be a permission issue (aren't init.d
scripts run as root?)
/etc/init.d/iptoslack.sh
:
#!/bin/bash
script()
{
ifconfig > /home/myname/startlog.log
sleep 30 # wait a moment to give the internet connection time to establish
ip="$(ifconfig | sed -n 2p)"
text="Intra server rebooted, ifconfig returned $ip"
curl -X POST -H 'Content-type: application/json' --data "{'text':'$text'}" 'https://hooks.slack.com/services/asdf/qwer/fghj' >> /home/myname/startlog.log
}
script &