Mac User Wind Up

12 Jan 2012 In: Jokes

A few weeks ago I was invited to a house party that was a tad dull. So I got bored and noticed all the music was coming from the home owners macbook pro.
As she wasn’t a particularly interesting person, kind of annoying and I had also drank a little too much vodka I decided I would mess with the mac.
Under the disguise as “DJ” I stole the laptop and set to work writting up a simple little bash script that would randomly kill firefox every now and again

Not a majorly evil script to run but I didn’t want to break the mac just something small enough to be annoying but not make the mac un-useable

Unfortunately I didn’t get a copy of the script but I will re write it here

#!/bin/bash

DICE=$[ ( $RANDOM % 6 )  + 1 ];

if [[ $DICE == 3 ]]; then
killall firefox-bin
fi

Cron tab entry

*/30 * * * * /home/user/rollofthedie.sh

Obviously you can change it to run when you want and change the command to run but its a fun little way to mess with peoples heads. Curious to see if she took it to a shop to be repaired and if they charged her

If you think I’m mean for doing this, this is what I heard from her friend (who had invited me along) so no longer my responsibility >:D!

Message from homeowner to friend

from Miss A;

“I think mike did shit to my Firefox
It’s closing all the time now”

Messages between me and friend

Me:
Ahahahaha yes I did!

Friend:
haha
fuck it

Me:
You told her how to fix it?

Friend:
Nahhh don’t know how to plus it’s funny if we just leave it as it is! Hahaha

Me:
I can tell you if you like?

Friend:
Nah More fun this way! Hahaha


9 Things I Hate About Everyone

Saw this the other day and felt like sharing

1. People who point at their wrist asking for the time… I know where my watch is pal, where the hell is yours? Do I point at my crotch when I ask where the toilet is?

2. People who are willing to get off their a** to search the entire room for the TV remote because they refuse to walk to the TV and change the channel manually(admittedly I still do this but hate myself for it).

3. When people say “Oh you just want to have your cake and eat it too”. Damn Right! What good is cake if you can’t eat it?

4. When people say “it’s always the last place you look”. Of course it is. Why the hell would you keep looking after you’ve found it? Do people do this? Who and where are they?

5. When people say while watching a film, “did ya see that?” No Loser, I paid £20 to come to the cinema and stare at the damn floor!

6. People who ask “Can I ask you a question?”… Little bit late now isn’t it?

7. When something is ‘new and improved’. Which is it then?! If it’s new, then there has never been anything before it. If it’s an improvement, then there must have been something before it, couldn’t be new.

8. When people say “life is short”? Life is the longest damn thing your gunna do

9. When you are waiting for the bus and someone asks “Has the bus come yet?” If the bus came, would I be standing here???


I have written a quick perl script to scrape http access logs and report them back to nagios with running totals

I used a handy little script called LogTail which allows you to only tail the file since the last time you looked at it so you only get the running totals since your last nagios check

Log tail can be found here:
http://www.adamsinfoserv.com/twiki/pub/AIX/AdminTools/logtail.pl

Also I have presumed you will save it under ‘/usr/sbin/logtail’ which you may wish to update

If you have any problems with this script gimmie a shout and i’ll be happy to help out :)

#!/usr/bin/perl
use strict;
my $start_run = time();

use Pod::Usage();
use Getopt::Long();

my $count;
my $lvl;
my $error_code;
my $warning_lvl = 0;
my $critical_lvl = 0;
my $help = 0;

Getopt::Long::GetOptions (
	'error|e=s' => \$error_code,
	'warning|w=s' => \$warning_lvl,
	'critical|c=s' => \$critical_lvl,
	'help|?' => \$help,
	);

pod2usage(1) if ($help);
pod2usage(1) if (!$ARGV[0]);
pod2usage("Log file does not exist") unless -e($ARGV[0]);

my $count;

sub report {

	if($count > $critical_lvl){
		$lvl = "CRITICAL:";
	}elsif($count > $warning_lvl){
		$lvl = "WARNING:";
	}

my $end_run = time();
my $run_time = $end_run - $start_run;

print $lvl.$error_code."=".$count."_responses=".$count."\n";
print "Job took $run_time seconds\n";
exit;
}

open (F, "/usr/sbin/logtail $ARGV[0] |") or die;
while (<F>) {
	if ($_ =~m/HTTP\/1\.1" $error_code/o) {
		$count++;
	}
}
report;

