Today's Linux article has two purposes: 1) To add a little spice to your boring old email signature, and to help you understand a bit about bash scripting. The goal is to be able to create a pseudo-dynamic email signature that adds the uptime of your Linux box and/or the output of the fortune command. With this you can get creative and make your email signature as unique as you like.
In order for the bash script we will create to work, a single application will have to be installed and the users' crontab will have to be edited. These are simple tasks and the end result is sure to raise your "geek cred". No, this will not make your systems run more efficiently, your code compile perfectly, or your breath smell deliciously. But hopefully you will learn something and impress your friends and family with your trickery.
What to install
It used to be Linux distributions would ship with the Fortune application. That is no longer the case. You will have to install Fortune in order to take advantage of this simple little app. But what does it do? All Fortune does is print a random adage from stored flat-files found in /usr/share/games/fortune. You can add to these files by opening them up and editing them. But first you have to install the application. Since we are going to be dealing with the command line (for bash scripting), let's install from command. Open up a terminal window and issue the following command:
sudo apt-get install fortune
And fortune will be installed.
Let's now test the commands we will be using. From your terminal prompt issue the command:
and you should see something like:
11:13:45 up 225 day(s), 3 users, load average 0.07, 0.07, 0.02
Now let's take Fortune out for a test. Issue the command:
and you should see something like:
Cheer Up! Things are getting worse at a slower rate.
For this script we are going to take advantage of the echo command and we will write to the ~/.sig file, which will then be used for the signature file in your email client. The basic script looks like:
echo 'jack wallen' >> ~/.sig
echo `$fortune` >> ~/.sig
echo 'uptime:' `uptime` >> ~/.sig
NOTE: There are two different "quotes". The first is the single quote in the fourth line. The second is the back-tick in the fifth and sixth lines. These back-ticks are necessary to indicate a command is in use.
This script does the following:
Create this file (you'll want to personalize the echo 'jack wallen' >> ~/.sig line of course) and save it in a convenient directory. You will then need to give this file executable permission, so issue the following command:
chmod u+x FILENAME
Where FILENAME is the name of the script.
Now we need to create a cron job that will run the script so that the file isn't static. Open up your crontab editor with the command:
and add a line like:
* * * * * /path/to/script
Where /path/to/script is the explicit path to your script you created.
Every email client will be configured differently. But basically all you need to do is go to the signature preferences section and configure your client to use ~/.sig as the file for your email signature. Now every minute that file will be different and your signature will be "dynamic", containing a random quote and your machine's uptime.Advertisement
Advertising revenue is falling fast across the Internet, and independently-run sites like Ghacks are hit hardest by it. The advertising model in its current form is coming to an end, and we have to find other ways to continue operating this site.
We are committed to keeping our content free and independent, which means no paywalls, no sponsored posts, no annoying ad formats or subscription fees.
If you like our content, and would like to help, please consider making a contribution:
Ghacks is a technology news blog that was founded in 2005 by Martin Brinkmann. It has since then become one of the most popular tech news sites on the Internet with five authors and regular contributions from freelance writers.