LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-18-2015, 10:04 AM   #1
vasis
LQ Newbie
 
Registered: Jul 2013
Posts: 19

Rep: Reputation: Disabled
cron.daily symlink (double) does not seem to be executing?


Hello,

I cannot understand why the symlink I have put in /etc/cront.daily won't work. It is very possible I am wrong, but my understanding is that cront.{daily,weekly,monthly} works fine with symlinks.

Basically it is double symlink-ed. ls -la on /etc/cron.daily looks like this:

Code:
... 
lrwxrwxrwx  1 root root    49 Nov 27 18:26 rsync_mysql_backups.sh -> /home/myuser/scripts/bash/rsync_mysql_backups.sh
...
Now, ls -la on /home/myuser/scripts looks like this:

Code:
...
lrwxrwxrwx 1 myuser myuser    26 Sep 20  2013 scripts -> /media/md1_storage/scripts
...
I couldn't see anything suspicious in syslog, so I installed postfix in the hope that I will get some sort of information there. Nothing... I also redirected the output of the script to a file in /home/myuser/log.txt but nothing there. The file was not even created.

I am not doing anything mad in the script, I am just synchronising a local directory with a remote one like this:

Code:
/usr/bin/rsync -avzx -e 'ssh -i "/home/myuser/.ssh/myremotehost/id_rsa"' /media/md1_storage/backups/stuff/ myuser@myremotehost:/srv/backups/stuff/ >> /home/myuser/log.txt 2>&1;
As other people suggested in similar threads, I have verified that
Code:
test -x /usr/sbin/anacron
is false, which will result in the execution of the second part of the entry in /etc/crontab:

Code:
25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
Any input will be much appreciated. I know I am doing something wrong, but I just cannot see it right now... How can I gather more debugging which will help me understand what's going wrong?

Thanks!

Last edited by vasis; 01-18-2015 at 10:19 AM.
 
Old 01-18-2015, 10:14 AM   #2
vasis
LQ Newbie
 
Registered: Jul 2013
Posts: 19

Original Poster
Rep: Reputation: Disabled
I forgot to say, it isn't just cron.daily. I have exactly the same issue when using cron.hourly. I also tried using the actual path of the script rather than double symlink-ing it. Same problem. The weird thing is that when I switch user to root and I execute the script, it's OK... What am I missing?

Thanks!
 
Old 01-18-2015, 10:44 AM   #3
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 2,959

Rep: Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268
Filesystems under /media are commonly mounted with the "noexec" option, though that should prevent root from running the script too, unless you actually ran a shell and gave it the file name as a parameter ("bash /home/myuser/scripts/bash/rsync_mysql_backups.sh"). Also, you never showed the permissions on the rsync_mysql_backups.sh file itself. And, does that file start with the necessary "#!/bin/bash" or "#!/bin/sh" line?

Last edited by rknichols; 01-18-2015 at 10:46 AM.
 
Old 01-18-2015, 11:23 AM   #4
vasis
LQ Newbie
 
Registered: Jul 2013
Posts: 19

Original Poster
Rep: Reputation: Disabled
Thanks for your input. Here is how fstab looks like:

Code:
UUID=1ff6b579-38f0-455c-a9c8-b486025adfd8 /               ext4    discard,noatime,errors=remount-ro 0       1
UUID=8871a79a-a548-4004-8c7f-0d23a2324bb0       /media/md1_storage      ext4    errors=remount-ro       0       2
The file starts with "#!/bin/bash", I just have loads of unnecessary comments as I'm testing it, and I thought I wouldn't bother you with 10 useless lines, when there is only one line that matters.

The permissions of the actual file look like this:
Code:
myuser@helios✓:~$ ls -la /media/md1_storage/scripts/bash/rsync_mysql_backups.sh
-rwxr-xr-x 1 myuser myuser 707 Jan 15 13:13 /media/md1_storage/scripts/bash/rsync_mysql_backups.sh
Is fstab enough to check the noexec flag you pointed out as a potential problem? If not, what's the best way to check it?

Thanks!
 
Old 01-18-2015, 01:31 PM   #5
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 2,959

