× NETGEAR will be terminating ReadyCLOUD service by July 1st, 2023. For more details click here.
Orbi WiFi 7 RBE973
Reply

Auto clean "Recycle bin" on OS6.6 ?

EtherZhang
Aspirant

Auto clean "Recycle bin" on OS6.6 ?

I have looked though this post:

 

https://community.netgear.com/t5/Using-your-ReadyNAS/Can-Recycle-Bin-be-enabled-for-CIFS-and-OS-6-1-...

 

And I have successfully enabled the "recycle bin" on my NAS, it works fine excpet I have to empty it manually.

 

I have crated a 'clean_recycle_bins' script and a 'recycle.conf' file according to the post, but when I try to run this scrip using " /frontview/bin/clean_recycle_bins start", I get this :

 

"Can't locate Frontview.pm in @INC (you may need to install the Frontview module) (@INC contains: /frontview/lib /etc/perl /usr/local/lib/arm-linux-gnueabi/perl/5.20.2 /usr/local/share/perl/5.20.2 /usr/lib/arm-linux-gnueabi/perl5/5.20 /usr/share/perl5 /usr/lib/arm-linux-gnueabi/perl/5.20 /usr/share/perl/5.20 /usr/local/lib/site_perl .) at /frontview/bin/clean_recycle_bins line 8.
BEGIN failed--compilation aborted at /frontview/bin/clean_recycle_bins line 8."

 

So I guesee I am missing some frontview module files right? Where can I get them?

 

 

 

 

 

Model: RN204|ReadyNAS 204
Message 1 of 19

Accepted Solutions
EtherZhang
Aspirant

Re: Auto clean "Recycle bin" on OS6.6 ?

So the conclusion of the solution is here:

 

1. Create file:

 

/etc/frontview/samba/addons/addons.conf

 

 

2. Edit addons.conf according to your existing shares, if you want hide the recycle bin folder, add "."  as I did:

 

[share1]
vfs objects = recycle
recycle:repository = .Recycle Bin
recycle:keeptree = yes
recycle:versions = no

[share2]
vfs objects = recycle
recycle:repository = .Recycle Bin
recycle:keeptree = yes
recycle:versions = no

 

 

3. Reload the config file by go to the frontview web interface -> Shares and edit one of your current shares and change something then press OK. The recycle bin will now working on your NAS. Next are how to enable autoclean function for the recycle bin.

 

 

4. Create file

 

/frontview/bin/clean_recycle_bins

and edit it as below:

 

#!/usr/bin/perl
#-------------------------------------------------------------------------
#  Copyright 2007, NETGEAR
#  All rights reserved.
#-------------------------------------------------------------------------
#
# exit if( -f "/ramfs/.clean_recycle_bins.lock" );
# open(LOCK, ">/ramfs/.clean_recycle_bins.lock");
# close(LOCK);
# while ( -f "/ramfs/spindown" ) {
#   local $/;
#   open(SPIN, "/ramfs/spindown");
#   if( <SPIN> =~ ":1" ) {
#     sleep(530);
#   } 
#   else {
#     last;
#   }
# }

use lib qw( /frontview/lib );
# use Frontview;
# 
# my $fv = new Frontview;
# $fv->Account_get_info();
# $fv->Service_get_info();

open(IN, "/etc/frontview/recycle.conf") || exit;
my @dirlist = <IN>;
close(IN);

# if( $fv->{Service}{USER_HOME_DIRECTORY} &&
#     $fv->{Service}{USER_HOME_DIRECTORY_RECYCLE} )
# {
#   my $path;
#   my $recycle_max_days = $fv->{Service}{USER_HOME_DIRECTORY_RECYCLE_MAX_DAYS};
#      $recycle_max_days = $HOME_RECYCLE_AGE_LIMIT if( !$recycle_max_days );
#   my $recycle_max_size = $fv->{Service}{USER_HOME_DIRECTORY_RECYCLE_MAX_SIZE};
#      $recycle_max_size = $HOME_RECYCLE_MB_LIMIT if( !$recycle_max_size );
# 
#   foreach my $user( sort keys %{ $fv->{Account}{user} } )
#   {
#     if( -d "$fv->{Account}{user}{$user}{home}/.Recycle Bin" )
#     {
#       $path = $fv->{Account}{user}{$user}{home};
#       push @dirlist, "$user!!$path!!$recycle_max_size!!$recycle_max_days";
#     }
#   }
# }

