cron doesn't run the rule
Hello. I have a mailsystem server based on Ubuntu 14.04. I have created rules in crontab to delete some mails automatically:
root@mail:~# cat /etc/crontab # /etc/crontab: system-wide crontab # Unlike any other crontab you don't have to run the `crontab' # command to install the new version when you edit this file # and files in /etc/cron.d. These files also have username fields, # that none of the other crontabs do. SHELL=/bin/sh PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin # m h dom mon dow user command 17 * * * * root cd / && run-parts --report /etc/cron.hourly 25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily ) 47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly ) 52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly ) 00 23 * * * root /bin/rm /var/vmail_user/some_user/Maildir/.INBOX.some1/cur/* 00 23 * * * root /usr/bin/find /var/vmail_user/some_user/Maildir/.INBOX.some2/cur -type f -mtime +4 -delete Rule for find command is working, but for rm command is not. I tried to change "/bin/rm" to "rm" and to "rm -rf", but it's not working. I tried to make file: root@mail:~# cat /etc/cron.daily/rm #!/bin/bash rm -rf /var/vmail/info/Maildir/.INBOX.autotests/cur/ wait exit 0 It's not working too. If I run this commands (rm and /bin/rm or bash /etc/cron.daily/rm) from console, they are working fine. Permissions: root@mail:~# ls -la /etc/ | grep crontab -rw-r--r-- 1 root root 1002 Jan 20 12:29 crontab root@mail:~# ls -la /etc/cron.daily/ | grep rm -rwxr-xr-x 1 root root 78 Jan 20 12:26 rm Permissions to .INBOX.some1 and to .INBOX.some2 are the same. "service cron restart" isn't helping. Can You help me and say, what I'm doing wrong? |
I would try to write a shell script and execute it from cron and you can check anything you want in that script and also write a logfile (also use set -xv)
|
Quote:
Quote:
If I run this script from console, it's working fine. |
no, I mean to modify it, like:
Code:
#!/bin/bash |
Thank you, I shall try it.
|
in your script for any commands you are using that aren't shell built-in then use the full path to the command.
For example: Code:
/bin/rm Code:
rm |
If something runs from the command line, but not from cron, FIRST, check the environment. SECOND check the environment again. And FINALLY, re-check the environment.
We are talking about ownership, permissions, paths, and environment variables here. |
Quote:
Quote:
pan64, I tried to run this script via cron. Script worked, there is output in /tmp/mylogfile, but nothing to remove in catalog in rm command :( |
so script works, crontab works, just the directory was empty?
|
Quote:
|
But what? We cannot go further with a simple no....
|
Quote:
|
so that is where you can add some check/test to the script. For example:
id - to print the identity of the actual user ls - to show the content of some dir and permissions type - to check if a command is available and other things you can find useful. |
Quote:
|
Problem solved by reinstalling cron. Thanks.
|
All times are GMT -5. The time now is 10:41 PM. |