Bash: compute dates

Often I found myself in the need of computing some math on dates. For example what is 10 weeks from a given date? Rather than opening a calendar and start counting you can quickly open a bash shell.

Example: what’s 6th of June 2017 plus 10 weeks?

$ date -j -v '+10w' -f '%Y-%m-%d' '2017-06-06'
Tue 15 Aug 2017 10:00:20 BST

OSX Restarting GDrive App

If you use Google Drive and the OSX app, and like me you often travel and change network connection (VPNs count as well), you may have noticed that it won’t connect anymore.

While I don’t know why exactly, it may be due to some security things in the app itself, I noticed that by restarting the app it connects successfully.

Having to do it more than once a day, here is a simple script that with a double-click will restart it.

https://github.com/davidegiannella/misc/blob/master/restart-gdrive

How many CQ5 concurrent users?

Defining the concept of concurrent user in the web world is difficult and it’s even more difficult to do it in CQ as it doesn’t keep any session informantion. Technically speaking I define two users as concurrent when a request from user A has not finished yet that the one from B starts.

Don’t know if it’s possible to achieve such information just by looking at CQ logs but the analyse-access tool help you in the analysis of the access.log files that CQ produces giving you some numbers in a very handy markdown format that can be then converted to PDF for presenting it to the business.

References:

CQ5 backup your sources from CRX

El grito de la gaviota - Seagull scream

by Dani_vr via flickr

updated on Feb 15th, 2011

Yes, it happens. CRX has lost my sources from one day to another. As usual you realize that you need a backup when it’s too late. So the question became: how can I backup my sources outside the crx? Packages!

First you have to create a package of what you want to backup via the package manager provided with CRX. I wont go in details of this operation. Then you can call every package operation from a command line like bash and curl application. Fortunately Mac OS X and Linux come with cURL out of the box so nothing special is needed.

Just download the pdf containing the bash code, fix the variable according to your needs and schedule it or execute by hand.

The script is missing at all the error checking and some other things but works well for the moment; maybe in the future I’ll start a new SF project with the script source.

For more information here is a couple of links (same page)

Changing $PATH in Mac OS X

Two Paths Through the Tangled Japanese Forest

by Stuck in Customs via flickr

I’ve started few days ago using Mac OS X. While I still prefer Linux I appreciate the fact that I have the bash power within and I don’t have to go for cygwin anymore. However cygwin is a great tool!

The first thing I had to do was changing the PATH environment variable in my shell for having the newly installed XAMPP binaries. Here is how: edit your ~/.profile file (create it if not exists) and add/change the line export PATH=$PATH:/path/to/your/bins.

Easy! 🙂

[bash] format date

It happens often a script I have the needs to append a simple timestamp in the format of YYYYMMDDHHMMSS to a generated file.

It’s very easy to get it to work in pure bash, without perl script and similia. Just use the native date command with his format option. Easy as drinking a glass of water, the command is (for the format above)

$ date +”%Y%m%d%H%M%S”

for the full detail of the format arguments, refer to the man page.

A simple usage in script is

#!/bin/bash
set -e

NOW=`date +”%Y%m%d%H%M%S”`
FILE=my-cool-file-${NOW}.txt

echo $FILE