In sftp script to get files, I have to rename all the files which I am picking. Rename command does not work here. Is there any way to do this?
I am using #!/bin/ksh
For eg:
sftp user@host <<EOF
cd /path
get *.txt
rename *.txt *.txt.done
EOF
I understood the awk command but not the sed. Anyways, I tried using both the commands, but they are not renaming the files on remote server, even though the files are fetched.
I also had a similar requirement and found that we cannot rename multiple files in the remote server using wild character and below are the steps which i followed to achieve this.
First you need to receive the files.
Generate rename command for the files which you have received.
Again connect to the remote server passing the rename command as input.
Sample code which I used:
#!/usr/bin/ksh
###The below shell script is used to receive and rename files in remote server, and below is the steps followed.
###First you need to receive the xml files.
###Generate rename command for the files which you have received.
###Again connect to the remote server passing the rename command as input.
# Shell script to receive xml files from remote machine #
cd /home/oracle/XML_FILES/ ## local directory
#Clear renamescript.txt file at each execution#
cat /dev/null > /home/oracle/FTP_SCRIPTS/renamescript.txt
sftp userid@remote_server <<END
cd /home/user/XML ## remote directory
prompt
mget *
bye
END
# For generating rename script #
ls /home/oracle/XML_FILES/ > /home/oracle/FTP_SCRIPTS/count
for i in `cat /home/oracle/FTP_SCRIPTS/count`
do
{
print `echo rename /home/user/XML/$i /home/user/XML_BACKUP/$i` >> /home/oracle/FTP_SCRIPTS/renamescript.txt
};
done
# To rename files in remote machine #
sftp userid@remote_server < /home/oracle/FTP_SCRIPTS/renamescript.txt
bye
#End of script