The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
infinite loop to check process is running yabai Shell Programming and Scripting 12 10-23-2008 09:56 AM
the given code goes in infinite loop and does not increment variable i mrityunjay22 Shell Programming and Scripting 6 12-26-2007 02:20 AM
Infinite Loop in Autosys while running a shell script, Manual run is fine sharmagaurav_2k Shell Programming and Scripting 2 09-04-2007 08:20 AM
ls command in infinite Loop umakant SUN Solaris 3 07-17-2007 01:25 AM
high priority thread contains an infinite loop rvan High Level Programming 0 02-14-2007 09:30 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-21-2008
Raamc Raamc is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 31
Running a script in INFINITE LOOP

Hi All,

I have a requirement as below.

I supposed to get a file from Source system once in a month. But we dont know when the source system will send the file. My script has to wait for that file in LOOP once it gets the file then it has to FTP the file.

I thought of scheduling the job once in a daily but "My requirement is to get the file ASAP else it will expire from the source system"

So can any one suggest me the best solution for this?

Thanks in Advance,

Raamc.
  #2 (permalink)  
Old 10-21-2008
Wotan31 Wotan31 is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 17
I don't like loops. Why not have a cron job that runs every hour, checking for the presence of this file?

If once an hour isn't frequently enough, just do a script that runs in a loop and start it with "nohup" so it continues to run even when you log out.
  #3 (permalink)  
Old 10-21-2008
Raamc Raamc is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 31
Smile

Running the script for every hour by using the CRON is suitable for my requirement.

Thanks for the reply.

Can i have a code for scheduling the script for every hour ,31 days in a month and 365 days a year?

And, CRON is a part of UNIX OS or do we need a buy any special licence for that?

Raamc.
  #4 (permalink)  
Old 10-21-2008
danmero danmero is offline Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,420
Quote:
Originally Posted by Wotan31 View Post
I don't like loops. Why not have a cron job that runs every hour, checking for the presence of this file?
And if the cron die ?
1. add a cron job to check if the script is running, if not start the script.
2. The script should be something like:
Code:
#!/bin/sh
# Loop forever
while :
do
# Check if cron is running
  test $(ps ax | grep -c "[c]ron") -gt 0 || /etc/init.d/crond start
#Do whatever you have to do
  echo "Hello world"
# Sleep one hour
  sleep 360
done # Start over
  #5 (permalink)  
Old 10-21-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
You can cron every minute if you need it. crontab entry
Code:
* * * * * [[ -f /path/to/file/filename ]] && mv /path/to/file/filename /path/to/storage/
This is not a great idea because if the file is ftp'ed to your system you may get a partial file if ftp has not completed. Change the ftp process to transfer a small dummy file after the real file is already there. Then search for the dummy file and then mv both files if you find the dummy.
  #6 (permalink)  
Old 10-21-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
cron is part of unix, you system has to have crond running. Try man crond
Code:
00 */1 * * * < comannd goes here>
every hour.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:38 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0