1834416 Members
1780 Online
110067 Solutions
New Discussion

Re: FTP and rename

 
Jessie Jackson
Occasional Contributor

FTP and rename

I have a cron job running daily that gets files from a remote system via ftp. I use the following mget *.txt . This gives me the files I need. The problem is that once the cron job runs to bring down the files, I also need to go back and rename the files to .old extensions.

I have tried doing rename *.txt *.old , all I get is no file or directory..

If anyone knows how I can get around this please let me know.

Thanks again.
6 REPLIES 6
Joseph C. Denman
Honored Contributor

Re: FTP and rename

You could try this:

cd /where/the/files/are
find *.txt | while read file
do
pre=`echo ${file} | cut -f 1 -d "."`
mv ${file} ${pre}.old
done

Hope this help....There are a million ways to skin a cat!!!!!


...jcd...
If I had only read the instructions first??
Alan Riggs
Honored Contributor

Re: FTP and rename

for FILE in *.txt
do
mv ${FILE} ${FILE%txt}old
done
Vincenzo Restuccia
Honored Contributor

Re: FTP and rename

#!/usr/bin/ksh
ll *.txt|awk '{print $9}'>file
while read file
do
mv ${file} ${file}.old
done
federico_3
Honored Contributor

Re: FTP and rename

I'd do like this:

for xx in *.txt
do
mv $xx ${xx%txt}old
done

Federico
Shannon Petry
Honored Contributor

Re: FTP and rename

If your renaming locally, then you need to look at the examples or use
>/usr/bin/sh
back=`pwd`
cd /location/of/files
for I in *.txt ; do
mv $I $I.old
cd $back
done

I think though you are referring to renaming on the FTP server, which is much more complex. First, you have to make a list of the files that you got from the server on the client.
Next you need to use expect, to run a batch rename, or issue a separate ftp command for each file to be renamed, as you can not use shell commands from within FTP!
Cheasy example.....
#/usr/bin/sh
cd /location/of/files
for I in *.txt ; do
eval while ! EOF ; do
ftp host
user
password
cd /destination
ren $I $I.old
bye
<done
done

Dont know if this works or not (PROBABLY NOT) but I think it gives you the concept anyway. Too much perl/CGI lately to think of shell scripting very clearly! :)

Regards,
Shannon
Microsoft. When do you want a virus today?
KLoeff
Frequent Advisor

Re: FTP and rename

ftp also does not like 2 dots in a name as in filename.txt.old