Computing.Net > Forums > Unix > need a script which runs infinately

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

need a script which runs infinately

Reply to Message Icon

Name: yash_yadav1
Date: October 14, 2008 at 05:35:30 Pacific
OS: SUN-OS
CPU/Ram: NA
Product: NA
Comment:

i need a script which shd run for infinate loop and it should poll the current directory (excluding sub-directories)and whenevr a new *.txt comes, it shd call other script say temp.sh with this new *.txt as argument and once the processing is done, it shd poll again.



Sponsored Link
Ads by Google

Response Number 1
Name: Vasanth
Date: October 14, 2008 at 07:00:20 Pacific
Reply:

You use cron job for this .

Vasanth


0

Response Number 2
Name: yash_yadav1
Date: October 16, 2008 at 04:34:55 Pacific
Reply:

what does cron job mean?
can you explain me how to do that?


0

Response Number 3
Name: nails
Date: October 16, 2008 at 07:19:12 Pacific
Reply:
0

Response Number 4
Name: yash_yadav1
Date: October 17, 2008 at 05:26:15 Pacific
Reply:

i did go through the link...
bt i cldn't get hw exactly we can use tht.


0

Response Number 5
Name: nails
Date: October 17, 2008 at 09:38:28 Pacific
Reply:

It's simple enough. Assume your test program, test.ss, looks like this:


#!/bin/ksh

# test.ss
# your PATH maybe different
PATH=/usr/bin:/usr/sbin:/sbin:/usr/sfw/bin:/usr/sfw/sbin

# your current directory will be different
cd /home/nails/mytmp
ls -1 *.txt 2> /dev/null|while read file
do
echo "$file"
# execute what you want to
#
rm "$file"
done

cron, if set up correctly, can execute this ever minute. Here is how to do it.

# it's always a good idea to save your user's cron file:

crontab -l > mycronfile

Now, place this line in mycronfile:

* * * * * /path/to/test.ss

This will execute test.ss every minute.

To implement the cron command:

crontab < mycronfile

execute

crontab -l

to ensure the command now exists in cron.

Not every Unix user is set up to execute cron. If you can't, the system administrator can grant users cron permissions.




0

Related Posts

See More



Response Number 6
Name: Randi
Date: January 4, 2009 at 11:09:14 Pacific
Reply:

In windows, I would do something like the following. In UNIX something similar ? (This is written in biterscripting (http://www.biterscripting.com) , but any scripting language will do.)

Let's assume that you are looking for .txt files in C:/mydir.

var str currentFileList
var str oldFileList

while (true)
do
lf -n "*.txt" "C:/mydir" > $currentFileList
if ($currentFileList <> $oldFileList)
# File list has changed - do something
endif

set $oldFileList = $currentFileList # for next time
sleep 5 # Sleep 5 seconds
done

Hope this helps.

Randir Randwa


0

Sponsored Link
Ads by Google
Reply to Message Icon

Script to find whether li... extra entry when joining ...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: need a script which runs infinately

Shutdown remotely by a script-Linux www.computing.net/answers/unix/shutdown-remotely-by-a-scriptlinux/5225.html

script to change file names www.computing.net/answers/unix/script-to-change-file-names/8327.html

help for a primitive icq script? www.computing.net/answers/unix/help-for-a-primitive-icq-script/5039.html