home   articles   archive   forum   masthead  
Published at 22.06.02
Author: Günther Zander
Languages: de
Printer printer-version
Support Us!
  Warning: This article is in progress of being translated.

Eine Netzwerkinstallation unter SuSE 8.0 [Scripte]

Back to the article

7. Scripts



addjob (download)
   #!/bin/sh
   #
   # Günther Zander, Germany <g.zander@hamburg.de>
   # Copyright (c) by Author, GPL
   #
   # This script makes it possible to start jobs some time after
   # starting the system.
   #
   
   # set some variable defaults
   # --------------------
   ZPATH=/etc
   ZCONFIG=addjob.config
   ZSEP=" "
   ZTMP=/tmp/addjob.tmp
   ZDXXX=0
   ZTHHMM=0
   ZTHOUR=0
   ZTMINUTE=0
   ZHOUR=`date +%H`
   ZMINUTE=`date +%M`
   ZDAYNR=`date +%j`
   
   
   # get program name (last parameter)
   for i in $@
   do
     ZPROGRAM=$i
   done
   
   # get options
   # ------------------
   for i in $@
   do
   case "$i" in
   	-t*)
   	     echo $i | awk '{ t = substr($0,3)
   	       	if (length(t) == 4)
   	       	{
   	        	print substr($0,3,2)
   	      		print substr($0,5)
   	      		exit (0)
   	       	}
   	      	else
   	      	{
   	     	 	print ""
   	      	        print "ERROR: option -t wants a four digit number"
   		       	exit (1)
   		}
   	      }' > $ZTMP
   
   	      if [ $? -gt 0 ]; then
   			cat $ZTMP
   			exit 1
   	      else
   			{
   			a=1
   			for t in `cat $ZTMP`
   			do
   				if [ "$a" = "1" ]; then
   					 ZTHOUR=$t
   					 fi
   				if [ "$a" = "2" ]; then 
   					 ZTMINUTE=$t
   					 fi
   				a=`expr $a + 1`
   			done
   			}
   	      fi
   	      ;;
   	-d*)
   		echo $i | awk '{ t = substr($0,3)
   					print t
   					}' > $ZTMP
   		if [ "`cat $ZTMP`" = "1" ]; then
   			echo "0" > $ZTMP
   			fi
   		ZDXXX=`cat $ZTMP`
   		;;
   	-p*)
   		echo $i | awk '{ t = substr($0,3)
   					print t
   					}' > $ZTMP
   
   		ZPATH=`cat $ZTMP`
   		;;
   	-h | --help)
   		echo ""
   		echo " Synopsis: addjob [options] program "
   		echo ""
   		echo " This script needs root rights"
   		echo ""
   		echo " add programs      -> addjob [options] program"
   		echo " run the program   -> addjob [-p]"
   		echo " kill config file  -> addjob [-p] -clear"
   		echo ""
   		echo " options"
   		echo " --------"
   		echo " -thhmm       run hh hours and mm minutes after starting system (4 digits!)"
   		echo " -dxxx        repeat after xxx days, 0 for none"
   		echo " -p{path}     path to addjob.config. Default /etc"
   		echo " -h | --help  get this help"
   		echo " -clear       kill config file addjob.config"
   		echo " -list        list all config entries"
   		echo ""
   		exit 0
   		;;
   	-clear)
   		rm $ZPATH"/"$ZCONFIG
   		exit 0
   		;;
   	-list)
   		echo ""
   		echo "Entries in $ZPATH/$ZCONFIG"
   		cat $ZPATH"/"$ZCONFIG
   		echo ""
   		exit 0
   		;;
   esac
   done
   
   # format of addjob.config
   # ------------------------
   # all data in 24 hours format.
   #
   # Program: hh: mm: {-d}: {number of day start 1-366}
   
   if [ $# -ge 2 ]; then
  	i="$ZPROGRAM$ZSEP$ZTHOUR$ZSEP$ZTMINUTE$ZSEP$ZDXXX$ZSEP$ZDAYNR"
   	echo "$i" >> $ZPATH"/"$ZCONFIG
   	echo ""
   	echo " Entries in $ZPATH/$ZCONFIG"
   	cat $ZPATH"/"$ZCONFIG
   	exit 0
   fi
   
   # read and interpret config file
   a=1
   for t in `cat $ZPATH"/"$ZCONFIG`
   do
   	if [ "$a" = "1" ]; then
   		 ZPROGRAM=$t
   		 fi
   	if [ "$a" = "2" ]; then
   		 ZTHOUR=$t
   		 fi
   	if [ "$a" = "3" ]; then
   		 ZTMINUTE=$t
   		 fi
   	if [ "$a" = "4" ]; then
   		 ZDXXX=$t
   		 fi
   	if [ "$a" = "5" ]; then 
   		ZDAYNR=$t
   		a=0
   		DAYNR=`date +%j`
   		DIFF=`expr $DAYNR - $ZDAYNR`
   		if ! [ "$ZDXXX" = "0" ]; then
   			DIFF=`expr $DIFF % $ZDXXX`
   			else DIFF=0
   			fi
   		ZMIN=`expr $ZTMINUTE + $ZMINUTE`
   		ZHOU=`expr $ZTHOUR + $ZHOUR`
   		
   		if [ $ZMIN -ge 60 ];then
   			ZHOU=`expr $ZHOU + 1`
   			ZMIN=`expr $ZMIN - 60`
   		fi
   		if [ $ZMIN  -lt 10 ]; then
   			ZMIN="0"$ZMIN
   		fi		
   		
   		ZAUS="today"	
   		if [ $ZHOU -ge 24 ];then
   			ZAUS="tomorrow"
   			ZHOU=`expr $ZHOU - 24`
   		fi
   		if [ $ZHOU -lt 10 ]; then
   			ZHOU="0"$ZHOU
   		fi
   						
   		if [ "$DIFF" = "0" ]; then
   			`at -f $ZPROGRAM $ZHOU$ZMIN $ZAUS`
   			fi
   #		echo "test -->  $ZPROGRAM $ZHOU $ZMIN $ZAUS"
       	fi
   	a=`expr $a + 1`
   done
  







addjob-init (download)
   #! /bin/sh
   # Copyright (c) Günther Zander, Germany, <G.Zander@Hamburg.de>, GPL
   #
   # /etc/init.d/zander/addjob-init
   #
   
   ### BEGIN INIT INFO
   # Provides:       addjob-init
   # Required-Start: $netdaemons inetd
   # Required-Stop:
   # Default-Start:  5
   # Default-Stop:
   # Description:    Systemstartscript for execute addjob
   ### END INIT INFO
   
   
   . /etc/init.d/zander/zander.config
   . /etc/rc.status
   
   rc_reset
   if [ "$1" = "stop" ];then
      exit 0
      fi
  
   if test $ZANDER_START_ADDJOB = "yes" ; then
             echo -n "starting jobs for cron process"
             rc_status -v
   	  /usr/local/bin/addjob
   fi
   rc_reset
   rc_exit
  







zander.config (download)
   #
   # space seperated FQDN of the time servers
   #
   #ZANDER_NTP="cdwriter.maienweg.de time.fu-berlin.de"
   ZANDER_NTP="cdwriter.maienweg.de"
   
   #
   # how we get acces to our time server
   # local = internal network
   # ppp   = via ppp connection
   # ippp  = via isdn connection
   #
   ZANDER_NTP_ART="local"
   
   #
   # path to log file, if empty there will be no log file.
   #
   ZANDER_NTP_LOGDATEI="/var/log/ntp.log"
   
   # start of addjob (yes/no)
   #
   ZANDER_START_ADDJOB="yes"
  







ip-up.local (download)
   #!/bin/sh
   #
   # this script gets these parameters from ip-up
   # $1 = Connection type		(ppp0)
   # $2 = Connection device	(/dev/ttyS1)
   # $3 = speed			(57600)
   # $4 = local ip address 	(www.xxx.yyy.zzz)
   # $5 = peer ip address 	(www.xxx.yyy.zzz)
   #
   . /etc/init.d/zander/zander.config
   
   case "$1" in
   ppp*)
       #
       # activate network time protocol after connecting via ppp
       #
       if test $ZANDER_NTP_ART = "ppp"; then
          # ---------- Begin Protocol ----------------------------------------
          if ! test $ZANDER_NTP_LOGDATEI = ""; then
             echo -n "Adjust begin : "		 >> $ZANDER_NTP_LOGDATEI
             /sbin/clock				 >> $ZANDER_NTP_LOGDATEI
          fi      
          # ---------- Time update -------------------------------------------
          ZANDER_TMP1="NOT TIMESERVER FOUND!"       
          for ZANDER_TMP in `echo $ZANDER_NTP`
          do 
            `/usr/sbin/netdate $ZANDER_TMP > /tmp/netdate.tmp 2>&1`
            if test `grep -c "failed" /tmp/netdate.tmp` = 0; then
               /sbin/clock -wu
   	    ZANDER_TMP1=$ZANDER_TMP
   	    break 
            fi	
          done
          # ---------- End Protocol ------------------------------------------
          if test $ZANDER_NTP_LOGDATEI != ""; then
             echo -n "with Data    : "		 >> $ZANDER_NTP_LOGDATEI
             /sbin/clock				 >> $ZANDER_NTP_LOGDATEI
             echo "Timeserver   : "$ZANDER_TMP1	 >> $ZANDER_NTP_LOGDATEI
             echo					 >> $ZANDER_NTP_LOGDATEI
          fi      	
       fi
       # ------------- Cleaning ---------------------------------------------- 
       rm -f /tmp/netdate.tmp
       ;;
   ippp*)
       #
       # activate network time protocol after making an IPPP connection
       #
       if test $ZANDER_NTP_ART = "ippp"; then
          # ---------- Begin Protocol ----------------------------------------
          if ! test $ZANDER_NTP_LOGDATEI = ""; then
             echo -n "Adjust begin : "		 >> $ZANDER_NTP_LOGDATEI
             /sbin/clock				 >> $ZANDER_NTP_LOGDATEI
          fi      
          # ---------- Time update -------------------------------------------
          ZANDER_TMP1="NOT TIMESERVER FOUND!"       
          for ZANDER_TMP in `echo $ZANDER_NTP`
          do 
            `/usr/sbin/netdate $ZANDER_TMP > /tmp/netdate.tmp 2>&1`
            if test `grep -c "failed" /tmp/netdate.tmp` = 0; then
               /sbin/clock -wu
   	    ZANDER_TMP1=$ZANDER_TMP
   	    break 
            fi	
          done
          # ---------- End Protocol ------------------------------------------
          if test $ZANDER_NTP_LOGDATEI != ""; then
             echo -n "with Data    : "		 >> $ZANDER_NTP_LOGDATEI
             /sbin/clock				 >> $ZANDER_NTP_LOGDATEI
             echo "Timeserver   : "$ZANDER_TMP1	 >> $ZANDER_NTP_LOGDATEI
             echo					 >> $ZANDER_NTP_LOGDATEI
          fi      	
      fi	
       # ------------- Cleaning ----------------------------------------------
       rm -f /tmp/netdate.tmp
       ;;
   *)
       ;;
   esac
  







ntpdate (download)
   #! /bin/sh
   # Copyright (c) Günther Zander, Germany, <G.Zander@Hamburg.de>, GPL
   #
   # /etc/zander/ntpdate
   #
   ### BEGIN INIT INFO
   # Provides:       ntpdate
   # Required-Start: $netdaemons inetd
   # Required-Stop:
   # Default-Start:  3 5
   # Default-Stop:
   # Description:    Update Time from Time-Server
   ### END INIT INFO
   
   
   . /etc/init.d/zander/zander.config
   . /etc/rc.status
   #
   # activate network time protocol via local net 
   #
   clearline()  {
   	     printf "\033[1A\033[2K" 
   	     }
   	    
   rc_reset
   if [ "$1" = "stop" ];then
       exit 0
       fi
   
   if test $ZANDER_NTP_ART = "local" ; then
      # ---------- Begin Protocol ------------------------------------------------
      if ! test $ZANDER_NTP_LOGDATEI = ""; then
         echo -n "Adjust begin   : "			>> $ZANDER_NTP_LOGDATEI
         /sbin/clock					>> $ZANDER_NTP_LOGDATEI
      fi
      # ---------- Time update ---------------------------------------------------
      ZANDER_TMP1="NOT TIMESERVER FOUND!"
      echo
         
      for ZANDER_TMP in `echo $ZANDER_NTP`
      do
          clearline
          echo "Calling NTP-Server $ZANDER_TMP"
          `/usr/sbin/netdate $ZANDER_TMP > /tmp/netdate.tmp 2>&1`
          if test `grep -c "failed" /tmp/netdate.tmp` = 0; then
             clearline
             echo -n "Starting NTP from $ZANDER_TMP"
             rc_status -v 
   	  ZANDER_TMP1=$ZANDER_TMP
             echo -n "Update RTC "
             /sbin/clock -uw
             rc_status -v
   	  break
          else
             clearline
             echo -n "Can't find Timeserver"
             rc_status -u
          fi
      done       
      # ---------- End Protocol --------------------------------------------------
      if test $ZANDER_NTP_LOGDATEI != ""; then
        echo -n "with Data      : "			>> $ZANDER_NTP_LOGDATEI
         /sbin/clock					>> $ZANDER_NTP_LOGDATEI
         echo "Timeserver     : "$ZANDER_TMP1              >> $ZANDER_NTP_LOGDATEI
         echo                                              >> $ZANDER_NTP_LOGDATEI
      fi
      # --------- Cleaning -------------------------------------------------------
     rm -f /tmp/netdate.tmp
   fi   
   rc_reset
   rc_exit
  







