autorun bash commands upon ssh login
This is to be set up on the machine that you are connecting to.
Edit ~/.bashrc (or /etc/bash.bashrc if you want this to affect all users who login over ssh instead of just yourself).
I added the following code to the end my .bashrc file on my server to test if it’s an ssh connection, and if it is, to run the toilet command and screenfetch command upon login. The echos are for formatting and not necessary.
#autorun on ssh login if [[ -n $SSH_CONNECTION ]] ; then sleep 2 echo toilet -f slant -t Titan Server echo screenfetch echo echo checking wireless connection... sleep .4 nmcli dev wifi | grep \* echo echo checking on bind service for local dns... sleep .4 systemctl status bind9 | grep active echo checking on dynamic dns service to update dynu.com with this server\'s network\'s public ip address... sleep .4 systemctl status dynuiuc | grep active echo echo checking that rum and redacted domains point to the public ip address that this server uses via dynamic dns... sleep .4 host rum.redacted.tk echo echo checking if local mediawiki backups are syncing with cloud backups, identical = yes, differ = no... sleep .4 diff -s -q <(ls /var/lib/automysqlbackup/daily/wikidb) <(ls ~/pCloudDrive/Titan\ Server/Mediawiki\ Backup/mysql\ database/daily/wikidb/) | grep 'identical\|differ' echo echo checking hard drive space... sleep .4 df -h echo echo To edit what runs automatically upon ssh login, edit the '~/.bashrc' file and echo scroll to the bottom. Once you are finished and have saved your changes, view echo how they will look in terminal by running '. ~/.bashrc' echo fi
That will display the following in the terminal every time I successfully connect to the server over ssh
- running ‘. .bashrc’ from the home directory prompts the script to run if you want to do it manually vs reconnecting over ssh every time to see how yours looks
┌─[feoleb@titan]─[~] └──╼ $. .bashrc _______ __ _____ /_ __(_) /_____ _____ / ___/___ ______ _____ _____ / / / / __/ __ `/ __ \ \__ \/ _ \/ ___/ | / / _ \/ ___/ / / / / /_/ /_/ / / / / ___/ / __/ / | |/ / __/ / /_/ /_/\__/\__,_/_/ /_/ /____/\___/_/ |___/\___/_/
./+o+- feoleb@titan yyyyy- -yyyyyy+ OS: Ubuntu 16.04 xenial ://+//////-yyyyyyo Kernel: x86_64 Linux 4.15.0-45-generic .++ .:/++++++/-.+sss/` Uptime: 4h 42m .:++o: /++++++++/:--:/- Packages: 2270 o:+o+:++.`..```.-/oo+++++/ Shell: bash 4.3.48 .:+o:+o/. `+sssoo+/ CPU: AMD Phenom II X2 555 @ 3.2GHz .++/+:+oo+o:` /sssooo. GPU: AMD/ATI RS880 [Radeon HD 4200] /+++//+:`oo+o /::--:. RAM: 1000MiB / 3437MiB \+/+o+++`o++o ++////. .++.o+++oo+:` /dddhhh. .+.o+oo:. `oddhhhh+ \+.++o+o``-````.:ohdhhhhh+ `:o+++ `ohhhhhhhhyo++os: .o:`.syhhhhhhh/.oo++o` /osyyyyyyo++ooo+++/ ````` +oo+++o\: `oo++. checking wireless connection... * SSID MODE CHAN RATE SIGNAL BARS SECURITY * Sewing Room 5G Infra 36 54 Mbit/s 68 ▂▄▆_ WPA1 WPA2 checking on bind service for local dns... Active: active (running) since Mon 2019-03-04 12:04:35 EST; 4h 42min ago checking on dynamic dns service to update dynu.com with this server's network's public ip address... Active: active (running) since Mon 2019-03-04 12:04:31 EST; 4h 42min ago checking that rum and redacted domains point to the public ip address that this server uses via dynamic dns... rum.redacted.tk is an alias for redacted.dynu.net. redacted.dynu.net has address 555.20.180.169 checking if local mediawiki backups are syncing with cloud backups, identical = yes, differ = no... Files /dev/fd/63 and /dev/fd/62 are identical checking hard drive space... Filesystem Size Used Avail Use% Mounted on udev 1.7G 0 1.7G 0% /dev tmpfs 344M 5.9M 338M 2% /run /dev/sda1 231G 6.9G 213G 4% / tmpfs 1.7G 696K 1.7G 1% /dev/shm tmpfs 5.0M 4.0K 5.0M 1% /run/lock tmpfs 1.7G 0 1.7G 0% /sys/fs/cgroup tmpfs 344M 56K 344M 1% /run/user/1000 pCloud.fs 7.0G 605M 6.5G 9% /home/feoleb/pCloudDrive To edit what runs automatically upon ssh login, edit the ~/.bashrc file and scroll to the bottom. Once you are finished and have saved your changes, view how they will look in terminal by running . ~/.bashrc