Re: manage starting and stopping processes with less typing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



On 13/04/10 20:50, Linas wrote:
David C. Rankin wrote:
Guys,

	One thing I miss with Arch are init-script shortcuts for starting and stopping
processes. rc-commands really help cut down on typing. For example, all suse did
was to create links to the files in /etc/rc.d/... with a naming convention of
rc<init script name>. So, for example, instead of having to type:

   /etc/rc.d/postfix

the shortcut was simply

   rcpostfix

	I have normally seen the sym-link shortcuts placed in /usr/sbin, but
/usr/local/sbin works fine as well. The convenience is addictive. If you manage
your box from the command line or want to, then you can give this setup a
testdrive. You can create the sym-links very easily with the following cut and
pasted to the command line (as root - all on one line):

for i in $(ls /etc/rc.d); do [[ -e /etc/rc.d/$i ]]&&  [[ ! -h /usr/local/sbin/$i
]]&&  ln -sv /etc/rc.d/$i /usr/local/sbin/rc${i}; done

No need to create one symlink per file.
You can just add rc() { /etc/rc.d/$*; } to the user profile to
automatically be able to do:

rc postfix start  for any script you have or ever add.

To have autocompletion with your new command, also add:
complete -o filenames -W "$(cd /etc/rc.d/&&  echo *)" rc


here's my rc script, no need for completion IMO when you can just type: `rc r l~pd` to restart lighttpd

#!/bin/sh

WC='~'

if [ $# -ne 2 ]; then
    echo "usage: <OPERATION> <PATTERN>"
echo " OPERATION can also be one of: k(stop), r(restart), s(start)"
    echo "       PATTERN(grep -E ^PATTERN$) where $WC is replaced with .*"
    exit 1
fi

case $1 in
k) opr="stop"
    ;;
r) opr="restart"
    ;;
s) opr="start"
    ;;
*) opr=$1
esac
if [ "$opr" = "" ]; then
    echo "error: no operation specified."
    exit 1
fi

pat=$(echo $2 | sed "s/$WC/.*/g")
rc=$(ls /etc/rc.d/ | grep -E "^$pat$")
mat=$(echo $rc | wc -w)
if [ "$mat" = "1" ]; then
    sudo /etc/rc.d/$rc $opr
elif [ "$mat" = "0" ]; then
    echo "error: no targets found."
else
    echo "error: multiple targets found:"
    for t in $(echo $rc); do
        echo "       $t"
    done
fi






[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]
  Powered by Linux