foreach (@dirlist)
{
  chomp;
  my ($share, $path, $mb_limit, $age_limit) = split('!!');

  if( $age_limit )
  {
    system("find '$path/.Recycle Bin' -type f -ctime +$age_limit -exec rm -rf {} \\; &>/dev/null");
  }
  if( $mb_limit )
  {
    my $dev = `df $path | tail -1 | awk '{print \$1}'`;
    chomp $dev;
    my $blocksize = `dumpe2fs -h $dev 2>/dev/null | grep 'Block size' | awk '{print \$3}'`;
    chomp $blocksize;
    my $recycle_mb = `du -sm '$path/.Recycle Bin' 2>/dev/null`; chomp $recycle_mb;
    if( $recycle_mb > $mb_limit )
    {
      my %files;
      open(FIND, "find '$path/.Recycle Bin' -type f -printf '%p!=!=%C@!=!=%s\n' |");
      while(<FIND>)
      {
        chomp;
        my ($name, $time, $size) = split('!=!=');
        while( exists $files{$time} )
        {
          ++$time;
        }
        $files{$time}{name} = $name;
        $files{$time}{size} = $size > $blocksize ? $size : $blocksize;
      }
      close(FIND);

      my $total_size = 0;
      my $byte_limit = ($mb_limit * 1024 * 1024);
      foreach my $time (reverse sort keys %files)
      {
        $total_size = ($total_size + $files{$time}{size});
        if( $total_size > $byte_limit )
        {
          unlink("$files{$time}{name}");
        }
      }
    }
  }

  # Do a reverse sort so we can rmdir child directories before the parents.
  open(FIND, "find '$path/.Recycle Bin' -type d 2>/dev/null | sort -r |");
  while(<FIND>)
  {
    chomp;
    rmdir;
  }
  close(FIND);
}
close(IN);
# unlink("/ramfs/.clean_recycle_bins.lock");

PS: You can modify all the '$path/.Recycle Bin' by using your own recycle bin name you used in file addons.conf at the beginning.

 

 

5. Create file:

 

/etc/frontview/recycle.conf

then edit it like this:

 

share1!!/data/share1!!0!!1
share2!!/data/share2!!0!!1

The last digit "1" I use here represent the how old of the files inside the recycle bin you want to delete when this scrip runs, 1 means older than 1 day, you can set it to 30 then it will only clean files that stays in the recycle bin folder more than one month. 

 

 

6. Create a Cron by adding a file called "autoclean" or whatever into "/etc/cron.d" folder, then edit the file as below:

 

0 1 * * * root /frontview/bin/clean_recycle_bins start

Then run

/etc/init.d/cron force-reload

and

/etc/init.d/cron restart

This will allow the scrip to run at every day's 01:00 am and clean the recycle bin according to the "recycle.conf". You can modified it if you know how to write a cron script.

 

 

7. Remember all the files that you created here should have 0755 permissions, check this first if you received a error on anything.

 

View solution in original post

Message 18 of 19

All Replies
FramerV
NETGEAR Employee Retired

Re: Auto clean recycle bin on OS6.6

Hi EtherZhang,

 

Welcome to the community.

 

Let me ask if this is something that we have and/or provide.

 

 

Regards,

Message 2 of 19
mdgm-ntgr
NETGEAR Employee Retired

Re: Auto clean recycle bin on OS6.6

Why not just use snapshots rather than enabling the recycle bin for CIFS?

Message 3 of 19
EtherZhang
Aspirant

Re: Auto clean recycle bin on OS6.6

Yes, I know the snapshot function is more "advance", but it runs accroding a schedual, so if you misdeleted a file between 2 schedualed time point, it will gone forever...

 

