Thursday, July 23, 2015

Get notified when your linux server boots.

Getting notified of things is great, and when one of your servers boots up, it's always good to know when. With that in mind, it's easy to add this feature to most any Linux or BSD server without much trouble, especially since I've already done the work for you :)

Here's an example message, from one of my servers:
Box has booted! 
System information: 
Date and time: 
Thu Jul  9 20:43:49 EDT 2015 
Uptime (length of boot): 
20:43:49 up 1 min,  0 users,  load average: 2.94, 0.98, 0.35 
Network addresses:  
Server disk usage: 
Filesystem                  Size  Used Avail Use%   
Mounted on/dev/mapper/Box--vg-root  1.8T  1.5T  266G  85% /

By pasting my Boot Notification Script into your /etc/rc.local, you can use your local mail server to send boot notifications with useful statistics whenever your system comes up, with minimal and straightforward configuration.

Note that this script requires a functioning mail server to be running on the system (such as Postfix), as well as the mailx utility, which can be installed from the mailutils or bsd-mailx packages. In a future post, I'll explain how you can easily send mail via postfix using Gmail as a relay, while also keeping your domain name intact.

For inital setup, which will produce the message shown above, you only have to set 2 variables, EMAIL and LANIFACE. There is a third variable, HOST, which is automatically set using the machine's hostname.

EMAIL should contain the email address to which messages should be sent. If you like, you can add multiple addresses, separated by commas. This can be any email address, including your phone's if you'd like to get notifications via SMS.

The second is HOST. This is set automatically from the machines hostname and requires no manual configuration.

The third is LANIFACE, which is the network interface that the LAN IP should be retrieved from. Usually, this is eth0, but it changes depending on your OS. You can run the command ip link show to get a list of your available network interfaces, if you're unsure.


On some systems, /sbin/ifconfig is not installed. This command is usually replaced with /sbin/ip, with addresses shown using the command "ip addr". 
Should this be the case, replace the code on line 52 with the following:
`/bin/ip addr | /bin/grep inet | /usr/bin/tail -n 2 | /usr/bin/head -n 1` 
Which should produce something along the lines of:
inet brd scope global eth0

Monday, July 6, 2015

Banepost.c: Easy Baneposting for the Linux Enthusiast

Have you ever been browsing your favorite online forum or social media website, when suddenly, you see the perfect opportunity to make a reference to your absolute favorite meme? 

Have you ever proceeded to throw your hands up in anguish when you suddenly realized that, nowhere in your extensive collection of images, copypasta, and everything in between, could you find that one, perfect ASCII banepost that would have made the perfect reply? 

Well then I've got the perfect software for you. 
I've tried countless other programs, but none of them flied so well, and some of them even crashed my computer, with no survivors! 

Ultimately, I became so distraught by the lack of free, open source software to solve this problem that I decided to create my own implementation of everyone's favorite Big Guy, Banepost.c, which I guarantee is better than any competing version (at least it can talk). 

It didn't matter who I was, what mattered was my plan, and that was to start a fire in the open source copypasta community that would not only tell you about Bane, but also why he wore the mask. If this were some grand crime, then getting caught is most certainly a part of my plan, and I wasn't alone in this effort. 

There are many eager young developers in the OSS with a fire in their hearts which rises as they find themselves Completely In Agreement with this effort, and that will undoubtedly lead them to create their own, high quality copypasta generating software.