Help with permission, path, cron, script problems.

advertisement
This topic from the old SourceForge.net forum was donated from a personal archive and has been edited to improve
readability. If you do not want your posts reproduced herein, please notify one of the maintainers.
[SOLVED] Help with permission, path, cron, script problems.
by nullpointrninja » Mon Aug 02, 2010 5:24 pm
Hello. I'm in the process of building a FreeNAS server and found out about the possibility of emulating apple's "time
machine" with rsync. I wrote a script that works when I execute it manually but not when scheduled as a cron job. I read
the FAQ and fixed some paths but it still doesn't run.
I'm using FreeNAS version 0.7.1 rev5127 in a virtual machine (don't have any hardware yet so I'm learning how to use
FreeNAS for now).
I have one 1TB HDD where all data is stored, and a 2TB HDD where every night, this script runs to make a backup of the
current state of the "Backup" folder in the 1TB disk while storing the previous day's snapshot without duplicating
everything.
Code: Select all
#!/bin/sh
date=`date "+%Y_%m_%d"_%H_%M_%S`
rsync -azPE --link-dest=/mnt/2TB/current /mnt/1TB/Backup /mnt/2TB/$date \
&& rm -f /mnt/2TB/current \
&& ln -s /mnt/2TB/$date /mnt/2TB/current
I used full paths and the access restrictions are set to allow the owner, group and others to read, write and execute but
the script won't run when scheduled (it does run when I click run manually). I know there must be something I'm
overlooking, so please help a newbie
.
Thanks.
Re: Help with permission problems
by al562 » Mon Aug 02, 2010 8:38 pm
Hi Nullpointrninja,
nullpointrninja wrote:I read the FAQ and fixed some paths but it still doesn't run.
Because you did not fix all the paths.
nullpointrninja wrote:I used full paths
For your data files, what about the executables? They are files too
Try:
.
Code: Select all
#!/bin/sh
date=`/bin/date "+%Y_%m_%d"_%H_%M_%S`
/usr/local/bin/rsync -azPE --link-dest=/mnt/r5/current /mnt/sys /mnt/r5/$date \
&& /bin/rm -f /mnt/r5/current \
&& /bin/ln -s /mnt/r5/$date /mnt/r5/current
See what's different? Does it work now?
REgards,
Al
Re: Help with permission problems
by nullpointrninja » Mon Aug 02, 2010 8:55 pm
It works!!!
1 of 5
I knew it was a stupid detail
Thank you very much.
.
I have another question and since it's related to the original question, I'll use this same thread to ask.
I've tried some complicated (to me
) scripts and single line commands to delete backups older than 30 days, but none of
them have done it (they either delete everything or nothing).
I found this:
Code: Select all
find /var/backup/ -name ‘backup*’ -type d -mtime +30 | xargs rm -f
It should delete all folders inside /var/backup/ that were modified in the last 30 days and begin with backup, but it doesn't
work. Any ideas/suggestions?
Thanks again.
Re: Help with permission problems
by al562 » Mon Aug 02, 2010 9:46 pm
nullpointrninja wrote:Any ideas/suggestions?
There are lots of one-liners you can use to keep things neat. There are also a bunch of issues in getting them to work
properly. I would recommend you read nightly empty .recycle cron job, it covers everything you should need to achieve
your goal.
Editors' Note: nightly empty .recycle cron job is included in this archive, at the end of this topic.
Regards,
Al
Re: Help with permission problems
by nullpointrninja » Mon Aug 02, 2010 11:17 pm
Thanks. It worked perfectly.
I pasted this command directly in the command box when creating the cron job and it does exactly what I wanted.
Code: Select all
find /mnt/2TB/ -depth 1 -ctime +1 -exec rm -fr "{}" \;
Thanks a lot
.
Re: Help with permission problems
by al562 » Tue Aug 03, 2010 12:40 am
You are welcome.
This topic from the old SourceForge.net forum was donated from a personal archive and has been edited to improve
readability. If you do not want your posts reproduced herein, please notify one of the maintainers.
nightly empty .recycle cron job.
by gtp04 » Sat Mar 27, 2010 7:20 pm
as per http://thewichitacomputerguy.com/blog/automatically-empty-cifssmb-recycle-bin-freenas-server
i have followed the directions to use cron to setup a script that runs at midnight that allows automatic deletion of files
older that 1 day.... instead of his default 14 days.
the issues is that the cron job will not run with an error....
from event log root: Failed to execute cron job 'sh /usr/opt/autorecycle.sh'.
Im a freebsd noobie and a windows boy..... Im a computer pc tech by day and not afraid of command line, or learning new
2 of 5
things....
any help to a noobie would be appriciated..
Dan
ps 0.7 Khasadar (revision 4919) freenas version
Re: nightly empty .recycle cron job.
by mstorin » Sun Mar 28, 2010 5:47 pm
Have you tried '/bin/sh /usr/opt/autorecycle.sh' ?
Re: nightly empty .recycle cron job.
by danmero » Sun Mar 28, 2010 7:22 pm
gtp04 wrote:from event log root: Failed to execute cron job 'sh /usr/opt/autorecycle.sh'.
You don't need a script , just add the following command line to System|Advanced|Cron, just change the path to your
recycle bin
Code: Select all
find /path/ -depth 1 -atime +1 -exec rm -fr {} \;
Re: nightly empty .recycle cron job.
by gtp04 » Mon Mar 29, 2010 2:16 am
thanks for the suggestions... but neither of the above worked ... same error
root: cron service restarted
Mar 29 07:12:24 freenas root: Failed to execute cron job '/bin/sh /usr/opt/autorecycle.sh'.
Mar 29 07:13:16 freenas kernel: GEOM_LABEL: Label ufsid/4af471aec8448e1d removed.
Mar 29 07:13:16 freenas kernel: GEOM_LABEL: Label for provider ad0a is ufsid/4af471aec8448e1d.
Mar 29 07:13:19 freenas root: cron service restarted
Mar 29 07:13:26 freenas root: Failed to execute cron job 'find /path/ -depth 1 -atime +1 -exec rm -fr {} \;'.
Re: nightly empty .recycle cron job.
by danmero » Mon Mar 29, 2010 2:24 am
gtp04 wrote:Mar 29 07:13:26 freenas root: Failed to execute cron job 'find /path/ -depth 1 -atime +1 -exec rm -fr
{} \;'.
danmero wrote:You don't need a script , just add the following command line to System|Advanced|Cron, just
change the path to your recycle bin
Re: nightly empty .recycle cron job.
by cadavor » Tue Mar 30, 2010 9:17 pm
danmero wrote:You don't need a script , just add the following command line to System|Advanced|Cron, just
change the path to your recycle bin
Code: Select all
find /path/ -depth 1 -atime +1 -exec rm -fr {} \;
I tried your command danmero with the right path but I obtain the same error :
root: Failed to execute cron job 'find /mnt/NASRaid10/.recycle/* -depth 1 -atime +1 -exec rm -fr {} \; '.
3 of 5
I tried several commands without any good results :
Code: Select all
find /mnt/NASRaid10/.recycle/ -depth 1 -atime +1 -exec rm -fr {} \;
Code: Select all
find /mnt/NASRaid10/.recycle/ -atime +1 -exec rm -fr {} \;
Code: Select all
find /mnt/NASRaid10/.recycle/* -depth 1 -atime +1 -exec rm -fr {} \;
Have you any idea to solve this problem
Version :
FreeNas 0.7.1 rev.5113 - Full
Re: nightly empty .recycle cron job.
by al562 » Wed Mar 31, 2010 6:40 pm
cadavor wrote:Have you any idea to solve this problem
Yes; from the find man, -exec section:
" If you invoke find from a shell you may need to quote the semicolon if the shell would otherwise treat it as a control
operator. "
Cron does not appear to treat the ; as a control operator, so there is no need to escape it. Try the following:
Code: Select all
find /mnt/NASRaid10/.recycle -depth 1 -atime +1 -exec rm -rf {} ;
I think you'll find it works, but on my test system it behaves oddly. When I click the "Run Now" button it seems to work
fine. When I let it run automatically it doesn't. Based on the difficulties with cron I would suggest you save it in a script
and have cron execute the script. This is the way I always do it because usually there are other things I am cleaning up so
it is difficult to create a one-liner that can just be typed into the WebGUI.
For example:
Code: Select all
#!/bin/sh
find /mnt/NASRaid10/.recycle/ -depth 1 -atime +1 -exec rm -fr {} \;
Save this as clean.sh, then execute it in WebGUI cron with
Code: Select all
/mnt/NASRaid10/clean.sh
It would be nice to be able to do this as a one-liner directly, but it just won't work. EDIT - Now works fine after upgrading,
see posts below. - Al
Regards,
Al
Re: nightly empty .recycle cron job.
by cadavor » Wed Mar 31, 2010 9:45 pm
The direct command works fine
Code: Select all
root: The cron job 'find /mnt/NASRaid10/.recycle -depth 1 -atime +1 -exec rm -rf {} ;' has been executed successfully.
4 of 5
But with .sh file it doesn't
Code: Select all
root: Failed to execute cron job '/mnt/NASRaid10/clean.sh'.
I copy the given code in clean.sh file and put it in /mnt/NASRaid10/
Version :
FreeNas 0.7.1 rev.5113 - Full
Re: nightly empty .recycle cron job.
by danmero » Thu Apr 01, 2010 10:58 am
cadavor wrote:The direct command works fine
Code: Select all
root: The cron job 'find /mnt/NASRaid10/.recycle -depth 1 -atime +1 -exec rm -rf {} ;' has been executed successfully.
I suggested because just work(for me
, tested) from cron (not RUN NOW).
Code: Select all
find /mnt/NASRaid10/.recycle/ -depth 1 -atime +1 -exec rm -rf {} \;
Test run on: FreeNAS 0.7.1 (revision 5024) i386-embedded; ASUS P4B266LA Intel(R) Pentium(R) 4 CPU 2.20GHz 768MiB
RAM
Re: nightly empty .recycle cron job.
by al562 » Thu Apr 01, 2010 2:08 pm
cadavor wrote:The direct command works fine
If that's the case then you should have no need for the script file
.Are you sure the unwanted files are actually deleted??
If you still want to use the script file make sure the ownership and privileges are correct. You probably want the owner to
the root and the group to be wheel, then file should be rwxr-xr-x.
danmero wrote:Test run on: FreeNAS 0.7.1 (revision 5024) i386-embedded;
Hey Dan, I can't get the one-liner to run right on either of my test systems. I will upgrade as soon as possible, try it again
and report back.
Regards,
Al
5 of 5
Download