This page looks best with JavaScript enabled

Running a script on FreeBSD startup

 ·  🎃 kr0m

When providing technical support to non-technical people, it can be frustrating. Any simple action such as checking a website to see the WAN IP address can become a titanic task. In these cases, it is better to leave the Ssh access prepared and run a script on system startup to send us the WAN IP address via Telegram. This way we will be self-sufficient.

The script in question is as follows:

vi /root/.scripts/wanIp

#!/usr/local/bin/bash
function sendTelegram {
  /usr/local/bin/curl -s -X POST https://api.telegram.org/botTOKEN/sendMessage -d chat_id=CHAT_ID -d text="$1"
}

wanIp=$(/usr/local/bin/curl -4 icanhazip.com)
sendTelegram "$HOSTNAME WanIp: $wanIp"

The task to be crontabbed will be the following, as a note, we sleep for 30s to ensure that the network is ready when the script is executed:

crontab -e

@reboot /bin/sleep 30 && /root/.scripts/wanIp >/dev/null 2>&1

Now every time the computer restarts, we will receive a Telegram with the WAN IP address.

If you liked the article, you can treat me to a RedBull here