Archive for 'Shell'

Fun times with the bash read function and subshells

There are a few shellisms that have bitten me over the years. One issue that has bitten me more than once is the interation of variable assignments when a pipe is used to pass data to a subshell. This annoyance can be easily illustrated with an example: $ cat test #!/bin/bash grep MemTotal /proc/meminfo | […]

Converting time since the epoch to a human readable string

I was parsing some Netbackup logs today, and needed a way to convert the time since the epoch into a human readable string. A while back I read about the various forms of input that can be passed to the GNU date’s “-d” option, one of these being the time since the epoch: $ date […]

Advanced Bash Scripting Guide

I came across the Advanced Bash Scripting guide while checking through my RSS feeds this morning.  It has a ton of great examples and goes pretty in-depth on Bash scripting features.  A good read for sure.  =)

Serve out content over HTTP from your cwd immediatly

Ever want to immediatly serve content from a specific directory over HTTP, but didn’t want to bother messing with httpd.conf or other webserver configiurations? If you’ve got Python installed, this is a snap.  Execute python with the SimpleHTTPServer module, using port 8080 so there isn’t a need to elevate privs to root. $ python -m […]

Awesome use of read-only variables in bash scripts

I was reading through Jim Perrin’s CentOS hardening article, and saw one super interesting use of read-only bourne shell variables. If you have users that are frequently logging in and staying idle for days and or weeks, you can add a readonly TMOUT variable to /etc/profile: $ echo “readonly TMOUT=3600″ >> /etc/profile The TMOUT variable […]

Implementing locks in shell scripts

I have been working on a shell script that manages lxc-containers, and came across a use case last where it is possible for two yum processes to interfere with each other. To ensure that only one yum process is run at a single point in time, I implemented file based locks using flock(1). Flock makes […]

« Older Entries