delete old files thru unix script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting delete old files thru unix script
# 1  
Old 02-08-2010
delete old files thru unix script

I have to delete files older than 60 days from a windows directory. So I tried to include this script

Code:
FTP_LOG=${DATA_TOP}/data_tmp/logfile
FTP_CMDS=${DATA_TOP}/data_tmp/cmdfile
echo "open ftp1" > ${FTP_CMDS}
echo "user anonymous local" >> ${FTP_CMDS}
echo "cd ${SRC_DIR}" >> ${FTP_CMDS}
echo "find . -mtime +56 -exec rm -f {} \;" >> ${FTP_CMDS}
echo "bye" >> ${FTP_CMDS}
ftp -iv ${SERVER_NAME} < ${FTP_CMDS} > ${FTP_LOG}

But it is not recognizing the find command. I am getting "?Invalid command" error. The command works fine in command line in unix.
any thoughts?

Last edited by pludi; 02-08-2010 at 02:30 PM.. Reason: code tags, please...
# 2  
Old 02-08-2010
If you are connecting to a Windows server with your ftp, which I assume that you are, you'll have to use Windows commands to search and locate the files that you are looking for. The commands within a ftp session are limited. Google "windows ftp commands" to find a list of them.

Hope this helps.
# 3  
Old 02-08-2010
thanks. couldn't find how to specify to delete files older than 'n' days..
# 4  
Old 02-08-2010
@snair001

The unix command "find" is not available within a ftp session. Some ftp commands have similar syntax to unix commands but when you are in an ftp session you are not in a unix shell. If your only access to the server is an anonymous ftp session it may be advisible to approach the administrator of the server to handle filesystem maintenance tasks.

Last edited by methyl; 02-09-2010 at 01:35 PM.. Reason: typo
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script needed to delete to the list of files in a directory based on last created & delete them

Hi My directory structure is as below. dir1, dir2, dir3 I have the list of files to be deleted in the below path as below. /staging/retain_for_2years/Cleanup/log $ ls -lrt total 0 drwxr-xr-x 2 nobody nobody 256 Mar 01 16:15 01-MAR-2015_SPDBS2 drwxr-xr-x 2 root ... (2 Replies)
Discussion started by: prasadn
2 Replies

2. Shell Programming and Scripting

Unix shell script to delete files on windows server

Hi experts, can anyone suggest me on the below: how to write a shell script to search and delete files on windows server. -script runs on unix box -it should search for specific files on windows server and delete them periodically. (2 Replies)
Discussion started by: chpradeepch
2 Replies

3. 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

4. Shell Programming and Scripting

Need help creating a script to FTP files to a server and then delete the files that were transfered.

I am trying to FTP files to a Windows server through my Linux machine. I have setup the file transfer with no problems but am having problem deleting those files from the Linux box. My current non-working solution is below. Any ideas, anyone?? :wall: Please be gentle, I'm fairly new to this... (4 Replies)
Discussion started by: jmalfhs
4 Replies

5. Shell Programming and Scripting

perl script to check if empty files are created and delete them and run a shell script

I have a local linux machine in which the files are dumped by a remote ubuntu server. If the process in remote server has any problem then empty files are created in local machine. Is there any way using perl script to check if the empty files are being created and delete them and then run a shell... (2 Replies)
Discussion started by: hussa1n
2 Replies

6. UNIX for Dummies Questions & Answers

Delete folders and files in it - UNIX

I need to delete a folder and files in it of yesterdays and simply put this in cron. Folder name - "2010-03-2010" File name - "eprod_06_23.dmp" and "eprod_06_23.exp" Actually this folder and file is been created by a script which takes a backup of DB everyday.Thats why it creates folder and file... (3 Replies)
Discussion started by: j_panky
3 Replies

7. Shell Programming and Scripting

using c programming in unix to delete zero-byte files in a specified directory

we were asked to make a program that deletes all zero-byte files in a psecified directory. we need to use sysytem_calls like: scandir(),chdir(),stat() and remove(). (3 Replies)
Discussion started by: sogetsu009
3 Replies

8. Shell Programming and Scripting

Delete files older than 2 days using shell script in Unix

I'm new to shell script.... can any one help... What is the shell script to delete the files older than 2 days ? (3 Replies)
Discussion started by: satishpabba
3 Replies

9. Shell Programming and Scripting

How to delete files in UNIX using shell script

Hi, I have the following task to perform using shell script. The user will provide a directory name along with a date. The script will delete all the files in the specified directory that was created earlier to that date. Also it should display the number of files that has been deleted. ... (7 Replies)
Discussion started by: theguy16
7 Replies

10. UNIX for Dummies Questions & Answers

How to delete many files in Unix

Hi, I am tryting to delete 3 lakch files using below command. rm 1000318* it is showing a message "sh: /usr/bin/rm: The parameter list is too long." please let me know how can i do this. Thanks Senthil (7 Replies)
Discussion started by: skcontact
7 Replies
Login or Register to Ask a Question