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

How do I code an ftp MRENAME

Status
Not open for further replies.

Tison

Programmer
May 12, 1999
216
CH
I need an ftp script to do the following ;
mget *.DAT
mmove OR mrename *.dat *.old

I need the script to rename or move the files once they have been ftp'd. The reason is so that if the job runs again,it does not get the same files.
Any ideas ?
 
not sure if i am following, just script it ;]


ftp -in <<EOF
open $tohost
user $usrname $passwd
ascii
cd $destdir
lcd $sourcedir
mget *.dat
rm *.dat
bye
EOF
 
rather than the rm *.dat, you could use rename <origname.dat> <newname.whatever>

But if there are a lot of files you need to rename, I think you might need to do something with rexec, or schedule a cron job that can do the &quot;mass&quot; renaming after you get the dat files.

Does this help any?

 
Tison,

Can you not use the sunique command so that if a file being put has the same name, say &quot;newfile&quot;, the next time another file named &quot;newfile&quot; is put, it will be called &quot;newfile1&quot;.

-pd
 
Sorry but you are missing 1 point.
I do not know the file names , they vary every day.
I would like to rename them but cannot do &quot;rename *.dat *.old&quot;. That is what I am trying to achieve.
 
Here is a script I use to rename file extensions, but I don't know how you can run it from the ftp session. As I said in my previous post, you may have to schedule it through cron. Perhaps when you do your mget, the last thing you could do would be to do a put of a trigger file. Have a script look for that trigger file. When it finds it, run the code below to change the extension and delete the trigger file.

I got this code from someone on Tek-Tips:

Using pure ksh:

old_ext=pl
new_ext=pm
for file in $(ls *.$old_ext)
do
mv $file ${file%${old_ext}}${new_ext}
done
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top