antipaucity

fighting the lack of good ideas

shell scripting

I’ve been playing around with bash scripting quite a bit recently in relation to my current job.

Came up with one that’s really useful (imho) around chkconfig:

# mass set all services known to chkconfig to be `on` or `off` at given level
# written by warren myers - warren@warrenmyers.com
# 28 sep 2009

echo "USAGE:"
echo " $0 <level> [on|off]"
echo

# list all services, just the name, skip blank lines, do in order
SERVICES=`chkconfig --list | cut -f 1 | grep -v ^$ | grep -v ':' | sort`

for SERVICE in $SERVICES
do
  chkconfig --level $1 $SERVICE $2
  echo "$SERVICE has been altered for $1 to state $2"
done

Yes – there’s an evil you could perform:

for CS in `chkconfig --list | cut -f 1 | grep -v ^$ | grep -v ':'`
do
  chkconfig --level 12345 $CS off
done

So, if you wanted to stop all services from coming on at startup, you could – and not know you did it until you rebooted.