School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,483 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,767 people online right now. Registration is fast and FREE... Join Now!




Creating a repeating process

 
Reply to this topicStart new topic

> Creating a repeating process, How to create a poor-mans version of a Windows Service

no2pencil
Group Icon



post 27 Jul, 2008 - 12:30 AM
Post #1


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.
CODE

@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.
CODE

#!/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 thumbnail(s)
Attached Image
Go to the top of the page
+Quote Post


Register to Make This Ad Go Away!


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 


Lo-Fi Version Time is now: 11/8/09 04:03AM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month