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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FTP in a cron script 1

Status
Not open for further replies.

DanAuber

IS-IT--Management
Apr 28, 2000
255
FR
I want to create a script that moves a file from one Unix server (SCO) to another (HP) each night.<br>Can anyone tell me if this is possible using FTP and what the syntax of the FTP command in the script eould look like ??<br>I can FTP interactively - but not sure how to use it in scripts...<br><br>thanks for any advice<br><br>Dan <p>Dan Auber<br><a href=mailto:DanAuber@aol.com>DanAuber@aol.com</a><br><a href= Auber's Home Page</a><br>
 
Here's an extract from a script we use to copy some data on a daily basis to a different machine:<br><FONT FACE=monospace><br># Find files created in the last 24 hrs, and put them in an archive.<br>FILES=&quot;`find . -type f -mtime -1 -print`&quot;<br><br>for File in ${FILES}<br>do<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ftp -n otherbox &lt;&lt;endofdata&nbsp;&nbsp;&gt;/dev/null<br>user <i>username password</i><br>binary<br>cd <i>/target/directory</i><br>put $File $File_To<br>put $File $File<br>bye<br>endofdata<br></font><br><br>It doesn't do any checking for errors, so you may want to add this in.&nbsp;&nbsp;Hope this helps.
 
or you can use the the .netrc facilityCreate a <b>~/.netrc</b> filein the file write<FONT FACE=monospace><b>machine</b> server_name <b>login</b> your_user <b>password</b> your_password<b>macdef init</b>your commands go here...your commands go here</font>Then you can use<b>ftp server_name</b>The server_name must be <b>exact</b>I hope it works
 
Yeah ,both AndyBo's and ElgisRamon's methord are useful .<br>No I write the exact sample for you . It works fine in<br>my Solaris2.5 platform .<br><br>Step 1:<br>In your corresponding crontab file , add this line:<br>0 5 * * * cp ftputfile .netrc;ftp -i HP-machine&gt;&gt;ftpputlog<br>#It will work at 5am each day and record your ftp processing<br>to ftpputlog file<br><br>Step 2: Write the autorunning ftpputfile:<br># Find files created in the last 24 hrs, and put them in an #archive.<br>FILES=&quot;`find . -type f -mtime -1 -print`&quot;<br><br>machine Your-HP-machine<br>login username<br>password your-password-in-HP<br>macdef init<br><br>bin<br>hash<br>cd /HPmachine-your-dir<br>for File in $FILES<br>&nbsp;do<br>&nbsp;&nbsp;&nbsp;put $File $File<br>&nbsp;done<br>quit<br><br>However , I'd like to compress and tar those files first and<br>then put them to the backup machine . <br>Notice ,you can adjust the ftpputfile to match your need .<br><br>Hope it helpful for you,<br><br>James<br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top