LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-07-2016, 04:04 AM   #16
Raakh5
Member
 
Registered: Mar 2012
Posts: 167

Original Poster
Rep: Reputation: Disabled

Here is result with set -xv
Code:
putdir="/Backup/dmp"
+ putdir=/Backup/dmp
ndays=1
+ ndays=1

# work out our cutoff date
MM=`date --date="$ndays days ago" +%b`
date --date="$ndays days ago" +%b
++ date '--date=1 days ago' +%b
+ MM=Jul
DD=`date --date="$ndays days ago" +%d`
date --date="$ndays days ago" +%d
++ date '--date=1 days ago' +%d
+ DD=06

echo removing files older than $MM $DD
+ echo removing files older than Jul 06
removing files older than Jul 06

# get directory listing from remote source
listing=`ftp -i -n $ftpsite <<EOMYF 
user $ftpuser $ftppass
binary
cd $putdir
ls
quit
EOMYF
`
ftp -i -n $ftpsite <<EOMYF 
user $ftpuser $ftppass
binary
cd $putdir
ls
quit
EOMYF
++ ftp -i -n dedibackup-dc2.online.net
+ listing='Trying 62.210.17.27...
-rw-r--r--    1 1001       ftp          12672814 Jul  7 07:57 GSW-05-07-2016.dmp
-rw-r--r--    1 1001       ftp          12672913 Jul  1 08:27 GSW-07-01-2016.dmp
-rw-r--r--    1 1001       ftp          12672889 Jul  7 07:57 GSW-07-07-2016.dmp
-rw-r--r--    1 1001       ftp        1099121178 Jul  7 07:57 MI-05-07-2016.dmp
-rw-r--r--    1 1001       ftp        1099121165 Jul  1 08:28 MI-07-01-2016.dmp
-rw-r--r--    1 1001       ftp        1099121206 Jul  7 07:58 MI-07-07-2016.dmp'
lista=( $listing )
+ lista=($listing)
echo $lista
+ echo Trying
Trying

# loop over our files
for ((FNO=0; FNO<${#lista[@]}; FNO+=9));do
  # month (element 5), day (element 6) and filename (element 8)
  echo Date ${lista[`expr $FNO+5`]} ${lista[`expr $FNO+6`]} File: ${lista[`expr $FNO+8`]}

  # check the date stamp
  if [[ ${lista[$((FNO+5))]} == "$MM" ]];
  then
    if [[ ${lista[$((FNO+6))]} == "$DD" ]];
    then
      # Remove this file
      echo "Removing ${lista[`expr $FNO+8`]}"
      ftp -i -n $ftpsite <<EOMYF2 
      user $ftpuser $ftppass
      binary
      cd $putdir
      delete ${lista[$((FNO+8))]}
      quit
EOMYF2
    fi
  fi
done
+ (( FNO=0 ))
+ (( FNO<56 ))
expr $FNO+5
++ expr 0+5
expr $FNO+6
++ expr 0+6
expr $FNO+8
++ expr 0+8
+ echo Date ftp 12672814 File: 7
Date ftp 12672814 File: 7
+ [[ ftp == \J\u\l ]]
+ (( FNO+=9 ))
+ (( FNO<56 ))
expr $FNO+5
++ expr 9+5
expr $FNO+6
++ expr 9+6
expr $FNO+8
++ expr 9+8
+ echo Date ftp 12672913 File: 1
Date ftp 12672913 File: 1
+ [[ ftp == \J\u\l ]]
+ (( FNO+=9 ))
+ (( FNO<56 ))
expr $FNO+5
++ expr 18+5
expr $FNO+6
++ expr 18+6
expr $FNO+8
++ expr 18+8
+ echo Date ftp 12672889 File: 7
Date ftp 12672889 File: 7
+ [[ ftp == \J\u\l ]]
+ (( FNO+=9 ))
+ (( FNO<56 ))
expr $FNO+5
++ expr 27+5
expr $FNO+6
++ expr 27+6
expr $FNO+8
++ expr 27+8
+ echo Date ftp 1099121178 File: 7
Date ftp 1099121178 File: 7
+ [[ ftp == \J\u\l ]]
+ (( FNO+=9 ))
+ (( FNO<56 ))
expr $FNO+5
++ expr 36+5
expr $FNO+6
++ expr 36+6
expr $FNO+8
++ expr 36+8
+ echo Date ftp 1099121165 File: 1
Date ftp 1099121165 File: 1
+ [[ ftp == \J\u\l ]]
+ (( FNO+=9 ))
+ (( FNO<56 ))
expr $FNO+5
++ expr 45+5
expr $FNO+6
++ expr 45+6
expr $FNO+8
++ expr 45+8
+ echo Date ftp 1099121206 File: 7
Date ftp 1099121206 File: 7
+ [[ ftp == \J\u\l ]]
+ (( FNO+=9 ))
+ (( FNO<56 ))
expr $FNO+5
++ expr 54+5
expr $FNO+6
++ expr 54+6
expr $FNO+8
++ expr 54+8
+ echo Date File:
Date File:
+ [[ '' == \J\u\l ]]
+ (( FNO+=9 ))
+ (( FNO<56 ))
[root@centos backup-scripts]#
 
Old 07-07-2016, 04:10 AM   #17
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,104

Rep: Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267
looks like it was completed without any error message
 
Old 07-07-2016, 04:12 AM   #18
Raakh5
Member
 
Registered: Mar 2012
Posts: 167

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
looks like it was completed without any error message
Yes but not did anything on the ftp server. All the files exists in /Backup/dmp directory as it is
 
Old 07-07-2016, 04:20 AM   #19
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,104

Rep: Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267
did you recognize:
Code:
# in your shell script
  # month (element 5), day (element 6) and filename (element 8)
  echo Date ${lista[`expr $FNO+5`]} ${lista[`expr $FNO+6`]} File: ${lista[`expr $FNO+8`]}
# in your log
Date ftp 1099121206 File: 7
this is not really the expected result. it should be:
Code:
Date jul 7 File: GSW-05-07-2016.dmp
I think
 
Old 07-07-2016, 04:37 AM   #20
Raakh5
Member
 
Registered: Mar 2012
Posts: 167

Original Poster
Rep: Reputation: Disabled
You are very right. I am trying to correct it. Please let me know if you have any idea about it
 
Old 07-07-2016, 04:44 AM   #21
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,104

Rep: Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267
I would say (based on your log):
Code:
++ ftp -i -n dedibackup-dc2.online.net
+ listing='Trying 62.210.17.27...
-rw-r--r--    1 1001       ftp          12672814 Jul  7 07:57 GSW-05-07-2016.dmp
that very first line caused a shift, probably by two, you need to check that.
in that case you need to adjust all the "expr $FNO + <number>" expressions by incrementing that number - everywhere. But it is only a guess and you need to check if that really works
 
1 members found this post helpful.
  


Reply

Tags
centos6, script, sh


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] bash script problem, using zenity to file select m2t file for mplayer but don't work? davetesc Linux - Newbie 2 05-26-2012 07:49 PM
script - problem with reading file name dlugasx Linux - Server 1 08-18-2009 03:22 PM
Script file problem (or operator problem) HELP! lostone Programming 2 05-23-2001 03:30 PM
Script file problem (or operator problem) HELP! lostone Linux - General 1 05-17-2001 07:11 PM
Script file problem (or operator problem) HELP! lostone Linux - Newbie 0 05-15-2001 08:59 PM


All times are GMT -5. The time now is 02:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration