How archive the older than 30 day files to another unix server


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How archive the older than 30 day files to another unix server
# 1  
Old 08-07-2012
How archive the older than 30 day files to another unix server

I need to archive the older than 30 day file to another uinx server.I have wrote the below uinx script.
Code:
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


Moderator's Comments:
Mod Comment Please use code tags next time for your code and data.

Last edited by zaxxon; 08-07-2012 at 07:36 AM.. Reason: code tags
# 2  
Old 08-07-2012
So your problem is to cut off the path from the filename?

Edit:
I just saw you are using -30. Why not try +30? Did you write that script?

Last edited by zaxxon; 08-07-2012 at 07:48 AM..
# 3  
Old 08-07-2012
yes i need to cut off form the path
# 4  
Old 08-07-2012
Code:
...
echo ${FILE##*/} >> file_list ## This file will have the list of files copied and removed
...

# 5  
Old 08-07-2012
as per you note i have include the +30

Code:
echo ${FILE##*/} >> file_list

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


Moderator's Comments:
Mod Comment Please use code tags next time for your code and data.

Last edited by zaxxon; 08-07-2012 at 08:38 AM.. Reason: code tags
# 6  
Old 08-07-2012
I asked you via PM to use code tags, sent a video with a guide and added a mod comment. You got another PM with a guide.

Quote:
based on the above code we will get only file name.
That's what you asked for.

Quote:
but when i am calling ftp function i getting file name along with directory
Define the variable after writing cut off names to the file:
Code:
...
echo ${FILE##*/} >> file_list ## This file will have the list of files copied and removed
FILE=${FILE##*/}
...

# 7  
Old 08-07-2012
Quote:
Originally Posted by zaxxon
I asked you via PM to use code tags, sent a video with a guide and added a mod comment. You got another PM with a guide.


That's what you asked for.


Define the variable after writing cut off names to the file:
Code:
...
echo ${FILE##*/} >> file_list ## This file will have the list of files copied and removed
FILE=${FILE##*/}
...


Thanks zaxxon for the qick respose....

I have one more question

When I doing the less than 30 day of file. so I am getting the multiple files.

I need to iterate the loop can you help on this

I have code like this can you please check this.

Code:
for ( i=1 ; i<="$FILE” ; i++ ))
     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}
          bye
          EOF
          EOF
     }
done


Moderator's Comments:
Mod Comment Please use code tags next time for your code and data.

Last edited by zaxxon; 08-07-2012 at 10:31 AM.. Reason: code tags....
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need command/script to archive files older than

I need to find a way to archive all files older than a given date but there are some conditions that are making it difficult for me to find the correct command: Linux based system (RH5) there are multiple layers of directory depth I need to search each file should be tar'd in it's original... (1 Reply)
Discussion started by: KaosJedi
1 Replies

2. Shell Programming and Scripting

Grep files older than 1 day

I thought that this would work for grep'ing files older than 1 day. ps -o etime,pid,user,args -e|awk '/^+-/'|sort -t- -n -k 1,1 |grep qdaemon |grep /usr/bin/ksh But, it is not grep'ing any of files (i.e. below) older than 1 day. d_prod 33757970 61999560 0 Oct 27 - 0:00... (8 Replies)
Discussion started by: Daniel Gate
8 Replies

3. Shell Programming and Scripting

Sftp - 1 day older files count

Need to write a shell script on AIX box which will connect to different servers using SFTP and get the file count of only 1 day older files. (purging list) How to achieve this? On local server we can use: find <path> -type f -mtime +1 But how to do it in case of SFTP? Please advise. Thanks... (9 Replies)
Discussion started by: vegasluxor
9 Replies

4. UNIX for Advanced & Expert Users

Help with get/mget from FTP server with files older than 10 minutes

Hi! I am new to unix and this forum as well.. Can someone please help me : I want to "get/mget" files which are older than 10 minutes from a remote FTP server like "ftp.com". After getting the files to local unix server say "Prod.com" , i need to delete only those files from ftp.com which... (4 Replies)
Discussion started by: SravsJaya
4 Replies

5. Shell Programming and Scripting

scp files that are 3 days older from remote server-

hello, i am trying to get a list of files to be scped from the remote server by running the below in my local unix server ( note - there is a passwordless connectivity setup made between the local and remote server) and, we use KSH. --- ssh $scp_host "find /a/b/c/*/ -iname "$remote_file"" >... (4 Replies)
Discussion started by: billpeter3010
4 Replies

6. Shell Programming and Scripting

Find and delete files and folders which are n days older from one unix server to another unix server

Hi All, Let me know how can i find and delete files from one unix server to another unix server which are 'N' days older. Please note that I need to delete files on remote unix server.So, probably i will need to use sftp, but question is how can i identify files and folders which are 'N'... (2 Replies)
Discussion started by: sachinkl
2 Replies

7. Shell Programming and Scripting

Find the number of files older than 1 day from a dir

Hello All, I need to write a script/command which can find out the number of .csv files residing in a directory older than 1 day. The output should come with datewise (means for each date how many files are there). I've this command, but this command gives the total number of files. It's... (10 Replies)
Discussion started by: NARESH1302
10 Replies

8. UNIX for Dummies Questions & Answers

sample script to archive & move previous day syslog files

hi all. Please help me with archiving previous day syslog files. the files have no extension and have the format YYYY-MM-DD. I want to archive the file then move it to some other machine. thanks. (2 Replies)
Discussion started by: coolatt
2 Replies

9. Shell Programming and Scripting

Deleting / finding files older than X days missess a day

Hi When trying to find and delete files which are, say, 1 day, the find command misses a day. Please refer the following example. xxxd$ find . -type f -ctime +1 -exec ls -ltr {} \; total 64 -rw-rw-r-- 1 oracle xxxd 81 Apr 30 11:25 ./ful_cfg_tmp_20080429_7.dat -rw-rw-r-- 1... (4 Replies)
Discussion started by: guruparan18
4 Replies

10. Shell Programming and Scripting

Archive files older than 30days

I have files with the names BARE01_DLY_MKT_20060724 in the source directory /biddf/ab6498/dev/ctl. I need to archive folders older than 30days. Like if i have a file named BARE01_DLY_MKT_20060622 I need to move this to /biddf/ab6498/dev/ctl/archive. How can I do this. One more thing is that I... (8 Replies)
Discussion started by: dsravan
8 Replies
Login or Register to Ask a Question