Click to See Complete Forum and Search --> : start-stop-restart script


ccc
03-16-2006, 10:26 PM
hi

howto change this script:

#!/bin/bash

modprobe ath_pci
sleep 1
ifconfig ath0 down
sleep 5
ifconfig ath0 up
route add default gw 192.168.2.1

to put start, stop and restart command ?

greetings
ccc

happybunny
03-16-2006, 10:43 PM
just compare it to an existing script in /etc/init.d

if you put a "case" in for start stop restart, when you type /etc/init.d/script start/stop/restart it will perform the action defined in that section of the script.

voidinit
03-16-2006, 11:58 PM
All you need to do is use a case statement. Do a man case then check it out.




case $1 in # $1 is the first parameter passed to the script.
start)
command1
command2
;; #exit the switch, like break.
stop)
command1
command2
;;
restart)
$0 stop #$0 is the path to the script itself.
$0 start
*) #The default case, if nothing else matches.
echo "Usage $0 ( start | stop | restart)"
# You don't need ;; here.
esac #close the case