LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-10-2012, 05:21 AM   #1
thbaig
LQ Newbie
 
Registered: Feb 2008
Posts: 11

Rep: Reputation: 0
delete remote files


Hi,
I have schedule my backup files to put on remote ftp.

Now I want to edit my schedule script to delete files older than 10 days.

Can I do so from my shell script?
 
Old 01-10-2012, 05:40 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
If the backup files contain the date specification in their name, it would be simple to cycle over the past 10 days date, that is every day you have something like
Code:
to_delete=$(date -d "10 days ago" +%Y%m%d)
and then use this date in the FTP delete statement
Code:
delete "${to_delete}_backup.tar.gz"
or whatever be the name of your archives. In this way you can manually delete the files older than 11 days and then start to delete the 10-days old file every day.

An alternative method would be to check the timestamp of the remote files. To do this you can try the FTP modtime command or even better you may try lftp as client software, that permits some coding (e.g. if/then constructs) and a finer control over the task to accomplish. HTH.
 
Old 01-10-2012, 05:40 AM   #3
allez
Member
 
Registered: Jul 2008
Location: Russia/Siberia/Krasnoyarsk
Distribution: SuSE, CentOS, FreeBSD
Posts: 77

Rep: Reputation: 21
Yes, you can do it, for example, with sed.

P. S. Hmm, it looks like I've misunderstood the topicstarter. I've decided that phrase "can I do so from my shell script?" is related to "edit my schedule script", not to "delete files older than 10 days".

Last edited by allez; 01-10-2012 at 05:51 AM.
 
Old 01-10-2012, 06:57 AM   #4
thbaig
LQ Newbie
 
Registered: Feb 2008
Posts: 11

Original Poster
Rep: Reputation: 0
thank you colucix

Dec_31_11_bkp.dmp.gz, will this work ? how should I set date token and place 10 days gap ?




Quote:
Originally Posted by colucix View Post
If the backup files contain the date specification in their name, it would be simple to cycle over the past 10 days date, that is every day you have something like
Code:
to_delete=$(date -d "10 days ago" +%Y%m%d)
and then use this date in the FTP delete statement
Code:
delete "${to_delete}_backup.tar.gz"
or whatever be the name of your archives. In this way you can manually delete the files older than 11 days and then start to delete the 10-days old file every day.

An alternative method would be to check the timestamp of the remote files. To do this you can try the FTP modtime command or even better you may try lftp as client software, that permits some coding (e.g. if/then constructs) and a finer control over the task to accomplish. HTH.
 
Old 01-10-2012, 07:22 AM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
You can use the date format specification to generate the whole filename, as in:
Code:
to_delete=$(date -d "10 days ago" +%b_%d_%y_bkp.dmp.gz)
then in your FTP batch session you simply do
Code:
delete $to_delete
 
1 members found this post helpful.
Old 01-10-2012, 07:54 AM   #6
codemaniac
Member
 
Registered: Feb 2010
Location: INDIA
Distribution: Slackware,Suse,Mint
Posts: 39

Rep: Reputation: 17
Code:
find . -type f -ctime +30  -ls  -exec rm -r {} \;

Should find your files 30 days old and delete from system ..


regards ,

Codemaniac
 
Old 01-10-2012, 08:08 AM   #7
thbaig
LQ Newbie
 
Registered: Feb 2008
Posts: 11

Original Poster
Rep: Reputation: 0
thank you very much colucix
 
Old 01-10-2012, 08:11 AM   #8
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
You're welcome!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
copy/delete files on remote server crypted Linux - Server 8 07-07-2010 02:56 PM
Can I delete files in /mnt/tmp? and Files in the trash can will not delete? M$ISBS Slackware 15 10-02-2009 11:56 PM
rsync not delete non existing files on remote server proNick Linux - Software 2 09-10-2008 03:47 AM
shell script to compare filese b/w local and remote and delete files from local serve dsids Linux - Networking 9 08-23-2006 07:20 AM
How to delete once whole files in a remote directory? backpacker Linux - Networking 1 03-10-2006 05:04 AM


All times are GMT -5. The time now is 01:22 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration