Showing posts with label script. Show all posts
Showing posts with label script. Show all posts

Wednesday, May 6, 2009

cygwin shell syntax error near unexpected token

This is a common error and the reason is your are using Windows to create the file. Thus the line break is \r\n rather than \n.

All you need to do is change the format using a system command:

dos2unix filename_here

Sunday, August 17, 2008

Create startup script in SMEServer

SME Server is a pre-configured Linux server designed for small to medium businesses!
It used Red Hat Enterprise Linux kernel, or CentOS kernel.

When creating packages, I wanted a script to be running when the system boot up. For example, an auto usb drive mounting script. I started with something that running in the background, and didn't work quite well. Using & straight away is not a clever way because script in init.d folder should follow certain standard, and can be managed by the boot up program manager( it might be called something else).

Firstly, you can write a normal script and wrap it as the following example:



#!/bin/sh
#
# description: usbMountWrapper is the daemon to xxxxxx
#

. /etc/rc.d/init.d/functions

function start()
{
printf "Starting %s: " "usbMountWrapper"
daemon /opt/smebackup/usbMountWrapper &
echo
touch /var/lock/subsys/usbMountWrapper
}

function stop()
{
printf "Stopping %s: " "usbMountWrapper"
killproc usbMountWrapper
echo
rm -f /var/lock/subsys/usbMountWrapper
}

function reload()
{
pid=`pidof ulogd`
if [ "x$pid" != "x" ]; then
kill -HUP $pid 2>/dev/null
fi
touch /var/lock/subsys/usbMountWrapper
}

case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
reload)
reload
;;
status)
status usbMountWrapper
;;
*)
printf "Usage: %s {start|stop|status|restart|reload}\n" "usbMountWrapper"
exit 1
esac

exit 0




This is a much nice way of writing boot up script and you can start or stop them like this:
/etc/rc.d/init.d/usbMountWrapper start
/etc/rc.d/init.d/usbMountWrapper stop
/etc/rc.d/init.d/usbMountWrapper restart