Archive for 'Shell'

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 [...]

Indenting bourne shell here documents

The Bourne shell provides here documents to allow block of data to be passed to a process through STDIN. The typical format for a here document is something similar to this: command <<ARBITRARY_TAG data to pass 1 data to pass 2 ARBITRARY_TAG This will send the data between the ARBITRARY_TAG statements to the standard input [...]

« Older Entries