Security

One-liner to mail when someone logs in as root

This is a short post describing how to automatically send an email every time someone logs in as root on a linux server. Add the following line to /root/.bash_profile if you are using bash as your default shell interpreter. Refer to /etc/passwd. (echo “Subject: ALERT: servername Root Shell Access from `who | awk ‘{print $5}’`”; […]

Read More
Misc

IP address change notifier script

This is a simple bash script that is run by crontab every 5 minutes on a linux box. It e-mails me the new address when a change of IP address is detected. The script (ipchangemail.sh) #!/bin/bash # Check if IP-address has changed. If a change has occured, mail me the new address # Add the […]

Read More
Scripting

Execute commands on multiple hosts using ssh

#!/bin/bash # Linux/UNIX box with ssh key based login SERVERS=”192.168.1.1 192.168.1.2 192.168.1.3″ # SSH User name USR=”jadmin” # Email SUBJECT=”Server user login report” EMAIL=”admin@somewhere.com” EMAILMESSAGE=”/tmp/emailmessage.txt” # create new file >$EMAILMESSAGE # connect each host and pull up user listing for host in $SERVERS do echo “——————————–” >>$EMAILMESSAGE echo “* HOST: $host ” >>$EMAILMESSAGE echo “——————————–” […]

Read More