Skip to content

Instantly share code, notes, and snippets.

@matriphe
matriphe / ssh-telegram.sh
Last active May 7, 2023 15:00
Bash Script to notify via Telegram Bot API when user log in SSH
# save it as /etc/profile.d/ssh-telegram.sh
# use jq to parse JSON from ipinfo.io
# get jq from here http://stedolan.github.io/jq/
USERID="<target_user_id>"
KEY="<bot_private_key>"
TIMEOUT="10"
URL="https://api.telegram.org/bot$KEY/sendMessage"
DATE_EXEC="$(date "+%d %b %Y %H:%M")"
TMPFILE='/tmp/ipinfo-$DATE_EXEC.txt'
if [ -n "$SSH_CLIENT" ]; then
@olegch
olegch / README.md
Created January 24, 2012 16:46
These scripts are used for simple management of hostnames for several VirtualBox VMs comprising a test or sandbox environment on your local machine.

These scripts are used for simple management of hostnames for several VirtualBox VMs comprising a test or sandbox environment on your local machine.

Architecture:

  1. each VM is configured to use bridged network adapter, so all VMs and the host can see each other

  2. a script is installed in each VM to run on post-ifup, which grabs VM's IP, puts "$IP $desired-hostname $desired-fully-qualified-hostname" into /etc/hosts, changes hostname correspondingly, and puts VM's hostname and fq-hostname into VM's properties

  3. a script is used on the host machine, which loops through running VMs, and updates /etc/hosts on the host machine and on the VMs