The UNIX and Linux Forums  


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
I need to write a shell script. lakshmanrk Shell Programming and Scripting 6 06-20-2007 07:00 AM
please Write a shell script rvrao77 Shell Programming and Scripting 6 11-16-2006 10:16 AM
need help to write shell script getdpg Shell Programming and Scripting 0 04-10-2006 11:30 AM
Help needed to write a shell script! sreedharsn Shell Programming and Scripting 3 10-11-2005 01:21 PM
Shell Script for Beginner aaron_fong Shell Programming and Scripting 3 07-18-2005 03:24 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 08-19-2002
duncan_glover duncan_glover is offline
Registered User
  
 

Join Date: Aug 2002
Posts: 3
Beginner trying to write a shell script!

Dear All,

I'm trying to write a shell script that continously checks a certain folder. When a file is placed in the directory securely copies the file to another server.

I've got the secure copying working, but I don't know how to contiously check a directory for a new file and then use that file to scp.

(The files contain a date & timestamp within the file name)

Any ideas???

Thanks,

A Complete Novice
  #2 (permalink)  
Old 08-19-2002
RTM's Avatar
RTM RTM is offline Forum Advisor  
Hog Hunter
  
 

Join Date: Apr 2002
Location: On my motorcycle
Posts: 3,039
One way would be to use cron. Check the man page for crontab and cron. Set your script to run every minute of every day.

If that isn't good enough, then you would have to check out inittab - this could start your process and if it died, restart it. Then inside your script you would have to loop (along with a sleep command - to wait say 10 seconds and then check the directory for files, if there are files, move them, loop to wait)

Scripting is only putting into a file what you would do manually - the only hard part is getting the logic of things you do without realizing it ( like listing a directory and not moving or deleting certain files).
  #3 (permalink)  
Old 08-19-2002
auswipe's Avatar
auswipe auswipe is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2001
Location: Wide Awake Wylie, Texas
Posts: 535
Here is one possible solution:


Code:

while true; do
  sleep 1
  if [ -f /path/to/some/file ]; then
    # Take some action
  fi
done

After reading RTM's post, you might want to up the time to 10 seconds, or 60 seconds or whatever is reasonable. 1 second is probably to tight of a loop.
  #4 (permalink)  
Old 08-19-2002
janr janr is offline
Registered User
  
 

Join Date: Jun 2002
Location: Amsterdam (Netherlands)
Posts: 142
Cool Some options

You can start a script from the cron e.g. every 1 minute or you write a script with is running for ever with a sleep in it (eg. sleep 60, means a sleep for 60 sec).

eg.


#!/bin/csh
foreach FILE (`find /<your path>/ -newer LastCheck -print`)
scp /<your path>/ $FILE /<new path>/$file
...... maybe some more code ......
end

touch LastCheck

exit


To initialize this way you need to create the 'LastCheck' the first time by hand by `touch LastCheck`

every time you run this script it copies all files who are newer then the file LAstCheck to the new location

See also the find man page:
http://docs.sun.com/?q=find&p=/doc/8...9vek55d&a=view
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 11:03 PM.


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