Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
# 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:
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)
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)
#!/bin/bash
exec >/tmp/mylogfile 2>&1
set -xv
echo "my script blabla started"
rm -rf /var/vmail/info/Maildir/.INBOX.autotests/cur/
echo completed
wait # < this wait is not required. What is it good for?
exit 0
and you can check the content of that /tmp/mylogfile
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.
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
instead of
Code:
rm
I tried this. I wrote about it in the first post of this topic. But thanks.
Quote:
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.
I can't understand what may be wrong...
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 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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.