Page 1 of 1

Creating a repeating process How to create a poor-mans version of a Windows Service Rate Topic: -----

#1 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5355
  • View blog
  • Posts: 27,314
  • Joined: 10-May 07

Post icon  Posted 27 July 2008 - 01:30 AM

Creating a repeating process

How to create a poor-mans version of a Windows Service (or Cron job):

In this scenario we need to check for the existence of two files & log the results. The server is running Windows Server 2003, & the logging will be handled by Korn shell scripts running under MKS Toolkit.

Our 1st script will be the engine. It's job is to launch the 2nd job every 300 seconds or 5 minutes.
@echo off

cls
echo ==================================
echo PLEASE DO NOT CLOSE THIS WINDOW :
echo LOGGING IN PROCESS...
echo ==================================
:start
sh log_files.ksh
sleep 300
goto  :start



As long as this program is running, it is looping through, restarting over, which relaunches the 2nd program or script.

While this code is running, you'll see a screen like the following :


Every 300 seconds it will launch the 2nd script, which is checking for the existence of two files. This 2nd program can be replaced by whatever recurring even that you need.
#!/bin/ksh

line="---------------------------------------------"
logfile="temp.log"
File1=//server/g$/downloads
chk=0

if [ -f ${logfile} ]; then
else
  touch ${logfile}
fi

echo ${line} >> ${logfile}

if [ -f ${File1}/upload.tmp ]; then
  chk=1
  date >> ${logfile}
  ls -l ${File1}/upload.tmp >> ${logfile}
fi

if [ -f ${File1}/trigger.go ]; then
  chk=1
  date >> ${logfile}
  ls -l ${File1}/trigger.go >> ${logfile}  
fi

if [ ${chk} -eq 0 ]; then
  date >> ${logfile}
  echo upload.tmp nor trigger.go currently exist >> ${logfile}
fi

echo ${line} >> ${logfile}



Again, the 2nd script is irrelevant, & can be replaced by anything you choose as useful. What is important is that the 1st script is constantly looping, & running the 2nd script or program multiple times.

Attached image(s)

  • Attached Image


Is This A Good Question/Topic? 0
  • +

Page 1 of 1