__END__

=head1 NAME

Nagios Http Log Monitoring tool

=head1 SYNOPSIS

scrape_http_nagios.pl [arguments] [Vaild/path/to/logfile]

 Arguments:
 -e, -error	Error code your looking for, defaults returning all codes
 -w, -warning   Maximum acceptable errors before warning error, Defaults at none
 -c, -critical  Maximum acceptable errors before critical error, Defaults at none
 -h, -help	Help Message

.
So here is the problem I came across, we don’t have a central logging in place and I need to get a copy of the access and error logs from a cluster of servers

Now I know this isn’t the best way to do this and I’m sure it could of done quicker in bash but as I don’t know it that well I wrote another little Perl script to do it for me.
#! /usr/bin/perl

# files for downloading, using the * wildcard so it gets the rotated ones
my @files = qw(access.log* error.log*);

#array of servers to scp from
my @serv = qw(web0{1..4}.server.com);

foreach my $serv(@serv){
# will create a separate directory for each server so the files don’t get overwritten
`mkdir ~/$serv-logs`;
foreach my $file(@files){
print”Getting $file from $serv\n”;
`scp $serv:/usr/local/apache2-nap/logs/nap/$file ~/$serv-logs`;
}
}
print “done”;

Now I have two reasons for posting up this blog!
Firstly for anyone else who gets stuck and has no where else to go and needs to get it done asap
Secondly so someone can possibly comment and point me in the right direction!

and the secret third reason is so I get embarrassed of showing people the wrong way way to do things, learn bash and post up a correct and better method!


.
Right so I’m a bit of a nightmare for committing puppet code with syntax errors and breaking puppet for the rest of my team, which they aren’t always to happy about. Infact I always know when I’ve committed something wrong as one of my team manages to sneak up behind me and announce my mistake.

I’m always forgetting the syntax commands to check the manifest files and the template files, so I thought i would list them here so i can reference back to them and also you might find it helpful too!

For the manifest file we have;

puppet --parseonly init.pp

And templates;

erb -x -T '-' -P some.template | ruby -c 

As I was also feeling lazy that day I decided to write a little perl wrapper that could run down the directory I was working in run all the check correct checks and report back

As I’m feeling generous I will also show you a copy of that, I just put a copy of this in my /bin directory possibly not the right place but it works. if you know better write a comment and I can get it moved ;), i’m only a junior so always still learning a few basics.

This code comes with no guarantee what so ever and you use at your own risk!

When called you can either pass it a full directory as an argument or just let it use your CWD (current working directory). This script does expect you to have puppet installed as well as the cpan module Term::ANSIColor.

                                                                     
#!/usr/bin/perl -w

use strict;
use Term::ANSIColor;
use Cwd;

my $syn; # will be used to store syntax error

sub recurse($) {
my($path) = @_; #Path to check

$path = getcwd if(!$path);
## append a trailing / if it's not there
$path .= '/' if($path !~ /\/$/);

print $path,"\n";

## loop through the files contained in the directory
for my $eachFile (glob($path.'*')) {

	## if the file is a directory
	if( -d $eachFile) {
		## pass the directory to the routine ( recursion )
		&recurse($eachFile);
	} else {
	## print the file ... tabbed for readability
		if($eachFile =~ m/\.pp$/){
			$syn = `puppet --parseonly $eachFile`;
		}elsif($eachFile =~ m/\/templates\//){
			$syn = `erb -x -T '-' -P $eachFile | ruby -c 2>&1`;
			chomp($syn);
		}
		if(!$syn || $syn =~ m/^Syntax OK$/){
			print "\t",$eachFile;
			print color("green"),"\tOK\n", color("reset");
		}else{
			print "\t",$eachFile;
			print color("red"),"\tError\t",$syn,"\n", color("reset");

		}
	}
}
}

##initial call ... $ARGV[0] is the first command line argument
recurse($ARGV[0])


About this blog

Hey! Welcome to my site, If you've managed to find this site you must of been looking pretty hard or I was being sad and gave you the URL. Anyway I'm currently a Junior System Admin @ Net-A-Porter.com. I have recently decided I waned to get a place where I can dump a few little handy scripts I'm proud of or just to vent some steam.

Sponsors(better known as Ads)