Tag Archives: bash

HOWTO start a detached process in screen on boot

Using a key to gouge expletives on another's vehicle is a sign of trust... and friendship.

Using a key to gouge expletives on another's vehicle is a sign of trust... and friendship.

Ok, a quick one today – at work I had the problem of needing a process to be automatically started during boot, and have it running in the background, but it didn’t have its own init.d script. I knew there was a way I could use GNU Screen (one of my favorite ‘must have’ sys admin tools) to do this, but it took me some time searching to find the right syntax to translate for my needs, so I’m posting it here.

HOWTO monitor your servers via Twitter

Alert: your server has failed!

UPDATE: thanks to a reader’s comment I looked into what it would take to get this working again since Twitter has completely disabled the old style of authentication in favor of full on OAuth. Basically a lot. To just post messages now it seems far more complex than it once was.My original idea with this was to do it as low tech as possible so users wouldn’t have to install a ton of stuff and configure it – I wanted it to ‘just work’ easily. Now with OAuth it seems this will never work easily, first of all you have to ‘register an application‘ for it to have access to OAuth – which seems crazy to me, we don’t want it to have access, just the ability to push a message to an account. Then if you look there are libraries out there that *can* post, but look at the directions for one of the libraries, it involves not only building the app and getting temporary access to the twitter API, then you also have to get the two keys from that and bake them into the app by recompiling it, and then more configuration, etc. So for now I am MARKING THIS IDEA AS DEAD. If I figure out a new way to do it that I can sketch out I will, or if anyone else has a simple way post it in the comments and I’ll update it here. Thanks for your interest and good luck!

HOWTO sort web-server logs to find top users

The other day I came across a situation where a web-server was getting hammered, and we needed to know who the offend(ers) were. While watching a logfile tail by at high speeds is always fun, we wanted to be able to sort the web-server access log and find top users, to be able to narrow down where the traffic was coming from. While we don’t want to block users that want to access our data, sometimes we need to throttle things back so one requester doesn’t overwhelm all the available bandwidth and make the site unusable for others. So after some playing around and digging on Google, we came up with a nice, succinct one liner to do this, here it is:

cat /path/to/access.log | awk '{print $1}' | sort | uniq -c | sort -n | tail

HOWTO: send commandline email with attachments

You've got mail!

Are you like me, do you have scripts running on servers and you need to know what they know? If there’s output in a file you can sed/grep/awk info out of them and have them emailed to you, but if you don’t know specifically what you’re looking for you may need the entire file/log/whatever. You’ll need a utility called uuencode, which is a utility that,

HOWTO: webserver in 100 lines of Bash

I’m a big Bash fan, I know Perl is the more popular scripting language, and I’m slowly using it more, but hey, if I need something done, I can do it quicker in Bash (keeping in mind that I’m a systems guy, not a dev guy). While at work looking up Bash related syntax I came across a page describing how to run a webserver with 100 lines of Bash. It uses the old school GNU utility Netcat (nc) for communication between the pipes, and just a ton of basic logic and functions to pass it on to the user. It’s one of those things I look at and can’t believe it works, but it does. Of course security is unknown, as is the original author, but I consider this a reference on how to do networking things in Bash; who knows what I’ll use (parts) of it for. If anyone has details on who originally wrote this I’m all ears.[sourcecode language='xml']#!/bin/bash