Find all ServerNames and ServerAliases in several vhosts.conf files

In Apache one specify the servername and serveralias in a virtualhost directive in possible a single .conf file.

We had an Apache webserver with hundreds of such .conf files. With this bash one-liner you can find all ServerName and ServerAlias’s:

cd /etc/httpd/vhosts.d/ ; find . -type f | xargs egrep -i 'servername|serveralias' | awk {'print $3'} | sort | uniq

Use a variable counter in a bash one-liner

I had 70 different domain names that I need to add in a ssl cnf file for creating a certificate request.

The 70 different domain names was in a text file, one per line:

domainname1.something.com
domainname2.somehing.com
...

In order to create the alternative names list, I used this bash oneliner:

teller=1; for i in `cat /tmp/disse2`; do echo "DNS.$teller = $i"; teller=$((teller+1)); done

which then would give me:
DNS.1 = domainname1.something.com
DNS.2 = domainname2.somehing.com
...
DNS.70 = and-so-forth-until 70

This could be useful, if you have for instance hundreds or thousands of lines where you have to add a incremental value per line.

Pimp my shell!

Got a tip from my colleague JB!

Want to refresh your terminal? Is it spring and time to freshen things up? Look at: http://ohmyz.sh/

Easy to install on Redhat:

yum -y install zsh
sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"

Result in my Putty in Windows 7:

Cron every last Friday of month

We wanted to run a script every last Friday of the month. The script was set to remind people about certain issues. Friday is a nice day to be reminded of things, right?

Anyway, by putting this in the /etc/crontab file, one can achieve the request:

59 11 * * 5 username [ $(date +"\%m") -ne $(date -d 7days +"\%m") ] && $(cd /to/folder/; php myphpscript.php)

Which says:

At 11:59 on Friday run this command:

[ $(date +"\%m") -ne $(date -d 7days +"\%m") ] && $(cd /to/folder/; php myphpscript.php)

The first part:
[ $(date +"\%m") -ne $(date -d 7days +"\%m") ]

will test if the current month is equal to the month that will be in 7 days. If it is, it will generate something like:

01 -ne 01

which means it is current date is in January month (01), and it is compared (-ne = not equal to) the date in 7 days. If the result is:

01 -ne 02

one knows that the month in 7 days is February, hence the current date is the last Friday of this month 🙂

Reference: http://techsk.blogspot.no/2008/06/how-to-run-cronjob-on-last-friday-of.html