Archive for 'Shell'
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 | [...]
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 [...]
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. =)
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 [...]
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 [...]
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 [...]