LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This 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


Reply
  Search this Thread
Old 01-21-2015, 06:13 AM   #1
Iotar
LQ Newbie
 
Registered: May 2011
Distribution: Slackware64 14.0
Posts: 16

Rep: Reputation: Disabled
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?
 
Old 01-21-2015, 06:22 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 20,252

Rep: Reputation: 6837Reputation: 6837Reputation: 6837Reputation: 6837Reputation: 6837Reputation: 6837Reputation: 6837Reputation: 6837Reputation: 6837Reputation: 6837Reputation: 6837
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)
 
Old 01-21-2015, 06:27 AM   #3
Iotar
LQ Newbie
 
Registered: May 2011
Distribution: Slackware64 14.0
Posts: 16

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
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've tried to write a shell script:
Quote:
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.
Is you mean that or not?

If I run this script from console, it's working fine.
 
Old 01-21-2015, 06:34 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 20,252

Rep: Reputation: 6837Reputation: 6837Reputation: 6837Reputation: 6837Reputation: 6837Reputation: 6837Reputation: 6837Reputation: 6837Reputation: 6837Reputation: 6837Reputation: 6837
no, I mean to modify it, like:
Code:
#!/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
 
Old 01-21-2015, 06:38 AM   #5
Iotar
LQ Newbie
 
Registered: May 2011
Distribution: Slackware64 14.0
Posts: 16

Original Poster
Rep: Reputation: Disabled
Thank you, I shall try it.
 
Old 01-21-2015, 09:40 AM   #6
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,413

Rep: Reputation: 1540Reputation: 1540Reputation: 1540Reputation: 1540Reputation: 1540Reputation: 1540Reputation: 1540Reputation: 1540Reputation: 1540Reputation: 1540Reputation: 1540
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
 
Old 01-21-2015, 12:58 PM   #7
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD, Raspbian, Arch
Posts: 2,327

Rep: Reputation: 357Reputation: 357Reputation: 357Reputation: 357
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.
 
1 members found this post helpful.
Old 01-22-2015, 12:07 AM   #8
Iotar
LQ Newbie
 
Registered: May 2011
Distribution: Slackware64 14.0
Posts: 16

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by TenTenths View Post
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
 
Old 01-22-2015, 12:25 AM   #9
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 20,252

Rep: Reputation: 6837Reputation: 6837Reputation: 6837Reputation: 6837Reputation: 6837Reputation: 6837Reputation: 6837Reputation: 6837Reputation: 6837Reputation: 6837Reputation: 6837
so script works, crontab works, just the directory was empty?
 
Old 01-22-2015, 01:45 AM   #10
Iotar
LQ Newbie
 
Registered: May 2011
Distribution: Slackware64 14.0
Posts: 16

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
so script works, crontab works, just the directory was empty?
No.
 
Old 01-22-2015, 02:03 AM   #11
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 20,252

Rep: Reputation: 6837Reputation: 6837Reputation: 6837Reputation: 6837Reputation: 6837Reputation: 6837Reputation: 6837Reputation: 6837Reputation: 6837Reputation: 6837Reputation: 6837
But what? We cannot go further with a simple no....
 
Old 01-22-2015, 02:15 AM   #12
Iotar
LQ Newbie
 
Registered: May 2011
Distribution: Slackware64 14.0
Posts: 16

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
But what? We cannot go further with a simple no....
I can't understand why. Maybe it connected with some permissions, but I don't know where.
 
Old 01-22-2015, 02:25 AM   #13
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 20,252

Rep: Reputation: 6837Reputation: 6837Reputation: 6837Reputation: 6837Reputation: 6837Reputation: 6837Reputation: 6837Reputation: 6837Reputation: 6837Reputation: 6837Reputation: 6837
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.
 
Old 01-22-2015, 02:29 AM   #14
Iotar
LQ Newbie
 
Registered: May 2011
Distribution: Slackware64 14.0
Posts: 16

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
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.
Ok, thank you.
 
Old 02-13-2015, 02:05 AM   #15
Iotar
LQ Newbie
 
Registered: May 2011
Distribution: Slackware64 14.0
Posts: 16

Original Poster
Rep: Reputation: Disabled
Problem solved by reinstalling cron. Thanks.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Cron run fails at random points, throws: Attempting to re-run cron while.... Nighteyes Linux - Newbie 2 06-22-2012 05:08 AM
[SOLVED] Shell script doesn't run on cron (otherwise it works) kalashari Linux - Software 6 02-17-2012 01:50 PM
[SOLVED] Cron doesn't run a certain script mcdorians Linux - Software 12 04-04-2011 02:35 PM
script doesn't run in cron (runs from shell just fine) Timur Sakayev Linux - Software 6 02-26-2007 12:56 PM
Cron - doesn't seem to run scheduled tasks robintw Linux - General 11 11-25-2005 01:53 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:56 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration