POSTGRES – Top 100 Tables In Tablespace

I had a situation where I needed to find the top 100 largest tables in a certain tablespace on a postgres 9 database, in my case we archive tables into an archive1 tablespace. This query will find all the largest relations in the archive1 tablespace. Its important to swap out ‘archive1’ with whatever tablespace you are trying to list.

Hope this helps you out, took some time to get it to work.

Nagios Check Postgres Table Date Column Against now()

I had a situation where a daily sync of a table from one database to another was failing. This table was updated daily so the query should return something like this when it was synced correctly:

I use Nagios very heavily and I setup a custom plugin to check the query’s date against today’s date, this should warn or critical based on user supplied arguments. Here is what a failure looks like when running from the nagios servers command line. This worked well at alerting me when the sync failed, this was integrated into the nagios subsystem and emails and slack alerts are generated as expected.

Nagios Python Plugin Check Lock File Exists

Code Highlighting Test

I just installed the crayon code highlight plugin from the link below, man you got to give credit where credit is due. This plugin was simple to install on my site and it has endless code highlighting capabilities.
Crayon Highlight
OMG: This is some pretty code highlighting if I must say so myself. Have a look:

PYTHON:

PHP:

C++:

BASH:

PERL:

JAVA:

CYGWIN – clear.exe from scratch C Program

Hello all,

TL;DR – I wrote a C program to use as clear.exe on cygwin, I know about CTRL-L but I wanted a binary for scripts, and I am used to typing clear at a terminal

I was recently enforced to use Windows as my daily computer at work for all types of compliance PCI reasons, reasons that I do not wish to dive into. However I am now on Windows, I spend most of my day in a BASH shell on a remote system, so it’s not that bad. However traversing around Windows with CMD or PS sucked. I was introduced to cygwin and I was really impressed, I was able to use a ton of tools that I was already familiar with on the Linux CLI. Native SSH,SCP were huge for me at this time, also the ability to customize the colors with the TTY settings was awesome.

One issue I ran into was I liked to use the clear command in my scripts and from the CLI when I want a fresh terminal. Well, I figured I could just re launch the cygwin installer and search for clear.exe and install it. This was not the case, unfortunately I was instructed to install ncurses and the associated libraries. I followed these recommendations and never got clear.exe to work.

So I did what any computer scientist would do, research how to write a C program on this and compile it and copy it to my $PATH and wouldn’t you know it works!!.

So Here it is in all it’s glory. clear.exe for Windows and CYGWIN:

### Clear no workie ###

Ok so we can see the clear program was not working in the above example. So I wrote the following lines of C code below and compiled them.

OK, cool, now you will need to get GCC on your Windows machine from the CYGWIN installer, so just re run the installer and search GCC, you can install it from there like so.

View post on imgur.com

Ok now for the awesome stuff, it’s time to compile this with GCC and create a new clear.exe binary for Windows and CYGWIN.

Now that we see we can use the new executable to clear out cygwin shell, let’s copy it somewhere so we can just type “clear” to get what we want.

And there you have it, have fun!!!

Jason

MD5 check via ssh to be sure data has rsynced properly then delete 5 days of data from collector

EDIT: A colleague assisted with this.

STOWE VERMONT

I was sitting here thinking about how much I miss Stowe Vermont and how bad the snow count for this season 15/16 was up north. Stowe Vermont is a very magical place in northern Vermont that has one of the most desired ski resorts in the northeast(STOWE).

I love Stowe and it has a deep spot in my heart, I was engaged there so many memories of the place. Anyway I kind of wanted to pay a tribute to the resort and post some awesome pictures I found on the web. Hope you like it……………

STOWE03
STOWE04
STOWE05
STOWE06
STOWE07
STOWE08
STOWE01
STOWE02

C Code Learn – Open file write user input to it

Every once in a while I will get this urge to want to learn some C, C++. I am versed in Python and know my way around bash / Shell scripting like the back of my hand. But as always I am continuing to learn and self teaching myself is how learn the “BEST IS IS”.

Anyway let’s get to it, I wanted a program that would prompt a user for a sentence and then take that sentence and write it to a file, the program would have to create the file if it did not exist. Let me show you the code and attempt to break it down.

WeatherUnderground API fun – PYTHON

I started to play with web scraping in Python, this is pretty neat. I can grab an extended forecast from weatherunderground for any city and display this in my bash shell. This is just the tip of the iceberg, so much fun and capabilities.

Weather Code

Here is a sample of the raw JSON from the API request.

Puppet Enterprise Installation /bin/bash: bad interpreter: Permission denied

I thought I would write up a quick post in regards to installing PE and getting a BASH permission denied error.

information:bash: /tmp/pe-installer-ibqD7803/install/puppet-enterprise-installer: /bin/bash: bad interpreter: Permission denied

When using the enterprise installer from Puppet, I was able to get to the webpage and enter all the parameters. When I clicked deploy I was faced with the above error about the BASH interpreter. It turned out that I had NOEXEC permission on the /tmp directory. Once I changed this with the following command I was able to install PE.

To remove noexec:
mount -o remount,exec /tmp

To Put it Back:
mount -o remount,noexec /tmp