Tag Archives: bash

Install same packages for different PHP version

This is one of the things I should have thought of a long time ago.
More times than I can count I needed to install the same (or similar) list of PHP packages for a different version (ie. installing 7.0 while keeping 5.6) So instead of manually copying over the list or guessing as to what will be installed via dependencies here’s a quick one liner. Again, it’s a “facepalm” moment here for me:

# this installs 7.1 packages from a 7.0 list
dpkg -l | grep php7 | awk '{gsub(/7\.0/,"7.1",$2); print $2}' | xargs apt install

Also on my mind: instead of a sit/stand desk, can I install a shower desk. This way I can work and take showers at the same time!

Similar Posts:

Tagged , , ,

Update PIP on Ubuntu

From SO answer

Your pip may be outdated. Even in Ubuntu 14.04 LTS, the pip version it installed using apt-get install python-pip was 1.5.4. Try updating pip manually, and possibly the new packages again as well.

pip --version # 1.5.4
curl -O https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py
hash -r # reset bash cache
pip --version # 6.0.8

The hash -r line is essential!

reference: https://pip.pypa.io/en/latest/installing.html

Similar Posts:

Tagged , , , ,


json_curl() { curl --header "Accept:application/json" "$@" | python -m json.tool; }

add the line in ~/.bash_aliases

Similar Posts:

Tagged ,

IP Location

We rely on IP location for many things as sysadmins, like checking where that flood of logins to wordpress is coming from (China?!). Or even checking if a new order is coming from downtown Dubai or from the outskirts of Jakarta…

I usually use ip2location.com/demo/ and it works great from the browser. Recently however I noticed one of my colleagues using db-ip. They have a rest API. So I wrote this small wrapper, that needs plenty of fixes:
wget -qO- "http://api.db-ip.com/addrinfo?addr=${ADDR}&api_key=${KEY}"

Here’s a sample session:
$ ipinfo
{"address":"","country":"US","stateprov":"California","city":"San Francisco"}

Very simple, but seems enough if I want to check the IP location from the shell. Maybe I’ll add more features (if I need them!)

Similar Posts:

Tagged , , ,

Gnome Shell Screenshot + Imgur

The old gnome-screenshot was a very useful app. Unfortunately it seems to have been dropped in the latest gnome shell. I found this extension that does a similar job though. It’s called  Area Screenshot and you can find the code via github

Looking at the Advanced Usage note it seems that the developer added a hook that allows users to run a program after the screenshot has been taken. I used that to upload screenshots automatically to imgur.com. You will need to download the Bash Script Uploader and save it somewhere accessible as an executable. Then create the following script in ~/bin/area-screenshot-post

url=`imgur "$1"`
notify-send --hint=int:transient:1 "Screenshot Uploaded" "Copied URL to clipboard:\n$url"

You will get the url in the notification area.

Similar Posts:

Tagged , , , , ,

Create and Cancel a VPS at RIMUHOSTING

You can easily add and remove servers using the rimuhosting.com api. I wrote a quick bash script for that. The script is extendable with plenty of options per the docs.

Here’s the gist of it

Similar Posts:

Tagged , ,

Match SSL Certificate to Key and CSR

Renewing an SSL certificate is usually straight forward. But sometimes you’re not sure which CSR to use. Or if you need to generate a new CSR, which SSL key. Here are the commands I use to verify the certificate related files:

openssl x509 -noout -modulus -in mydomain.crt | openssl md5
openssl rsa -noout -modulus -in mydomain.key | openssl md5
openssl req -noout -modulus -in mydomain.csr | openssl md5

The MD5 hash should match.
You could use a bash script to search a directory for a specific MD5 hash. For example:

for f in $(ls $SOMEDIR); do echo $f; openssl x509 -noout -modulus -in $SOMEDIR$f | openssl md5 | grep "MYMD5HASH"; done

I guess the above could use some work 🙂

for the CLI-phobics check out this certificate key matcher

Similar Posts:

Tagged , , , ,

Dave’s Notepad

We were chatting in the morning and my colleague Dave said:

echo “blog post about distro choice” | mail -s “blog post” david@mydomain.org
that’s my ‘notepad’. 🙂

I thought that was pretty useful, but tried to make it easier by creating a bash alias. Turns out it’s better to use a bash function instead. (see this note). So my ‘jot’ function is:
function jot() { echo "$1" | mail -s "$2" abdallah@mydomain.com; }

I also noticed, that emails sent from my laptop were not reaching. It seems Ubuntu comes with Exim4 as a default MTA. I’m not too familiar with Exim, so I used the occasion to learn a new trick.

I might use this for micro-blogging next… let me go set it up 🙂

Similar Posts:

Tagged , , , , , , , , ,

MySQL Tuning

I’ve always felt it was a hassle to gather the data needed for tuning mysql, let alone interpret it. Here’s a great tool to do just that: the MySQL Performance Tuning Primer Script. From the page:

Currently it handles recomendations for the following:

  • Slow Query Log
  • Max Connections
  • Worker Threads
  • Key Buffer
  • Query Cache
  • Sort Buffer
  • Joins
  • Temp Tables
  • Table (Open & Definition) Cache
  • Table Locking
  • Table Scans (read_buffer)
  • Innodb Status
  • Similar Posts:

    Tagged , ,