#!/bin/bash # # off/respawn # # dentar@dentar.com # # this is FREE software. hell, it's just a damn script. # # This program disables/enables entries in the inittab by replacing off with # respawn or respawn with off and issuing init q # # This script is meant to be put in /sbin, chmodded to 700 root:root # and then linked to as follows: # # call the script /sbin/off or /sbin/disable # # link to it as /sbin/on, /sbin/enable, or /sbin/respawn # # if you wish to call it something else, be sure to change the item # names in the case statement below as we are evaluating $0 to find out if we # are to enable or disable. # VERSION=0.09 if echo $* | grep -q showlabel then grep -e ":off:" -e ":respawn:" /etc/inittab \ | grep -v "^\#" exit 0 fi if echo $* | grep -q usage then echo echo respawn/off v$VERSION echo echo echo respawn/off changes values in the /etc/inittab to respawn or off echo then issues an init q to start or stop that entry. echo echo this program will not work with inittab entries that have been echo commented out. echo echo off showlabel echo respawn showlabel echo echo " shows the labels in the inittab file and their values" echo echo off usage echo respawn usage echo echo " shows this screen" echo echo off label1 label2 label3... echo respawn label1 label2 label3... echo exit 0 fi for LABEL in $* do if grep -q "^$LABEL:" /etc/inittab then case `basename $0` in enable|respawn|on) if grep "^$LABEL:" /etc/inittab | grep -q ":respawn:" then echo "Label $LABEL is already enabled." else cat /etc/inittab \ | sed -e '/^'$LABEL':/s/:off:/:respawn:/' \ > /etc/inittab.tmp cp /etc/inittab.tmp /etc/inittab init q echo $LABEL enabled. fi ;; disable|off) if grep "^$LABEL:" /etc/inittab | grep -q ":off:" then echo "Label $LABEL is already disabled." else cat /etc/inittab \ | sed -e '/^'$LABEL':/s/:respawn:/:off:/' \ > /etc/inittab.tmp cp /etc/inittab.tmp /etc/inittab init q echo $LABEL disabled. fi ;; esac else echo $LABEL not found. $0 showlabels to see the available labels. fi done