BASH – making tab completion case insensitive

This is very lazy, but comes in handy for example if your browsing a Windows mount with random uppercases in file/folder names.

Add:

make your tab completion case insensitive

To your $HOME/.inputrc file (create the file if it doesn’t exist).  Alternatively you can make this userwide by adding it to /etc/inputrc .

You might need to reset the terminal, but now you can enjoy case insensitive tabbed browsing.

Using mod_proxy to avoid DNS propagation during site migration

There are a number of ways to migrate a site to a new server, whilst avoiding downtime or data concurrency issues. For a highly dynamic site, generally I would edit the old and new site connection strings to both use the same database during switchover.  mod_proxy is a useful method perhaps if a new version of the site is going live on the new server. Using mod_proxy, the new server can be configured to send site requests to the old server. This means that the DNS can be updated without anyone noticing. Once DNS has propagated, the new site can then be put live on the new server instantly, at any time by removing the proxy rules and resuming the standard vhost configuration.

Very simple to set up, make sure that mod_proxy is enabled by un-commenting the following in your httpd.conf:
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so

Then edit /etc/hosts on the new server to tell it to access the website at the old server:
85.233.111.222 www.mydomain.com

Then add the following two lines to your vhost configuration and restart apache.:
ProxyPass / http://www.mydomain.com/
ProxyPassReverse / http://www.mydomain.com/

Identifying apache process usage

When apache is running with php as an apache module rather than as a CGI, all processes will run as the apache user.  This makes it a little tricky on a busy multi-site box to identify which sites are using resources and keeping sessions open.  This little command will identify the working directory that the php (or other) script is running from, to hopefully identify which site/directory is causing grief:

for process in $(ps auxf | grep httpd | awk '{print $2}'); do ls -l /proc/$process/cwd; done

Mounting Windows drives and shares in Linux

The following have come in handy for mounting a Windows share on a Linux computer:

mount -t cifs -o username=user,password=password,umask=000 //winbox/winshare /mnt/home/

or

smbmount //winbox/winshare /mnt/home/ -o username=user,password=password,rw

An example of mounting a local NTFS partition held on the same machine:

ntfsmount /dev/sda2 /mnt/windows -o umask=0002,silent

Yum Automatic Updates

You can install yum-cron to automatically download and install all available updates:

yum install yum-cron

chkconfig –list | grep yum – should show that the service is disabled

chkconfig yum-cron on

service yum-cron start

Job Done – it will now check for and apply updates every night.  If its business critical solution though its probably a better idea to write a monitoring script to yum check-update and email when updates are available.

Random integers in BASH

Never really had a need for it before in BASH, but the following formula allows you to create random integers between two values:

rnumber=$(((RANDOM%(max-min+divisibleBy))/divisibleBy*divisibleBy+min))

Useful for example to create random passwords that have a length within a set range.

< /dev/urandom tr -dc A-Za-z0-9_$*?!.:=@#% | head -c$((RANDOM %4 +8))

Configuring MySQL over SSL for client connections

Useful for setting up encrypted connections between client and server.  Parts of this can be substituted if you wished to get a certificate issued from a trusted CA.

1. Check that SSL has been compiled in MySQL on the server:

SHOW VARIABLES LIKE ‘have_openssl’;
or
mysql –ssl –help
If it says disabled or yes then its fine.  If it says no then an SSL enabled version of MySQL needs to be installed.

Linux ip useful commands

ip -4 -o addr – nicely formatted list of IPv4 addresses on machine

ip link show – shows the available interfaces on machine

Exchange 2007 – Renewing self signed SSL

If your running Exchange 2007 and you don’t really have the need for an SSL that’s issued by a valid CA, then you can just renew the self signed one that’s automatically generated on server build.  Most devices are happy to connect to an unsigned SSL once an exceptions been made, but they may well require a valid date.

Open up Exchange powershell:

Get-ExchangeCertificate -DomainName servername.domainname.com

It should be obvious which certificate is the current one. To duplicate this into a renewed cert, grab the thumbprint and do:

Get-ExchangeCertificate -Thumbprint [thumbprint of old ssl] | New-ExchangeCertificate

Then to make it live:
Enable-ExchangeCertificate -Thumbprint [thumbprint of new ssl] -Service IIS

You can check the current cert details using:
Get-ExchangeCertificate | List

Bulk DNS Query in Plesk

I put this command together to grab DNS information relating to all of the domains hosted on a Plesk server.  Useful if your migrating to a new server and need to know where to update the DNS zones.  This checks the nameservers but can easily be substituted with A or MX:

for domain in $(mysql -uadmin -p$(cat /etc/psa/.psa.shadow ) -Dpsa -e'select name from domains;'); do dig ns $domain +noall +answer; done