vncserver (download)
   #! /bin/sh
   #
   # Author: Guenther Zander <g.zander@hamburg.de>
   #
   # /etc/init.d/vncserver		this Script
   # /usr/sbin/rcvncserver		Root-Link to this Script
   # /usr/X11R6/bin/vncserver	Program
   #
   #
   ### BEGIN INIT INFO
   # Provides: vncserver
   # Required-Start: $remote_fs $syslog
   # Required-Stop:  $remote_fs $syslog
   # Default-Start:  3 5
   # Default-Stop:   0 1 2 6
   # Description:    Start vncserver for remote control
   #	
   ### END INIT INFO
    
   test -r /etc/rc.config && . /etc/rc.config
   
   # Check for missing binaries 
   FOO_BIN=/usr/X11R6/bin/vncserver
   test -x $FOO_BIN || exit 5
   
   # Set HOME of root user
   HOME="/root"
   export HOME
   
   # Set ID for connections
   FOO_ID=1
   
   # Shell functions sourced from /etc/rc.status:
   #      rc_check         check and set local and overall rc status
   #      rc_status        check and set local and overall rc status
   #      rc_status -v     ditto but be verbose in local rc status
   #      rc_status -v -r  ditto and clear the local rc status
   #      rc_failed        set local and overall rc status to failed
   #      rc_failed <num>  set local and overall rc status to <num><num>
   #      rc_reset         clear local rc status (overall remains)
   #      rc_exit          exit appropriate to overall rc status
   #      rc_active	checks whether a service is activated by symlinks
   . /etc/rc.status
   
   # First reset status of this service
   rc_reset
   
   # Return values acc. to LSB for all commands but status:
   # 0 - success
   # 1 - generic or unspecified error
   # 2 - invalid or excess argument(s)
   # 3 - unimplemented feature (e.g. "reload")
   # 4 - insufficient privilege
   # 5 - program is not installed
   # 6 - program is not configured
   # 7 - program is not running
   # 
   
   case "$1" in
       start)
   	echo -n "Starting vnc server with terminal ID $FOO_ID "
   	
   	# Delete old PIDs
  	rm -f $HOME/.vnc/$HOSTNAME:$FOO_ID.pid 
   	
   	if [ -e $HOME/.vnc/$HOSTNAME:$FOO_ID.log ]; then
   	   cat $HOME/.vnc/$HOSTNAME:$FOO_ID.log >> /var/log/vncserver.log 2>&1
   	   rm -f $HOME/.vnc/$HOSTNAME:$FOO_ID.log 
   	fi
  
   	$FOO_BIN :$FOO_ID 2>&1
   	rc_status -v6
   	;;
       stop)
  	echo -n "Shutting down vnc server "
   	$FOO_BIN -kill :$FOO_ID 2>&1
   	
   	cat $HOME/.vnc/$HOSTNAME:$FOO_ID.log >> /var/log/vncserver.log 2>&1
   	rm -f $HOME/.vnc/$HOSTNAME:$FOO_ID.log 
   	
   	rc_status -v2
   	;;
       restart)
   	$0 stop
   	$0 start
   	rc_status
   	;;
       status)
   	echo -n "Checking for service vnc server on terminal ID $FOO_ID: "
   	## Check status with checkproc(8), if process is running
   	## checkproc will return with exit status 0.
   
   	# Return value is slightly different for the status command:
   	# 0 - service running
   	# 1 - service dead, but /var/run/  pid  file exists
   	# 2 - service dead, but /var/lock/ lock file exists
  	# 3 - service not running
   
   	# NOTE: checkproc returns LSB compliant status values.
   	checkproc $FOO_BIN
   	rc_status -v
   	;;
      *)
   	echo "Usage: $0 {start|stop|status|restart}"
   	exit 1
   	;;
   esac
   rc_exit
  





Talkback Area




Enter Own Comment