Help with FTP mdelete


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with FTP mdelete
# 1  
Old 04-10-2012
Question Help with FTP mdelete

Hi, I have some backup scripts running.
They allocate the files in separated folders, according to the current day.
(01, 02, 03...., 31)
After 1 month, the "cycle" starts again, and the files are uploaded to the folder 01, 02...
When that happens, I want the previous files to be deleted, so that I can put the new ones.

The backup script looks something like this:

Code:
#!/bin/bash
FILE="ccih-`date +%Y-%m-%d_%Hh%Mmin`"
DAY="`date +%d`"
MONTH="`date +%m`"

ftp -ni $FTPSERVER <<FIM
user $USERNAME $PASSWORD
lcd $LOCALDIR
cd $DAY
binary
mput $FILE.tar.bz2
bye
quit
FIM


I want to use mdelete to delete the older files, so it would look something like
Code:
mdelete ccih-2012-<??? WILDCARD THAT INDICATE DIFFERENT FROM THIS MONTH???>-*min.tar.bz2

I would appreciate your help.. I've tried every kind of regex...
Thanks in advance...

Last edited by Corona688; 04-10-2012 at 06:00 PM.. Reason: code tags for code, please
# 2  
Old 04-10-2012
Why not just upload after deleting, instead of deleting everything except the one just uploaded?
# 3  
Old 04-10-2012
Further to Corona688's excellent post.
If you have three separate runs of ftp (directory run; delete run; transfer run) you can first find out which files (if any) are present in the target directory, then delete them in a controlled manner if required, then transfer the new files.

Btw. In the script posted your mput will only transfer one file (if it exists ... which is unlikely).

Last edited by methyl; 04-10-2012 at 08:45 PM..
# 4  
Old 04-11-2012
Hi!
Corona688, methyl
This script transfers only one file each time it runs, the problem is that it runs several times a day.
It would be a perfect solution to delete everything on the folder before uploading, but I don't want to delete everything, I just want to delete files that were created "last" month.
Supposing it is the third time today that the script runs, it would delete the first and second copies I've done today, while I just wanted to delete copies from previous months.

I was thinking about using a wildcard that indicates difference, but I've tried several methods and it didn't work... Looks like only the wildcard "*" is permitted in this case (correct me if I'm wrong).

I've also tried to use RegEx, but it didn't work.

The third "solution" I've been thinking about is to use a similar way this post explains
unix . com/shell-programming-scripting/24085-how-get-previous-month-files.html
(I'm sorry, I can't post url formatted, since I'm a new user)
(Calculating the last month, and deleting last month files with mdelete and * wildcard)
Code:
#!/bin/ksh

year=$(date +%Y)
month=$(date +%m)

month=$(($month-1))
if [ $month -lt 1 ]; then
        year=$(($year-1))
        month=12
fi
echo $year$month

But my knowledge is very limited when it comes to linux, and I couldn't make it work. I think it must have something to do with the
Code:
#!/bin/bash

I'm using...

Last edited by rafaces; 04-11-2012 at 09:32 AM.. Reason: Malformatted code
# 5  
Old 04-11-2012
Code:
echo $year$month

If you want the date in the form YYYY-MM , Try:
Code:
printf "%04d-%02d\n" $year $month

Beware. There is a design issue in the script. When there are less days in this month than last month the process will not run for the day numbers which do not exist this month.

You may find it easier to break the process down into separate modules.
1) FTP: Get a directory listing of the remote directory
2) SHELL: Process the directory listing to find files not dated this month
3) FTP: Delete the surplus files (if any are found)
4) FTP: Transfer the new file


Footnote: FTP is not Shell. It knows nothing about regex . Some versions have trouble with complex filenames.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

FTP log only shows FTP LOGIN FROM entry?

OS: Solaris 9 Configuration /etc/syslog.conf daemon.debug /etc/inetd.conf ftp stream tcp6 nowait root /usr/sbin/in.ftpd in.ftpd -A -l -d Found the ftp.log only generate those entries from other servers/hosts. Can we trace on all ftp entries either from/to the server? ... (6 Replies)
Discussion started by: KhawHL
6 Replies

2. HP-UX

[Solved] Unable to rename file in ftp server .Net:FTP perl

Hello All, I am trying to connect to ftp server and get the files. Also i need to rename the file in other ftp dir. rename method is not allowing me to rename the file in other dir. When i tried copy command by using net::FTP:FILE then perl says it is not installed. Can some body help me to... (2 Replies)
Discussion started by: krsnadasa
2 Replies

3. AIX

ftp connect in passive mode , ftp settings

how to connect to ftp server in passive mode? ftp server.abc and how can i see ftp settings, doesn't exist some ftpd.conf there is some other file where i check the options and configurations of ftp server? Thanks (3 Replies)
Discussion started by: prpkrk
3 Replies

4. Shell Programming and Scripting

Automated FTP script using .netrc to multiple FTP servers

Hi all, I'm using the following script to automated ftp files to 1 ftp servers host=192.168.0.1 /usr/bin/ftp -vi >> $bkplog 2>&1 <<ftp open $host bin cd ${directory} put $files quit ftp and the .netrc file contain machine 192.168.0.1 login abc... (4 Replies)
Discussion started by: varu0612
4 Replies

5. Shell Programming and Scripting

passing parameter to ftp script from output of another ftp

Hi, I have a ftp script which first gets all the file names and echo's the latest file. I'm using another ftp command sets to get the file name given by first ftp. The problem is the parameter is not accepted by second ftp. The error message i'm getting is > Rename Temp File calloc:ICMP... (5 Replies)
Discussion started by: ammu
5 Replies

6. UNIX for Advanced & Expert Users

Using FTP to check whether file is completely FTP... plz find the description below

Hi, We have some clients who will place huge files in to one of the remote server. And the shell script written in our local server to retrieve client files (using FTP) placed on one of the remote server of ours by clients. My question Is there any FTP command/script to check from my local... (1 Reply)
Discussion started by: nmsrao
1 Replies

7. UNIX for Dummies Questions & Answers

mdelete command in FTP

What I need to do is ftp some files on a remote server, but before postong the file need to delete any existing file from the path on the remote dir. I am using the mdelete command for the same as follows : open server_name user_id password prompt off ascii cd /test mdelete * IF the... (3 Replies)
Discussion started by: rohini
3 Replies

8. Shell Programming and Scripting

mdelete

Hello, I have a big problem with mdelete and I don't know further. In my shell script mdelete filename1 filename2 filename3 etc. does not delete alle files. Here's the log: -rw-r--r-- 1 root root 1 Mar 7 14:40 corrado -rw-r--r-- 1 root root 1 Mar 7 14:40... (1 Reply)
Discussion started by: killmatic
1 Replies

9. Shell Programming and Scripting

mdelete power

hi to all! im using hp-ux 10.2 is it posible for the mdelete command to execute on the root directory if it did not find any file on the specified sub-directory? this is my sample script USER=root PASSWD=root cd /u01/app/oralog/arch ftp -n 192.119.10.3 user $USER $PASSWD prompt... (2 Replies)
Discussion started by: gunsbong
2 Replies

10. UNIX for Advanced & Expert Users

MVS->Unix FTP : Using chmod as part of FTP.

We are transferring file from mainframes to unix, & in FTP process itself we would like to set access rights for unix machine. Has anyone used chmod command in association with site command in ftp? How it should be used? Thanks in advance. (1 Reply)
Discussion started by: videsh77
1 Replies
Login or Register to Ask a Question