In this point, I belive the legacy recycle bin is more "flexible" and more "real-time", although, dumb, I admit, but still has it advantage.

Message 4 of 19
mdgm-ntgr
NETGEAR Employee Retired

Re: Auto clean recycle bin on OS6.6

Looks like you're trying to use a script designed for RAIDiator so the script may need some rewriting to work with OS6.

Message 5 of 19
EtherZhang
Aspirant

Re: Auto clean recycle bin on OS6.6

Yes, have you looked through that post? That was for OS6.1.2, I have enabled the recyle bin on OS 6.6 but can't get the auto clean function work, i don't know where I did wrong.

Message 6 of 19
Sandshark
Sensei

Re: Auto clean "Recycle bin" on OS6.6 ?

There is definately no "Frontview.pm" anywhere on the NAS and has not been since at least OS 6.4.2 (the oldest OS 6 version I still have running).

 

But while I'm no Perl coder, I think the author just failed to comment out a few additional lines.  The Frontview module seems to be used only to find all of the parameters for user home directories, but the code for emptying the recycle bins in home directories is commented out.  Try just commenting out these additional lines (put a "#" in front of them):

use Frontview;

my $fv = new Frontview;
$fv->Account_get_info();
$fv->Service_get_info();

I don't see $fv used anywhere other than within the other commented out lines.  So, as long as you aren't looking to have recycle bins in home directories, or at least don't need them to auto-empty, I think it will work if it ever did.  The logic looks good, but I can't check the syntax because I don't know it.

 

 

Let us know if it works.  I recently did something stupid that would have been easier to recover from with a recycle bin, so I'm thinking of re-instating one, too.

Message 7 of 19
EtherZhang
Aspirant

Re: Auto clean "Recycle bin" on OS6.6 ?

Thanks for the advice, but if I add "#"in front of those 4 lines, I recive this:

 

root@NAS:~# /frontview/bin/clean_recycle_bins start
syntax error at /frontview/bin/clean_recycle_bins line 15, near "my  ="
syntax error at /frontview/bin/clean_recycle_bins line 49, near "()
"
syntax error at /frontview/bin/clean_recycle_bins line 53, near ");"
syntax error at /frontview/bin/clean_recycle_bins line 101, near "}"
Execution of /frontview/bin/clean_recycle_bins aborted due to compilation errors.

So I guess it still need the Frontview library to run the "my" command or something else.

Message 8 of 19
Sandshark
Sensei

Re: Auto clean "Recycle bin" on OS6.6 ?

"MY" is a standard Perl keyword to declare variables and set their scope, so something else is wrong.  But I can find no examples of the "My =" syntax and don't understand why IN is opened once and closed twice.  And I can't even find wher the variable IN is used.

 

As I said, I thought that would work "if it ever worked".  I think something else is missing.

 

I may have to break my NVX out of the closet and see what 4.2.x really contains here.

Message 9 of 19
Sandshark
Sensei

Re: Auto clean "Recycle bin" on OS6.6 ?

OK, so the problem is that the "at" sign has special meaning in the forum software and some important things got deleted from the orignally posted code because of it.  Here is clean_recycle_bins from OS4.2.28 with the with the at sign replaced by [AT]..  Do a search and replace to put back in the at sign instead of [AT].

 

Frontview.pmc (compiled .pm) does not live anywhere in OS6.6.x, so all references to it and variables from it are commented out.  [AT] dirlist is referenced in the commented code, but that part is just adding the home directories to the list already in /etc/frontview/recycle.conf.    I don't think we need use lib qw( /frontview/lib );, either, but it shouldn't hurt to have it and not use it.  I have not added any of the OP's other edits, at least assuming the other differences are his and not just changes made in OS4.2.28 vs. whatever he got it from.

 

I have not tried this myself, though.  And as previously stated, I'm not really a Pearl coder, I've just modified a few lines of code now and then using examples I Googled.

 

#!/usr/bin/perl
#-------------------------------------------------------------------------
#  Copyright 2007, NETGEAR
#  All rights reserved.
#-------------------------------------------------------------------------

use lib qw( /frontview/lib );
# use Frontview;
# 
# my $fv = new Frontview;
# $fv->Account_get_info();
# $fv->Service_get_info();

open(IN, "/etc/frontview/recycle.conf") || exit;
my [AT]dirlist = <IN>;
close(IN);

# if( $fv->{Service}{USER_HOME_DIRECTORY} &&
#     $fv->{Service}{USER_HOME_DIRECTORY_RECYCLE} )
# {
#   my $path;
#   my $recycle_max_days = $fv->{Service}{USER_HOME_DIRECTORY_RECYCLE_MAX_DAYS};
#      $recycle_max_days = $HOME_RECYCLE_AGE_LIMIT if( !$recycle_max_days );
#   my $recycle_max_size = $fv->{Service}{USER_HOME_DIRECTORY_RECYCLE_MAX_SIZE};
#      $recycle_max_size = $HOME_RECYCLE_MB_LIMIT if( !$recycle_max_size );
# 
#   foreach my $user( sort keys %{ $fv->{Account}{user} } )
#   {
#     if( -d "$fv->{Account}{user}{$user}{home}/Recycle Bin" )
#     {
#       $path = $fv->{Account}{user}{$user}{home};
#       push [AT]dirlist, "$user!!$path!!$recycle_max_size!!$recycle_max_days";
#     }
#   }
# }

foreach ([AT]dirlist)
{
  chomp;
  my ($share, $path, $mb_limit, $age_limit) = split('!!');

  if( $age_limit )
  {
    system("find '$path/Recycle Bin' -type f -ctime +$age_limit -exec rm -rf {} \\; &>/dev/null");
  }
  if( $mb_limit )
  {
    my $recycle_mb = `du -sm '$path/Recycle Bin' 2>/dev/null`; chomp $recycle_mb;
    if( $recycle_mb > $mb_limit )
    {
      my %files;
      open(FIND, "find '$path/Recycle Bin' -type f -printf '%p!=!=%C[AT]!=!=%s\n' |");
      while(<FIND>)
      {
        chomp;
        my ($name, $time, $size) = split('!=!=');
        while( exists $files{$time} )
        {
          ++$time;
        }
        $files{$time}{name} = $name;
        $files{$time}{size} = $size;
      }
      close(FIND);

      my $total_size = 0;
      my $byte_limit = ($mb_limit * 1024 * 1024);
      foreach my $time (reverse sort keys %files)
      {
        $total_size = ($total_size + $files{$time}{size});
        if( $total_size > $byte_limit )
        {
          unlink("$files{$time}{name}") or system("rm -f \'$files{$time}{name}\'");
        }
      }
    }
  }

  # Do a reverse sort so we can rmdir child directories before the parents.
  open(FIND, "find '$path/Recycle Bin' -type d 2>/dev/null | sort -r |");
  while(<FIND>)
  {
    chomp;
    rmdir;
  }
  close(FIND);
}
close(IN);

 

Message 10 of 19
EtherZhang
Aspirant

Re: Auto clean "Recycle bin" on OS6.6 ?

Thank you so much! I ran this script without an erro, so I think it's working now! I'll wait for one more day and test whether it can auto clean files older than 1 day.

 

One more question, if I ran this scrip, is the autoclean schedual will automatically go on forever, or I need to add this scrip into a cron, otherwise it will only clean the recycle bin once when I run it mannually?

Message 11 of 19
Sandshark
Sensei

Re: Auto clean "Recycle bin" on OS6.6 ?

Glad I could help, please keep me updated.  I didn't end up having to break out my NVX, I just extracted the files from the OS 4.2.28 update package.  Once I saw the previously missing "ats", the code made more sense and I was pretty sure that was the key.

 

It will need to be a cron job to keep deleting files regularly.

Message 12 of 19
Sandshark
Sensei

Re: Auto clean "Recycle bin" on OS6.6 ?

I originally just looked where the other poster said clean_recycle_bins existed.  But it turns out that the file in /etc/cron.daily doesn't just point to the one in /frontview/bin, it's a slightly different file.  Some of it won't work in OS6 because OS6 doesn't use the /ramfs directory for flags.  You could create one or use another directory and some of the added code looks like it will lock clean_recycle_bins so that if it hangs you won't have a bunch of them hanging.  But you can't implement the wait for the drives to be spun up because nothing in OS6 creates that flag.  If OS6 has a similar flag elsewhere, I haven't found it.  I've commented out those parts of the code, too.  But there are a couple other small changes associated with not letting the recycle bin get bigger than the specified size that may be needed to make that part work.  Once again, the at sign is replaced with [AT].

 

#!/usr/bin/perl
#-------------------------------------------------------------------------
#  Copyright 2007, NETGEAR
#  All rights reserved.
#-------------------------------------------------------------------------
#
# exit if( -f "/ramfs/.clean_recycle_bins.lock" );
# open(LOCK, ">/ramfs/.clean_recycle_bins.lock");
# close(LOCK);
# while ( -f "/ramfs/spindown" ) {
#   local $/;
#   open(SPIN, "/ramfs/spindown");
#   if( <SPIN> =~ ":1" ) {
#     sleep(530);
#   } 
#   else {
#     last;
#   }
# }

use lib qw( /frontview/lib );
# use Frontview;
# 
# my $fv = new Frontview;
# $fv->Account_get_info();
# $fv->Service_get_info();

open(IN, "/etc/frontview/recycle.conf") || exit;
my [AT]dirlist = <IN>;
close(IN);

# if( $fv->{Service}{USER_HOME_DIRECTORY} &&
#     $fv->{Service}{USER_HOME_DIRECTORY_RECYCLE} )
# {
#   my $path;
#   my $recycle_max_days = $fv->{Service}{USER_HOME_DIRECTORY_RECYCLE_MAX_DAYS};
#      $recycle_max_days = $HOME_RECYCLE_AGE_LIMIT if( !$recycle_max_days );
#   my $recycle_max_size = $fv->{Service}{USER_HOME_DIRECTORY_RECYCLE_MAX_SIZE};
#      $recycle_max_size = $HOME_RECYCLE_MB_LIMIT if( !$recycle_max_size );
# 
#   foreach my $user( sort keys %{ $fv->{Account}{user} } )
#   {
#     if( -d "$fv->{Account}{user}{$user}{home}/Recycle Bin" )
#     {
#       $path = $fv->{Account}{user}{$user}{home};
#       push [AT]dirlist, "$user!!$path!!$recycle_max_size!!$recycle_max_days";
#     }
#   }
# }

foreach ([AT]dirlist)
{
  chomp;
  my ($share, $path, $mb_limit, $age_limit) = split('!!');

  if( $age_limit )
  {
    system("find '$path/Recycle Bin' -type f -ctime +$age_limit -exec rm -rf {} \\; &>/dev/null");
  }
  if( $mb_limit )
  {
    my $dev = `df $path | tail -1 | awk '{print \$1}'`;
    chomp $dev;
    my $blocksize = `dumpe2fs -h $dev 2>/dev/null | grep 'Block size' | awk '{print \$3}'`;
    chomp $blocksize;
    my $recycle_mb = `du -sm '$path/Recycle Bin' 2>/dev/null`; chomp $recycle_mb;
    if( $recycle_mb > $mb_limit )
    {
      my %files;
      open(FIND, "find '$path/Recycle Bin' -type f -printf '%p!=!=%C[AT]!=!=%s\n' |");
      while(<FIND>)
      {
        chomp;
        my ($name, $time, $size) = split('!=!=');
        while( exists $files{$time} )
        {
          ++$time;
        }
        $files{$time}{name} = $name;
        $files{$time}{size} = $size > $blocksize ? $size : $blocksize;
      }
      close(FIND);

      my $total_size = 0;
      my $byte_limit = ($mb_limit * 1024 * 1024);
      foreach my $time (reverse sort keys %files)
      {
        $total_size = ($total_size + $files{$time}{size});
        if( $total_size > $byte_limit )
        {
          unlink("$files{$time}{name}");
        }
      }
    }
  }

  # Do a reverse sort so we can rmdir child directories before the parents.
  open(FIND, "find '$path/Recycle Bin' -type d 2>/dev/null | sort -r |");
  while(<FIND>)
  {
    chomp;
    rmdir;
  }
  close(FIND);
}
close(IN);
# unlink("/ramfs/.clean_recycle_bins.lock");
Message 13 of 19
EtherZhang
Aspirant

