I need to archive the older than 30 day file to another uinx server.I have wrote the below uinx script.
for LOOK_DIR in /TempFiles
do
for FILE in `find ${LOOK_DIR} -mtime -30 -exec ls {} \;`
do
echo ${FILE} >> file_list ## This file will have the list of files copied and removed
done
done
#*********************************************************#
# Copy the files from share drive to Unix server #
#*********************************************************#
ArchFiles_ftp_put
ArchFiles_ftp_put()
{
/usr/bin/ftp -v -n << EOF > ${FTP_LOG_FILE}
open ${ARCH_SERVER}
quote USER ${ARCH_USERID}
quote PASS ${ARCH_PASSWORD}
passive
ascii
prompt off
cd ${REMOTE_DIR}
lcd ${DATA_DIR}
mput ${FILE}
bye
EOF
EOF
}
When I verify the file list form above script, I am getting file directory along with the file name,
Can you please suggest me the how can I select only older than 30 day files
based on the above code we will get only file name.
but when i am calling ftp function i getting file name along with directory
can you please suggest me where i need to update the script
At first, you should not ignore mod comments or PMs about using code tags. Because when you hit 20 points, your account will be set to "read-only" automatically. In worst cases it can result in a ban.
Iterating through a list of files and then opening a ftp connection for each of them, I would suggest, you just move the files to be transferred into a different directory and just ftp them with mput * all at once which is much more effective, if space on disk permits this.
Or if possible, think about using scp or rsync and move them by this. ftp is not encrypted and does not offer as much options.
Also 2 times EOF is not needed - once is enough. i<="$FILE� does not make sense to me as you are comparing a number with a string.
basename $FILE # This will give you the filename onle
for LOOK_DIR in /TempFiles
do
for FILE in `find ${LOOK_DIR} -mtime -30 -exec ls {} \;`
do
echo ${FILE} >> file_list ## This file will have the list of files copied and removed
ArchFiles_ftp_put ${FILE}
done
done
#*********************************************************#
# Copy the files from share drive to Unix server #
#*********************************************************#
#ArchFiles_ftp_put
ArchFiles_ftp_put()
{
/usr/bin/ftp -v -n << EOF > ${FTP_LOG_FILE}
open ${ARCH_SERVER}
quote USER ${ARCH_USERID}
quote PASS ${ARCH_PASSWORD}
passive
ascii
prompt off
cd ${REMOTE_DIR}
lcd ${DATA_DIR}
mput $1
bye
EOF
EOF
}
Hi ,
Have made some changes in the code and below is working fine for me.
#!/bin/ksh
ARCH_SERVER=xxxxxx
ARCH_USERID=xxxxxxx
ARCH_PASSWORD="xxxxxxx"
REMOTE_DIR=xxxxxxx
FTP_LOG_FILE=xxxxxxx/TEST/FTPLOGa
echo > $FTP_LOG_FILE
#*********************************************************#
# Copy the files from share drive to Unix server #
#*********************************************************#
ArchFiles_ftp_put()
{
/usr/bin/ftp -v -n << EOF >> ${FTP_LOG_FILE}
open ${ARCH_SERVER}
quote USER ${ARCH_USERID}
quote PASS ${ARCH_PASSWORD}
passive
ascii
prompt off
cd ${REMOTE_DIR}
lcd ${DATA_DIR}
mput ${FILE_NAME}
bye
EOF
}
for LOOK_DIR in /cb/home/n421522/TEST
do
for FILE in `find ${LOOK_DIR} -mtime -30 -exec ls {} \;`
do
echo ${FILE} >> file_list ## This file will have the list of files copied and removed
DATA_DIR=`dirname ${FILE}`
FILE_NAME=`basename ${FILE}`
ArchFiles_ftp_put ${FILE}
done
done
You can also add date to the FTP_LOG_FILE generated to retrive it for longer time.
I wrote the scipt as below:
#!/bin/ksh
set -x
ArchFiles_ftp_put()
{
/usr/bin/ftp -v -n << EOF > ${FTP_LOG_FILE}
open ${ARCH_SERVER}
quote USER ${ARCH_USERID}
quote PASS ${ARCH_PASSWORD}
passive
ascii
prompt off
cd ${ARCH_REMOTE_DIR}
lcd ${DATA_DIR}
mput ${FILE_NAME}
bye
EOF
EOF
}
#**************************************************#
# Main #
#**************************************************#
if [ $# -ne 5 ]
then
echo "Invalid number of parameters::"
echo "Please pass 5 parameters in following order:Host Name, UserID, Password, RemotDir and project dir::"
exit 1
fi
#***************************************************************#
# Set "FTP" variables #
#***************************************************************#
ARCH_SERVER=$1
ARCH_USERID=$2
ARCH_PASSWORD=$3
ARCH_REMOTE_DIR=$4
PROJ_NAME=$5
#**************************************************#
# Set directory values #
#**************************************************#
for LOOK_DIR in /tmp/arch_files/
do
for FILE in `find ${LOOK_DIR} -mtime -30 -exec ls {} \;`
do
echo ${FILE}>> file_list ## This file will have the list of files copied and removed
DATA_DIR=`dirname ${FILE}`
FILE_NAME=`basename ${FILE}`
ArchFiles_ftp_put ${FILE}
done
done
FTP_LOG_FILE="/tmp/Log/FTP_put_Archive_Files.log"
echo "Starting...">$FTP_LOG_FILE
When i ran the above scipt i am geeting below error message, can you please check the script.
---------- Post updated at 07:21 AM ---------- Previous update was at 05:05 AM ----------
Thanks zaxxon and aashish
i have resolved the problem.. as per the zaxxon suggestion I moved the older than the 30 day file to another folder and I called mput option it's working fine.
Thanks you so much for your suggestion s and code.
Thanks for update...Rather than using ftp for each file why don't you zip all the files together and ftp the compressed file only.
This will be much more effective !