The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
scp automated script gholdbhurg UNIX for Advanced & Expert Users 5 10-27-2008 01:23 AM
Automated shtudown joe1967 Shell Programming and Scripting 5 05-29-2007 08:04 PM
Automated FTP shauche UNIX for Advanced & Expert Users 11 07-11-2002 02:08 AM
FTP automated? n9ninchd UNIX for Dummies Questions & Answers 6 05-18-2001 10:21 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-03-2007
sangfroid sangfroid is offline
Registered User
  
 

Join Date: May 2007
Posts: 5
automated ftp.

Hi
I am trying to delete some specific files ( files other than created today) from the server on a cron basis. I wrote a small script, but I am stuck up in how to delete only specific files.


#!/usr/bin/expect -f

set IP [lindex $argv 0]
set timeout -1
spawn ftp $IP
expect ):
send "username\n"
expect word:
send "password\n"
expect ftp>
send "prompt\n"
expect ftp>
send "passive\n"
expect ftp>
send "cd logs/\n"
expect ftp>


After this I am stuck up. It is because I want to delete files with old dates ie, I don't want to delete the file dated today.


The files are like logfile-070501,logfile-070502 and so on..

I cannot run the command "rm logfile-0705*" ( as it will delete today's file too)

By the way, I have the list of files to be deleted in a separate file. I am wondering if by running any other additional script, we can delete selected files from the remote server .

I tried with ! command of ftp, but it runs the commands on local machine.

Your help will be highly appreciated.Thanks
  #2 (permalink)  
Old 05-03-2007
Shell_Life's Avatar
Shell_Life Shell_Life is offline
Registered User
  
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
sangfroid,
See if this would work for you:
Code:
vYYMMDD=`date '+%y%m%d'`
vFName='logfile-'$vYYMMDD
rm -f `ls -1 log* | egrep -v "$vFName"`
  #3 (permalink)  
Old 05-03-2007
sangfroid sangfroid is offline
Registered User
  
 

Join Date: May 2007
Posts: 5
i cannot execute rm -f inside ftp session and neither can i run egrep in it.

Last edited by sangfroid; 05-03-2007 at 11:50 AM..
  #4 (permalink)  
Old 05-03-2007
Shell_Life's Avatar
Shell_Life Shell_Life is offline
Registered User
  
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
Another option is to prepare a file with all the deletes, adding "delete"
in front of each file name in your list:
Code:
sed 's/^/delete /' list_file_names > to_del_file_names
Would this work for you?
  #5 (permalink)  
Old 05-03-2007
sangfroid sangfroid is offline
Registered User
  
 

Join Date: May 2007
Posts: 5
I am getting you. But the problem is how to execute at the remote end "inside" ftp session...

i am stuck up in this one
  #6 (permalink)  
Old 05-03-2007
Shell_Life's Avatar
Shell_Life Shell_Life is offline
Registered User
  
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
sangfroid,
Here is a solution:
Code:
rename logfile-070503 hold_logfile-070503
delete logfile*
rename hold_logfile-070503 logfile-070503
  #7 (permalink)  
Old 05-03-2007
ahmedwaseem2000 ahmedwaseem2000 is offline
Registered User
  
 

Join Date: Aug 2005
Location: Bangalore
Posts: 219
Quote:
Originally Posted by sangfroid
I am getting you. But the problem is how to execute at the remote end "inside" ftp session...

i am stuck up in this one
you could use co-process something like this:

Click Here
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 09:52 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0