Re: Auto clean "Recycle bin" on OS6.6 ?

Thanks a lot! I have added this scrip into the /etc/cron.daily, and will see if it can work automatically.

 

And BTW there is another mistake of the file '/etc/frontview/recycle.conf' in the original post, the directory should be '/data/blabla' rather than "/c/blabla", like this:

 

media!!/data/media!!0!!360
media-other!!/data/media-other!!0!!180

Otherwise the scrip will end up cannot find directory.

 

Message 14 of 19
FramerV
NETGEAR Employee Retired

Re: Auto clean "Recycle bin" on OS6.6 ?

Hi EtherZhang,

 

We are monitoring this thread and we would like to know of the current status on your end. Please post/update us so that we can check if there is anything that we can do for you.

 

 

Regards,

Message 15 of 19
Sandshark
Sensei

Re: Auto clean "Recycle bin" on OS6.6 ?

That's actually another difference between OS4.x and 6.x, not an error; but I'm glad you caught it.

 

So, is it working as expected?

Message 16 of 19
EtherZhang
Aspirant

Re: Auto clean "Recycle bin" on OS6.6 ?

Yes it's working but a little imperfect... every time it executing the cron auto-clean job, if the "Recycle bin" folder itself is older than one day, the cron job will delete it too. 

 

It's not a big deal becuase next time you delet somthing the "Recycle bin" will be re-created, but it will lost the hidden attribute which I manually set.

 

So I changed the folder name into ".Recycle Bin", I will post out all the revised and correct codes below.

Message 17 of 19
EtherZhang
Aspirant

Re: Auto clean "Recycle bin" on OS6.6 ?

So the conclusion of the solution is here:

 

1. Create file:

 

/etc/frontview/samba/addons/addons.conf

 

 

2. Edit addons.conf according to your existing shares, if you want hide the recycle bin folder, add "."  as I did:

 

[share1]
vfs objects = recycle
recycle:repository = .Recycle Bin
recycle:keeptree = yes
recycle:versions = no

[share2]
vfs objects = recycle
recycle:repository = .Recycle Bin
recycle:keeptree = yes
recycle:versions = no

 

 

3. Reload the config file by go to the frontview web interface -> Shares and edit one of your current shares and change something then press OK. The recycle bin will now working on your NAS. Next are how to enable autoclean function for the recycle bin.

 

 

4. Create file

 

/frontview/bin/clean_recycle_bins

and edit it as below:

 

#!/usr/bin/perl
#-------------------------------------------------------------------------
#  Copyright 2007, NETGEAR
#  All rights reserved.
#-------------------------------------------------------------------------
#
# exit if( -f "/ramfs/.clean_recycle_bins.lock" );
# open(LOCK, ">/ramfs/.clean_recycle_bins.lock");
# close(LOCK);
# while ( -f "/ramfs/spindown" ) {
#   local $/;
#   open(SPIN, "/ramfs/spindown");
#   if( <SPIN> =~ ":1" ) {
#     sleep(530);
#   } 
#   else {
#     last;
#   }
# }

use lib qw( /frontview/lib );
# use Frontview;
# 
# my $fv = new Frontview;
# $fv->Account_get_info();
# $fv->Service_get_info();

open(IN, "/etc/frontview/recycle.conf") || exit;
my @dirlist = <IN>;
close(IN);

