Blog by Daniel Hauck. Sysadmin, Developer, Blogger.

TAG: bash

PHP / Symfony Development Environment with Vagrant and Ansible – BONUS: MySQL

As I have received multiple requests now, I decided to make a little bonus for you 😉

It seems like a lot of you prefering mysql over postgresql. I don’t understand why, but that’s another topic 😉

You can do it!

Actually it ain’t that hard. But let’s go through it, step by step.

First, as usual, create your role:

We will reuse our apps config from the postgres database here, so nothing to change in case of the group_vars/all file.

Now it’s time to install the mysql server itself, therefore create a main.yml as usual:

As with postgres, to create databases and users, we need to install the python mysql binding, let’s to it.

Last but not least we will finally create our users and their databases:

Test it!

Get rid of the postgres role in provisioning/playbook.yml and replace it with

Now run your provisiong again, and you are ready to use mysql.

Ain’t that easy? See you next time!

Get Your Owncloud / Caldav Calendar Into Tmux

In my previous post I promised you that I will show you how to get you owncloud calendar into tmux status bar. Since owncloud uses the caldav protocol, this post should fit for most caldav servers.

To accomplish this task I will use the python library caldav, which latest version is 0.4.0. You can easily install it via pip:

pip install caldav

If pip is not available, install it with your package manager, i.e. apt:

apt-get install python-pip python-dev

Ok, you got everything setup. Let’s start.

First you need to grab the url from your owncloud web interface. Therefore login to owncloud click on the dropdown at the top left and select calendar.

On the left side you can see your calendar(or multiple ones), which default name is personal. Next to it there is a hyperlink symbol(as you see in the screenshot).

 

Selection_001Below there appears a link to the caldav api of owncloud. Just copy it for later.

Now we got every information we need. Let’s have a look at the python script I have prepared:

If you got any suggestions how to make the short script better, please use the comments 😉

The script prints out your next appointment in your calendar, so we can directly call it in tmux, no sed or else is required.
So save the script, for example to ~/bin/ or /usr/local/bin/ and make it executable:

chmod +x ~/bin/next_appointment.py

And call it from you ~/.tmux.conf:

set -g status-right '📅 #(~/bin/next_appointment.py)'

Voila! Your next appointment appears in tmux 🙂

Screenshot from 2015-07-07 08:51:40

If you got any questions, suggestions or wishes, please use the comments here on the blog. Otherwise they will be scattered at G+, Twitter and reddit.

You want to learn more about an effective workflow with tmux? Sign up for my book, of course you will get a discount with the newsletter 😉

Start TMUX on Login to a new Bash

I use tmux for a while now.

It is a Terminal Mutliplexer, so you can open multiple windows and split your windows in lot of panes.

For example I use it for development to have my vim in one pane, my mongo connection in another, and a python shell in the next one.

Sometimes I forgot to open a session at startup and later wondered why the shortcuts won’t work…

I tinkered around and just wrote tmux to the end of my .bashrc, not a good idea. It would try open tmux in every new pane or window.

At the end of the day you would have thousands of tmux session nested 😉 Trust me you don’t want this.

So you need so check if you are either in a ‘normal’ session like xterm or similar or if you already in a tmux session.

Just append this single line to your .bashrc:

Here I check if the TERM environment variable is NOT set to screen, otherwise I fire up a new tmux session.

Click the link to learn more about the TERM variable

Simple WordPress Bash Backup Script

Hey Guys,

I needed to do some backups of multiple wordpress sites, so I decided to write a backup script especially for wordpress.

All you need is to call the script with two parametes, the first is the folder where your wordpress instance is installed, in my case /var/www/example.com.
The second is the folder where to backup it.

So for example:
./backup_wordpress /var/www/example.com /tmp/backup/example.com

That’s all, the script figures out how to connect to the database, creates a gzipped dump with timestamp, and creates a tar archive also with a timestamp.

You’ll find it in your specified folder under wp and db.

That’s it, have fun.