*New 11.3 series Release:
2019-10-05: XigmaNAS 11.3.0.4.6928 - released, 11.2 series are soon unsupported!

*New 12.0 series Release:
2019-10-05: XigmaNAS 12.0.0.4.6928 - released!

*New 11.2 series Release:
2019-09-23: XigmaNAS 11.2.0.4.6881 - released!

We really need "Your" help on XigmaNAS https://translations.launchpad.net/xigmanas translations. Please help today!

Producing and hosting XigmaNAS costs money. Please consider donating for our project so that we can continue to offer you the best.
We need your support! eg: PAYPAL

.recycle cron job - works from shell, not in crontab.

XigmaNAS Scripts and shell tips
Forum rules
Set-Up GuideFAQsForum Rules
Post Reply
tdiaz
Starter
Starter
Posts: 27
Joined: 08 Mar 2017 21:12
Status: Offline

.recycle cron job - works from shell, not in crontab.

#1

Post by tdiaz » 04 Sep 2018 02:38

This works from a shell login

Code: Select all

/usr/bin/find /mnt/ -name ".recycle" > /tmp/list ; /bin/cat /tmp/list | xargs -I % /usr/bin/find %/ -atime +10 -exec rm -vrf '{}' \;
but when added to the cron page the log shows:

Code: Select all

root: Failed to execute cron job '/usr/bin/find /mnt/ -name ".recycle" > /tmp/list ; /bin/cat /tmp/list | xargs -I % /usr/bin/find %/ -atime +10 -exec rm -vrf '{}' \;.

User avatar
tony1
Moderator
Moderator
Posts: 172
Joined: 14 Jul 2016 19:04
Status: Offline

Re: .recycle cron job - works from shell, not in crontab.

#2

Post by tony1 » 05 Sep 2018 20:30

probably a syntax issue because cron uses sh as the shell and not bash.

try calling a script something like

#!/bin/sh
# find /mnt/[MountPoint]/.recycle/* -atime +[Age] -exec rm -rf '{}' \;
# find /mnt/[MountPoint]/.recycle/ -depth -type d -empty -exec rmdir {} \;
# Notice the "+14". That's how old a file has to be before it deletes it from the recycle bin.
# If you want 7 days, change it to +7. If you want 30 days, change it to +30
/usr/bin/find /mnt/tank/share/.recycle/* -atime +2 -exec rm -rf '{}' \;
/usr/bin/find /mnt/tank/share/.recycle/ -depth -type d -empty -exec rmdir {} \;
/bin/date

and run it with /persistent_location/scripts/recycle.sh > /root/logs/myscript.log 2>&1 in System > Advanced > Cron

keep an eye on script directory and file permissions.

this works fine for me, maybe you need something different?

User avatar
Snufkin
Advanced User
Advanced User
Posts: 289
Joined: 01 Jul 2012 11:27
Location: Etc/GMT-3 (BSD style)
Status: Offline

Re: .recycle cron job - works from shell, not in crontab.

#3

Post by Snufkin » 05 Sep 2018 20:42

I'll join tdiaz observation, something is definitely wrong if one starts binary using cron.
I've already reported about problem with php and cron.

Went a little deeper and found different shell and path environment.
  • root in remote shell

    Code: Select all

    shell   /bin/tcsh
    path    (/sbin /bin /usr/sbin /usr/bin /usr/local/sbin /usr/local/bin /root/bin)
  • crontab config

    Code: Select all

    SHELL=/bin/sh
    PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin
Not sure if the above could be the root cause, but beside cron there is problem to start smbclient binary as well.
Maybe something was missed during the transition from N4F to XNAS?
XNAS 11.3.0.4 embedded, ASUS P5B-E, Intel DC E6600, 4 GB DDR2, 2 x HGST HDN726040ALE614, 2 x WDC WD5000AAKS, Ippon Back Power Pro 400

User avatar
raulfg3
Site Admin
Site Admin
Posts: 4921
Joined: 22 Jun 2012 22:13
Location: Madrid (ESPAÑA)
Contact:
Status: Offline

Re: .recycle cron job - works from shell, not in crontab.

#4

Post by raulfg3 » 05 Sep 2018 21:15

not sure , but I suspect that r5943 is the patch to solve this: https://sourceforge.net/p/xigmanas/code ... d00f2:5942
12.0.0.4 (revision 6766)+OBI on SUPERMICRO X8SIL-F 8GB of ECC RAM, 12x3TB disk in 3 vdev in RaidZ1 = 32TB Raw size only 22TB usable

Wiki
Last changes

User avatar
Snufkin
Advanced User
Advanced User
Posts: 289
Joined: 01 Jul 2012 11:27
Location: Etc/GMT-3 (BSD style)
Status: Offline

Re: .recycle cron job - works from shell, not in crontab.

#5

Post by Snufkin » 05 Sep 2018 21:30

raulfg3 wrote:
05 Sep 2018 21:15
not sure , but I suspect that r5943 is the patch to solve this: https://sourceforge.net/p/xigmanas/code ... d00f2:5942
Thank you raulfg3, be waiting for the next release to test.
Edit:
Tested, php and cron issue resolved in XigmaNAS release 11.2.0.4.5925
Last edited by Snufkin on 07 Sep 2018 18:20, edited 1 time in total.
XNAS 11.3.0.4 embedded, ASUS P5B-E, Intel DC E6600, 4 GB DDR2, 2 x HGST HDN726040ALE614, 2 x WDC WD5000AAKS, Ippon Back Power Pro 400

tdiaz
Starter
Starter
Posts: 27
Joined: 08 Mar 2017 21:12
Status: Offline

Re: .recycle cron job - works from shell, not in crontab.

#6

Post by tdiaz » 05 Sep 2018 21:44

tony1 wrote:
05 Sep 2018 20:30
probably a syntax issue because cron uses sh as the shell and not bash.
....
this works fine for me, maybe you need something different?
Hmmm.. I'll have to see about the shell difference. As for the script type, I've got several shares within /mnt meaning I'd have to do that alternate method several times where as what I've got does it all at once, and does not need to sweep for empty directories in an additional pass.

Side note: I don't understand why there's no inbuilt function for .recycle purging.
I'm sure someone will come up with a highly technically pointed reason though... 8-)

User avatar
tony1
Moderator
Moderator
Posts: 172
Joined: 14 Jul 2016 19:04
Status: Offline

Re: .recycle cron job - works from shell, not in crontab.

#7

Post by tony1 » 06 Sep 2018 00:05

you do not need to sweep for empty directories unless you want to remove them, modify the script if you want :)

if you come up with something better share it for others to use.

take care!

User avatar
raulfg3
Site Admin
Site Admin
Posts: 4921
Joined: 22 Jun 2012 22:13
Location: Madrid (ESPAÑA)
Contact:
Status: Offline

Re: .recycle cron job - works from shell, not in crontab.

#8

Post by raulfg3 » 06 Sep 2018 07:59

tony1 wrote:
05 Sep 2018 20:30

Side note: I don't understand why there's no inbuilt function for .recycle purging.
I'm sure someone will come up with a highly technically pointed reason though... 8-)
You can use Extended GUI to have a automatic purge of .recycle bin , please test it.
12.0.0.4 (revision 6766)+OBI on SUPERMICRO X8SIL-F 8GB of ECC RAM, 12x3TB disk in 3 vdev in RaidZ1 = 32TB Raw size only 22TB usable

Wiki
Last changes

User avatar
tony1
Moderator
Moderator
Posts: 172
Joined: 14 Jul 2016 19:04
Status: Offline

Re: .recycle cron job - works from shell, not in crontab.

#9

Post by tony1 » 07 Sep 2018 19:37

Side note: I don't understand why there's no inbuilt function for .recycle purging.
it's all how you want to look at it I guess? deleting files from a recycle bin should be left to the user who deleted them to maintain.

you could always disable it if you want on the shares property page or maintain it on a admin level with a script. I love choices :)

Post Reply

Return to “Scripts and shell tips”