[SOLVED] Trying to delete older files from ftp server using shell script.
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Trying to delete older files from ftp server using shell script.
Hello All,
I am trying to delete older files from ftp server. But before that I want to check how many files I got through ${#var[@]} but it always gives me output count 1 which is not expected. Please see below snippet of my code.
#!/bin/bash
#set -x
#get a list of files and dates from ftp and remove files older than n days
MM=`date --date="$ndays days ago" +%b`
DD=`date --date="$ndays days ago" +%d`
TT=`date --date="$ndays days ago" +%s`
echo removing files older then $MM $DD from $ftpsite directory $putdir
#get dirlist from ftp
listing=`ftp -i $ftpserver << EOF
user $ftpuser $ftppass
binary
cd $putdir
ls -l
quit
EOF
`
#remove first 4 and last lines from output and stored it in a variable.
finallist="`printf "( $listing\n )" | tail -n +5 |head -n -1`"
echo "${#finallist[@]}"
echo "${#finallist[*]}"
###################################################
Both echo "${#finallist[@]}" and echo "${#finallist[*]}" gives me count 1 where I can see more that 25 files in the variable.
Dear arpit,
I myself just starting with scripting (chapter 8 of BasicShellScripting) so maybe my hint will not be useful.
However I will write to you.
Have you tried to debug your scripting inputting?
Code:
set -x
echo "${#finallist[@]}"
echo "${#finallist[*]}"
set +x
I have used below now and it worked...Thanks a lot for your inputs.
Hi...
Welcome to the forum
If your issue is resolved, please mark this thread as "SOLVED" by clicking on "Thread Tools" directly above your initial post. Thanks!
Also, just as a suggestion, you might want to change your username using the instructions at the top of the page here, lest your email inbox ends up with a boatload of SPAM in the very near future.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.