I set up a job to run a script in a certain directory to remove certain files. The script seems to run as my logs indicate but nothing happens. If I run the script manually then it removes the correct files. I'm now wondering if crontab doesnt have access to remove files from the directory I'm pointing to? Any advise would be greatly appreciated.
as always.... look into the FAQs first!
Did you read my question? The crontab faq did not answer it. I wasnt referring to cron running permissions.
99% of problems with crontab are that is executes with a minimal environment and does not execute your .login, .profile or whatever.
Put in a wrapper script that captures the stdout and stderr, and use "#!/bin/sh -x" as the first line in your script to debug it.
Yes, I did. I don't believe I said anything about 'running permissions'.
As porter has pointed the answer to 'why it works from CLI and not from crontab' usually has to do with the environment of the crontab. That's what the FAQ explains in great details.
If you do read the FAQ (once again) it might help you to troubleshoot the issue.
Actually I'm using the script you helped me with, which is basically
find . \( -size 100c -o -size 145c -o -size 170c \) -a -name "*testing*" | xargs -n 1 rm
So from what you're saying, its not retaining what its finding? Is there a way to make this work in cron for a certain directory?
I suggest you post the whole script.
So there should be a "#!/bin/sh" at the start, and also, change the current directory to what you want to start with.
Sure, not much to the script though. I just want it to remove a few files daily.
#!/bin/ksh
echo "Script started at: " `date` >> /home/tstfile.log
find . \( -size 100c -o -size 145c -o -size 170c \) -a -name "*testing*" | xargs -n
1 rm
echo "Script ended at: " `date` >> /home/tstfile.log
So you suggest, I add
cd 'directory to run script in'
Even though in crontab I add the path where the script is located. I'll add that, anything else you see wrong? Also, the script works great when I run it manually in the directory btw.
NycUnxer,
If you read the FAQ more thoroughly and understood your script in detail, it would have made it clear to you what's wrong.
Your 'find' starts from the current directory. The 'current' directory of any cron jobs is the HOME directory of the user/owner of the cron.
Do you see the problem now?
As porter has pointed out, 'change the current directory to what you want to start with'.
1 * * * * cd 'what you want the find to start with' && /path/to/scriptToRun
Ah, I actually didnt understand that you can put 'cd' in crontab -e(or my little script for that matter heh), since none of the other scheduled jobs do that. Its my first time btw.
I just tested this and it worked. Thanks as always for your patience guys. ![]()