Blog by Daniel Hauck. Sysadmin, Developer, Blogger.

Get your Google Calendar into TMUX

EDIT: If you need to have your caldav/owncloud calendar, have a look HERE.

The most time I work in the terminal in fullscreen mode for not getting disturbed. Therefore I like it to have my calendar(at least the next appointment) visible in my command line environment. I discovered a great tool for the command line called ‘gcalcli’. You can find it on github:

Install it via pip:

pip install gcalcli

After the installation you need to setup your account on the first connection. You can do this for example by requesting your agenda:

gcalcli agenda

A browser window will popup which is requesting your confirmation to manage your calendar:
Screenshot from 2015-06-29 21-29-10

After confirming you are able to query your calendar with the command line – GREAT! 😉

As wouldn’t that be cool enough, let’s put the calendar into tmux.

First we need to build the build the output we a few pipes and stuff:

gcalcli --nostarted --calendar "" agenda --nocolor | cut -d " " -f 4- | head -2 | tail -1 | sed "s/^ *//g" | sed "s/    / /g" | cut -c1-19

Let’s cut off the date, redundant spaces, empty lines and all the useless stuff and finally get only the next event in the calendar.
Also I only want the first 20 chars of the name, so let’s cut this ;).

Be sure to replace GOOGLE_USERNAME with your accountname(everything in front of

Now you have only the last element, so let’s get a nice calendar symbol and put it in our .tmux.conf.
Therefore your need to open your .tmux.conf modify the option ‘status-right’:
set -g status-right '📅 #(gcalcli --nostarted --calendar "" agenda --nocolor | cut -d " " -f 4- | head -2 | tail -1 | sed "s/^ *//g" | sed "s/    / /g" | cut -c1-19)'

So you are almost there, just save your file and reload your tmux config. So type your prefix(standard CTRL+B) and
:source-file ~/.tmux.conf

After a few seconds in the right bottom you should see your next event from the google calendar:
Screenshot from 2015-06-29 22-07-49
Nice! 🙂

In the next days I will write how to achieve this with your owncloud account.

Have fun and thanks for reading! 🙂


P.S.: Currently I am writing a bout about an effective workflow using tmux so don’t forget to opt in to the newsletter to get the latest updates on the work in progress.

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/
The second is the folder where to backup it.

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

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.

WTF: /bin/rm: Argument list too long

Imagine you got a directory, with millions of files in it. If you ever had the error message “/bin/rm: Argument list too long”,
you’ll know what I mean.

Here’s a workaround with find.

For example you wanted to delete all pdf files in the directory, here is how to do with find:

find -mindepth 1 -maxdepth 1 -type f -name '*.pdf' -delete

Let’s split the command:

find --> sure, the name of the command
-mindepth 1 --> find will search at least 1 level in depth
-maxdepth 1 --> find will search maximum 1 level in depth
-type f --> search only for files(see man find for other types)
-name '*.pdf' --> search for files ending with .pdf(use -iname for case insensitive search --> damn slow)
-delete --> deletes all matching files

With find you have the full control, and no need to be afraid, that you accidentally delete more files.

Have Fun!

Quick and dirty MySQL Backup

When you just need a simple backup of all your databases, this three lines do the job for you.

Just save it to a file and run it as a cron every night
00 01 * * * /srv/scripts/mysql_backup
and you get a zipped dump of every database with a timestamp.

It is easy extendable, if you want to exclude a database just write it into the grep regex
grep -Ev "(information_schema|performance_schema|another_database)"

Have fun! 🙂