# if( $fv->{Service}{USER_HOME_DIRECTORY} &&
#     $fv->{Service}{USER_HOME_DIRECTORY_RECYCLE} )
# {
#   my $path;
#   my $recycle_max_days = $fv->{Service}{USER_HOME_DIRECTORY_RECYCLE_MAX_DAYS};
#      $recycle_max_days = $HOME_RECYCLE_AGE_LIMIT if( !$recycle_max_days );
#   my $recycle_max_size = $fv->{Service}{USER_HOME_DIRECTORY_RECYCLE_MAX_SIZE};
#      $recycle_max_size = $HOME_RECYCLE_MB_LIMIT if( !$recycle_max_size );
# 
#   foreach my $user( sort keys %{ $fv->{Account}{user} } )
#   {
#     if( -d "$fv->{Account}{user}{$user}{home}/.Recycle Bin" )
#     {
#       $path = $fv->{Account}{user}{$user}{home};
#       push @dirlist, "$user!!$path!!$recycle_max_size!!$recycle_max_days";
#     }
#   }
# }

foreach (@dirlist)
{
  chomp;
  my ($share, $path, $mb_limit, $age_limit) = split('!!');

  if( $age_limit )
  {
    system("find '$path/.Recycle Bin' -type f -ctime +$age_limit -exec rm -rf {} \\; &>/dev/null");
  }
  if( $mb_limit )
  {
    my $dev = `df $path | tail -1 | awk '{print \$1}'`;
    chomp $dev;
    my $blocksize = `dumpe2fs -h $dev 2>/dev/null | grep 'Block size' | awk '{print \$3}'`;
    chomp $blocksize;
    my $recycle_mb = `du -sm '$path/.Recycle Bin' 2>/dev/null`; chomp $recycle_mb;
    if( $recycle_mb > $mb_limit )
    {
      my %files;
      open(FIND, "find '$path/.Recycle Bin' -type f -printf '%p!=!=%C@!=!=%s\n' |");
      while(<FIND>)
      {
        chomp;
        my ($name, $time, $size) = split('!=!=');
        while( exists $files{$time} )
        {
          ++$time;
        }
        $files{$time}{name} = $name;
        $files{$time}{size} = $size > $blocksize ? $size : $blocksize;
      }
      close(FIND);

      my $total_size = 0;
      my $byte_limit = ($mb_limit * 1024 * 1024);
      foreach my $time (reverse sort keys %files)
      {
        $total_size = ($total_size + $files{$time}{size});
        if( $total_size > $byte_limit )
        {
          unlink("$files{$time}{name}");
        }
      }
    }
  }

  # Do a reverse sort so we can rmdir child directories before the parents.
  open(FIND, "find '$path/.Recycle Bin' -type d 2>/dev/null | sort -r |");
  while(<FIND>)
  {
    chomp;
    rmdir;
  }
  close(FIND);
}
close(IN);
# unlink("/ramfs/.clean_recycle_bins.lock");

PS: You can modify all the '$path/.Recycle Bin' by using your own recycle bin name you used in file addons.conf at the beginning.

 

 

5. Create file:

 

/etc/frontview/recycle.conf

then edit it like this:

 

share1!!/data/share1!!0!!1
share2!!/data/share2!!0!!1

The last digit "1" I use here represent the how old of the files inside the recycle bin you want to delete when this scrip runs, 1 means older than 1 day, you can set it to 30 then it will only clean files that stays in the recycle bin folder more than one month. 

 

 

6. Create a Cron by adding a file called "autoclean" or whatever into "/etc/cron.d" folder, then edit the file as below:

 

0 1 * * * root /frontview/bin/clean_recycle_bins start

Then run

/etc/init.d/cron force-reload

and

/etc/init.d/cron restart

This will allow the scrip to run at every day's 01:00 am and clean the recycle bin according to the "recycle.conf". You can modified it if you know how to write a cron script.

 

 

7. Remember all the files that you created here should have 0755 permissions, check this first if you received a error on anything.

 

Message 18 of 19
Sandshark
Sensei

Re: Auto clean "Recycle bin" on OS6.6 ?

Actually, I believe that's the way it works on OS4.x, too.  An empty recycle bin is deleted.

 

Thanks for running with the baton.  I think I'll be doing this myself, very soon.

Message 19 of 19
Top Contributors
Discussion stats
  • 18 replies
  • 5885 views
  • 1 kudo
  • 4 in conversation
Announcements