Days of the week array

This snippet will give you the days of the week but human-readable in your own language.

today=$(date +%u)



Now you can use $today and $yesterday as variables in folder names, usefull for back-ups.

MySQL automatic restore script

We had a .sql export from a MySQL databaseserver from all the databases. In our case the filenames were made up like:


So I wrote a little bash script to recreate all the databases and import it’s data:



for file in `ls $folder/mysqldump-*.sql`
echo $file
IFS='-' read -r -a array <<< "$file"
echo ${array[2]}
echo "create database ${array[2]}" | mysql -u da_admin -ppassword
mysql -u da_admin -pnAcQKhIK ${array[2]} < $file


After a little while all databases were full with content again 🙂

Install Dutch Language in DirectAdmin Enhanced skin

I use this code to install the Dutch Language (Nederlandse taal) on all my servers. It will get automatically updated if there is a new version available.

cd /usr/local/directadmin/data/skins/
unzip -o
chown -R diradmin:diradmin enhanced/images/
chown -R diradmin:diradmin enhanced/lang/
chown diradmin:diradmin enhanced/files_custom.conf
chmod -R 755 enhanced/images/
chmod -R 755 enhanced/lang/
chmod 755 enhanced/files_custom.conf
rm -f

After running this code you can select the Dutch Language (nl) in the Modify User page in DirectAdmin.

How to reinstall the default Enhanced skin

If you need to reinstall the default DirectAdmin skin Enhanced you can use this code:

rm -f /usr/local/directadmin/data/skins/enhanced
cd /usr/local/directadmin/data/skins/
mkdir -p enhanced
tar -xzf enhanced.tar.gz

After this code the enhanced skin will be updated and be default again. Please not that you update DirectAdmin before reinstalling (and updating) the default Enhanced skin.

Rebuild your DirectAdmin user cache

In some particular cases I was unable to find my users using the DirectAdmin UI. Since then I use this little script to rebuild the user cache of the “Show All Users” list.


cd /usr/local/directadmin/data/users

for r in `ls */reseller.conf | cut -d/ -f1`; do
echo “fixing Reseller $r …”;

echo -n ” > $r/users.list

for u in `grep “^creator=$r$” */user.conf | cut -d/ -f1`; do
ISUSER=`grep -c usertype=user $u/user.conf`
if [ “$ISUSER” = “1” ]; then
echo $u >> $r/users.list

After using this script all users will be shown again in DirectAdmin.

Small sed cheatsheet

Sed is a brilliant function to delete or replace strings. I often used sed for replacing (a group of) words or deleting lines.

How to remove a line containing a string in sed:

sed -i '/string/d' /home/admin/filename.txt

How to replace a string in sed:

sed -i 's/#Port 22/Port 12340/g' /etc/ssh/sshd_config

How to remove white lines from ie a .ini file with sed:

sed -i '/^\s*$/d' /usr/local/directadmin/conf/directadmin.conf

Bash commands to see server stats

I found this little snippet elsewhere and find it very usefull to use in my own scripts for statistiscs:

free -m | awk 'NR==2{printf "Memory Usage: %s/%sMB (%.2f%)\n", $3,$2,$3*100/$2 }'
df -h | awk '$NF=="/"{printf "Disk Usage: %d/%dGB (%s)\n", $3,$2,$5}'
top -bn1 | grep load | awk '{printf "CPU Load: %.2f\n", $(NF-2)}'

It returns something like:

Memory Usage: 2340/24000MB (9.75%)
Disk Usage: 40/100GB (40%)
CPU Load: 0.04

Bash script to make MySQL back-ups

This simple but effective script makes a back-up of the target SQL database and deletes databases older then 90 days. I keep the folder synchronized with other systems so the customer can reach his database with 90 days retention himself.


cd /backups


date=$(date +"%d-%b-%Y")

umask 177

# dump the database
mysqldump --user=$user --password=$passwd --host=$host $db_name > $backup_path/$db_name-$date.sql

# zip contents
zip $db_name-$ $db_name-$date.sql

# remove old backups
find $backup_path/* -mtime +90 -exec rm {} \;

echo done


Of course, instead of setting the username/passwd variables in the script itself you can read the DirectAdmin credentials with:

source /usr/local/directadmin/conf/mysql.conf

Bash script to migrate Magento to DirectAdmin via rsync

Migrating Magento is pretty easy. Most of the times you only need to sync the files and export/import the database. But to automate such a process to test a lot, you can use a bash script to make things easier.

I often use this bash script (or similar) to migrate a Magento shop from one server to another:


echo dumping sql
ssh root@ -p 7685 "mysqldump -u magento_user -ppassword magento_db > /home/magento.sql"

echo rsync files
/usr/bin/rsync --exclude 'app/etc/local.xml' --exclude 'media/.htaccess' --exclude 'app/etc/config.xml' -a --delete -e "ssh -p 7685" root@ /home/user/domains/

echo rsync db
/usr/bin/rsync -a --delete -e "ssh -p 7685" root@ /home/user/domains/

echo importing db
source /usr/local/directadmin/conf/mysql.conf
mysql -u $user -p$passwd new_magentodb < /home/user/domains/

echo restoring permissions
chown -R user:user /home/user/domains/
chown user:user /home/user/domains/

echo done

This script is executed on the new server, which is loaded with DirectAdmin. The old server ( is plain CentOS 6.5. I added the to the authorized keys on the old server, so this server is able to execute commands as root without entering a password.

The port on the old server is 7685, that’s why you find it in the ssh and rsync commands.

I exclude the local.xml because on the new server I had to change the MySQL credentials. The media/.htaccess file gave problems on the new DirectAdmin server as well, so I had to change it and exclude the file from future rsyncs.

After running this script the Magento webshop is migrated from the old server to the new DirectAdmin server and works perfectly!


How to install/repair Installatron

This is how to install Installatron on a Centos server:

chmod +x
./ -f


If the normal install gets stuck, or your current installation is broken, try this full repair command:

rm -fr /usr/local/installatron/lib /usr/local/installatron/etc/php.ini 
curl -O 
chmod 755 
./ -f --stable 
rm -f /var/installatron/data.db /var/installatron/data.db-* 
/usr/local/installatron/installatron --repair --recache 
/usr/local/installatron/installatron --send-update-report