[Solved] Get files & delete them by shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Solved] Get files & delete them by shell script
# 1  
Old 06-20-2013
Computer [Solved] Get files & delete them by shell script

I want to use my script to get any file then delete it once it transfers to my side , I manage to create below script to generate "list" file which contains all file names in "10.10.1.1" then I made "a.out" file which contains the commands that I want to run it on "10.10.1.1" to get & delete the files , I feel my script still miss some statement as I tried to pass "a.out" to ftp command but went wrong , what I should do to automate my script in order to get the files & delete them as well ?


Code:
#!/usr/bin/ksh
ftp -in 10.10.1.1 << EOF 
user  ftpuser ftppass
cd /user/path
bin
dir  *.dat   ./list
bye
EOF

awk '{print $NF}'   ./list | while read file; do
echo "ftp -in 10.10.1.1
user  ftpuser ftppass
bin
cd /user/path
get $file
del $file
bye" >>  a.out
done

# 2  
Old 06-20-2013
Just remove the code echo " and " >> a.out and your loop should process them all.

If you are concenerned by the del during testing, you could just issue a dir of the file instead.


I hope that this helps,


Robin
Liverpool/Blackburn
UK
This User Gave Thanks to rbatte1 For This Post:
# 3  
Old 06-20-2013
Dear rbatte1

you are right I just remove the echo & do some modification for "here document" then it succeeded .. thanks a lot ...

Last edited by arm; 06-20-2013 at 08:36 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to delete the ip address from files

Hello, I am new to shell scripting, need help, my requirement is to delete the ip address from serveral files, please suggest (2 Replies)
Discussion started by: manoj.solaris
2 Replies

2. Shell Programming and Scripting

SFTP Shell Script Get & Delete && Upload & Delete

Hi All, Do you have any sample script, - auto get file from SFTP remote server and delete file in remove server after downloaded. - only download specify filename - auto upload file from local to SFTP remote server and delete local folder file after uploaded - only upload specify filename ... (3 Replies)
Discussion started by: weesiong
3 Replies

3. Shell Programming and Scripting

Shell Script to delete the protected files.

Hello, we have more than 100000 files in a directory which are write-protected regular file, these files are quite old and would like to delete them completely, Kindly let me know the command or peice of code to automate the process. The filenames are like below MPNT_... (6 Replies)
Discussion started by: Hadoop_Master
6 Replies

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

5. Shell Programming and Scripting

[Solved] Help with shell Script ,wait for some files for some time??

Hi All, I have the requirement that ,i have to write a shell script that job has to wait for a 7 touch files created by another application for 4 hours, if i get all 7 touch files ,i have to send a mail that i jobs are completed, if if it is waiting for more than 4 hours i have to send a mail... (2 Replies)
Discussion started by: Pradeep Shetty
2 Replies

6. Red Hat

Need Script to ZIP/SAVE & then DELETE Log file & DELETE ZIPS older than 12 months

ENVIROMENT Linux: Fedora Core release 1 (Yarrow) iPlanet: iPlanet-WebServer-Enterprise/6.0SP1 Log Path: /usr/iplanet/servers/https-company/logs I have iPlanet log rotation enabled rotating files on a daily basis. The rotated logs are NOT compressed & are taking up too much space. I... (7 Replies)
Discussion started by: zachs
7 Replies

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

8. Shell Programming and Scripting

Shell script delete log files from folder & subfolders on space usage

Hi, I am trying to write a shell script to delete logs generate by db when space in the folder reaches 70%. i am getting space values from db, find the files at OS and remove them by using a cron job runs every 5minutes. I have to keep the latest 5 files at any time, my problem is that log files... (3 Replies)
Discussion started by: saha
3 Replies

9. Shell Programming and Scripting

shell script for delete old files

i want to delete all the files in my directory except the latest one. i need to do this from shell script. say i have a.txt - latest file b.txt, c.txt.. it should delete all the files except a.txt? (4 Replies)
Discussion started by: krishnarao
4 Replies

10. UNIX for Advanced & Expert Users

how to delete empty files in a shell script

I'm trying to figure out a way to delete empty files in a directory. I have a cron that runs and creates a flat file every 15 mins. However, most times at night the flat file will be empty. I'd like to run a script to delete empty files that end with *.dat Any suggestions? Rich (1 Reply)
Discussion started by: rpnuge
1 Replies
Login or Register to Ask a Question