Skip to content

Instantly share code, notes, and snippets.

View nicdoye's full-sized avatar
🚲
All shall be well, and all shall be well, and all manner of thing shall be well

Nic Doye nicdoye

🚲
All shall be well, and all shall be well, and all manner of thing shall be well
View GitHub Profile
@nicdoye
nicdoye / pidfile-checker.sh
Created June 27, 2014 16:50
Simple shell script for monit to check if a lock file (containing a pid) has been left hanging around for a process that is not a daemon.
#!/bin/bash
. /lib/lsb/init-functions
pidofproc "$@" &>> /dev/null
retval=$?
# Ignore cases such as retval=3 (Pid file doesn't exist)
if [ $retval -ne 1 ]
@nicdoye
nicdoye / perl-find.sh
Created October 3, 2015 13:24
Find all .pm files (in /usr/*/perl5)
#!/bin/bash
# I know it's a bit stupid and there's better ways to do it. But who doesn't like playing.
# Written for an old CentOS 4 server where people have installed Perl modules any old how.
# Is there a way to merge the two matches together?
find /usr/*/perl5 | ruby -ne '/^(\/\w+){4}\/.*\.pm/.match($_) && puts( /^(\/\w+){4}\/[\.\d]*\/{0,1}(.*)/.match($_)[2] )'
@nicdoye
nicdoye / gpsnmpd
Created January 9, 2013 16:17
Init script for Greenplum 4 SNMP subagent for RHEL 5 Fork it and fix it for SLES, RHEL 6. You could also get it to work with .pgpass (as mentioned in the admin guide - didn't work here, so I put them in the file).
#!/bin/sh
#
# gpsnmpd: Provides the Greenplum SNMP as a sub-agent
#
# chkconfig: 35 99 01
# description: gpsnmpd is the GP Software agent for SNMP
#
#
# Sanity checks.
@nicdoye
nicdoye / statsd
Created January 9, 2013 16:29
Init script for statsd that works om RHEL 6/CentOS 6
#! /bin/sh
### BEGIN INIT INFO
# Provides: statsd
# Required-Start: $network $local_fs
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
### END INIT INFO
# Do NOT "set -e"
@nicdoye
nicdoye / tomcat7
Created January 9, 2013 16:52
Very simple Init Script for Tomcat 7 (works for 6, too). Tested on RHEL 6. Should work on RHEL 5 and SLES, too. Relies on file /etc/sysconfig/tomcat7 which contains two variables RUN_AS_USER (who to run) and CATALINA_HOME. Everything else (JAVA_OPTS, CATALINA_OPTS, CATALINA_PID) is set in $CATALINA_HOME/bin/setenv.sh
#!/bin/bash
#
# Init file for Tomcat 7 server
#
# chkconfig: 2345 80 20
# description: Tomcat 7 server
#
# Source function library.
. /etc/init.d/functions
@nicdoye
nicdoye / getpid.c
Created January 21, 2013 11:16
Quick demo of getpid (and getppid)
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
int main ( int argc, char *argv[] )
{
pid_t p;
pid_t pp;
@nicdoye
nicdoye / inodes.c
Created January 28, 2013 10:55
List number of inodes for file system and how many spare.
#include <stdio.h>
#include <stdlib.h>
#include <sys/statvfs.h>
int main(int argc, char **argv)
{
struct statvfs _statvfs;
if ( argc != 2 )
@nicdoye
nicdoye / mallocer.c
Created January 28, 2013 11:02
Allocate RAM wait a minute and exit. Useful for flushing caches etc. Can chose between malloc and calloc.
/*
Program to allocate MB of memory. Can chose between calloc and malloc implementations.
Author: nic doye http://worldofnic.org
Date: 2011.03.31
Last update: 2012.10.16
*/
#include <stdlib.h>
@nicdoye
nicdoye / count-commas.groovy
Created January 31, 2013 16:21
Count the number of commas in each line. Useful for checking simple CSV (but not proper, quoted CSV).
#!/usr/bin/env groovy
new File( args[0] ).eachLine{ it -> println it.count(',') }
@nicdoye
nicdoye / count-commas.rb
Last active December 13, 2015 18:18
A copy of my count-commas.groovy gist in ruby. Count the number of commas in each line, as of check-in 2 supports _real_ quoted CSV, too.
#!/usr/bin/env ruby
require 'csv'
CSV.foreach(ARGV[0],'r') {|row| puts row.size}