Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

'Schedule' linux command

Status
Not open for further replies.

ZK

MIS
Oct 2, 2000
27
GB
Hi there,

I'm completely new to programming, operating systems and linux, so any help will be much appreciated. I have a very tight deadline and need some help from you experts!

Does anyone know how to write a linux command/program that checks a folder (on a linux server) for files, and if those files exist, execute an ftp script? It needs to check the folder at regular intervals (example: every 2 minutes).

Thanks a lot!
ZK
 
Sure, you would use the cron daemon, type "man cron" at a prompt for information.

To check for the files, use perl. It's easy, forgiving, and comes with an ftp package.

"perl -v" will tell you if it's on your system, and the Perl Cookbook by Oreilly is an excelent read, along with learning perl.

will tell you how to download perl and NET::FTP to get up and going, if it's not on your system.

There are other languages to use, but I think that Perl will be your best bet to do it.

MWB As always, I hope that helped!

Disclaimer:
Beware: Studies have shown that research causes cancer in lab rats.
 
If you need help with the Perl, don't forget TT's Perl forum.




keep the rudder amid ship and beware the odd typo
 
HI
try to use /etc/crontab file. it is a schedular file in linux. it looks like 1 3 * * ... file to be executed.
the first number indicates the minues second one indicates hours third one indicate date and fourth one indicates no of month and last one indicates the year .
means on that day the file will be executed.

bye
santosh
 
Also take a look at the FAQ's in the TT's General Unix forum
There are some hints there to help you ..
You may have to wrap it in another script to check for the existance of the files ....

but you could do something like this ....

Dont quote me on the syntax .. NOT TESTED.
#!/bin/sh
# ----------------------------------------
# FTP script ---- Laurie Baker
#
# This is where you specify the settings for the ftp
# Changes will be: host,user & password
# ----------------------------------------
host=nnn.nnn.nnn.nnn
user=USER
password=PASSWORD
mysource=/some/directory/where/your/files/maybe
destination=/path/to/somewhere
errorlog=/path/to/ftperror.txt
#------------------------------------
echo "-----------------------------" >> $errorlog
echo `date` >> $errorlog
echo "-----------------------------" >> $errorlog
if (-e $mysource/*.doc);
then
ftp -v -n $host << EOF >> $errorlog
user $user $password
prompt
ascii
cd $destination
lcd $mysource
mput *
quit
EOF
print &quot;Proces complete&quot; # Just for test
done
fi


Then just call it every 2 minutes with cron:

crontab -e ..... add this line and ESC :wq!

60/30 * * * * /home/scripts/ftpit.sh > /dev/null 2>&1

Good Luck
Laurie.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top