Skip to content

Instantly share code, notes, and snippets.

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 Jun 27, 2014
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.
View pidfile-checker.sh
#!/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 Oct 3, 2015
Find all .pm files (in /usr/*/perl5)
View perl-find.sh
#!/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 Jan 9, 2013
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).
View gpsnmpd
#!/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 Jan 9, 2013
Init script for statsd that works om RHEL 6/CentOS 6
View statsd
#! /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 Jan 9, 2013
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
View tomcat7
#!/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 Jan 21, 2013
Quick demo of getpid (and getppid)
View getpid.c
#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 Jan 28, 2013
List number of inodes for file system and how many spare.
View inodes.c
#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 Jan 28, 2013
Allocate RAM wait a minute and exit. Useful for flushing caches etc. Can chose between malloc and calloc.
View mallocer.c
/*
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 / fstab
Created Jan 30, 2013
Sample /etc/fstab for cygwin
View fstab
# First just shows how to mount a UNC path
# Second just puts Google Drive somewhere useful
//<servername>/<path> /mnt/<path> smbfs acl,binary,nouser,posix=1 0 0
C:/Users/<username>/Google\040Drive /mnt/google smbfs acl,binary,nouser,posix=1 0 0
@nicdoye
nicdoye / count-commas.groovy
Created Jan 31, 2013
Count the number of commas in each line. Useful for checking simple CSV (but not proper, quoted CSV).
View count-commas.groovy
#!/usr/bin/env groovy
new File( args[0] ).eachLine{ it -> println it.count(',') }