Rep: Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268
Since you have that mount listed explicitly in /etc/fstab, the options there would be what is applied, and there is no "noexec". /media is mostly used for automatic mounts when USB flash drives, CD-ROMs, etc., are inserted, and it is for that that options like "noexec" and "nodev" are the default. The definitive answer is just to run the "mount" command with no arguments and see what options it shows for /media/md1_storage.

Another possibility would be a jobs.allow file in the /etc/cron.{daily,hourly} directory, but that is not common.

What Linux distribution are you running? Is it using a /usr/bin/run-parts script to run the jobs in those directories? If so, you could look at that script and see if any problem is apparent, or even execute "run-parts /etc/cron.hourly" as root and see if any relevant messages show up in the terminal. Heck, run it with "bash -x run-parts /etc/cron.hourly" and get a trace of what goes on.
 
1 members found this post helpful.
Old 01-20-2015, 04:44 PM   #6
vasis
LQ Newbie
 
Registered: Jul 2013
Posts: 19

Original Poster
Rep: Reputation: Disabled
OK, thank you very much for your suggestion, it did not solve the problem directly but it put me down a logical path which actually helped A LOT!

The short answer: it would appear that you cannot have a file name put in cron.{hourly,daily,weekly} which contains a "." (dot). Creating a symlink with the ".sh" extension removed did the job.

As suggested I switched user to root, went to "/" (not "/home/root"...) and ran:
Code:
root@helios✓:/# run-parts --list /etc/cron.daily
That would list all files in /etc/cron.daily directory (including non executable files), but will not actually run anything (see man page: http://manpages.debian.org/cgi-bin/man.cgi?query=run-parts). The output was suspicious, because it listed everything apart from my script. While looking at the output of the above command, it occurred to me that there was no file listed there (including other scripts that were put there before) which had an extension (".sh", ".php", ".pl" or whatever).

So, I deleted the symlink and I created it again, with the only difference that I didn't include the "." (dot)! To test my assumption I ran:
Code:
root@helios✓:/# run-parts --report /etc/cron.daily
which worked fine! I admit I will have to wait until tomorrow to find out if the cron.daily will do its thing at the scheduled time, but after running it manually I am relatively confident that it will work. I'll update the thread if that's not the case anyway.

By the way, I am running Debian 7 (I should have said that earlier really). Do you know if this is normal behaviour for cron? I might have missed it, but I couldn't find this documented anywhere. Searching the web I found other people experiencing the same behaviour, but I am not sure if that's normal?

Thanks again for all your help!

Last edited by vasis; 01-20-2015 at 04:47 PM.
 
Old 01-20-2015, 07:06 PM   #7
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 2,959

Rep: Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268
Quote:
Originally Posted by vasis View Post
By the way, I am running Debian 7 (I should have said that earlier really). Do you know if this is normal behaviour for cron?
It would be something in run-parts, not cron. My run-parts in CentOS 6 is a fairly simple shell script which would not have rejected a ".sh" suffix. Yours is apparently quite different. If it's a script, you can look at it and see what it does.

Last edited by rknichols; 01-20-2015 at 07:13 PM.
 
Old 01-27-2015, 06:31 PM   #8
vasis
LQ Newbie
 
Registered: Jul 2013
Posts: 19

Original Poster
Rep: Reputation: Disabled
Sorry for the delay, yes, you are right, it is going to be run-parts that's doing it. In Debian run-parts is compiled. Even then though, I am sure I can have a look into the code and see what it does. The important thing for this thread is that '.' + run-parts = problems apparently. Thanks again for all your help! I hope other people will find this thread useful/helpful.
 
  


Reply

Tags
crondaily, symlinks


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
Scripts in cron.daily are not running daily abefroman Linux - Server 1 12-23-2014 01:11 PM
[SOLVED] Configured Cron job executed every hour is instead executed every minute for 10m markings Linux - Software 4 05-13-2012 06:43 PM
script not executed by cron.daily hopefull Linux - Newbie 6 01-17-2009 10:54 AM
adding a perl script to cron.daily / cron.d to setup a cron job CrontabNewBIE Linux - Software 6 01-14-2008 09:16 AM
Can any one plz explain why/what for cron.d, cron.daily, cron.weekly etc are there. mavinashbabu Linux - Newbie 4 09-21-2006 02:50 PM


All times are GMT -5. The time now is 02:15 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration