You are not logged in.
I installed Cronie and did
crontab -e
as a user and inserted
*/1 * * * * __cron
I made sure that 'export' tells me that PATH contains my user's private bin folder (/home/jindur/bin):
declare -x PATH="/usr/local/sbin:/usr/local/bin:/usr/bin:/home/jindur/bin:/usr/bin/core_perl"
and made a file in /home/jindur/bin, called __cron:
echo hi >> /home/jindur/test.txt
However, nothing happens: The file test.txt doesn't get generated.
And I saw in the forums that someone said to look into /var/log/cron for errors (was a different problem though), but that folder doesn't exist on my system. I have only /var/spool/cron and /var/spool/anacron and those don't contain log files it seems.
Cronie is running:
localhost $ ps -e | grep cron
899 ? 00:00:00 crond
13467 ? 00:00:00 anacron
EDIT: I narrowed it down to the command not being executed.
It works if I specify full path in crontab, ie "/home/jindur/bin/__cron" instead of just "__cron". Why is this so? Afaik the cron commands are executed as the corresponding user who did "crontab -e", and the path to /home/jindur/bin is exported everywhere, so why does Cronie not recognize it?
(I have this in /etc/profile to export the path:
PATH="/usr/local/sbin:/usr/local/bin:/usr/bin:${HOME}/bin"
export PATH
)
SOLUTION: See post below that says "SOLUTION" in it.
Last edited by Jindur (2013-07-15 23:00:22)
Offline
I think you've told it to run every minute at midnight on no date in no month on no day of the week.
Oh, OK. I guess the manual page for crontab isn't complete. (Doesn't mention using 0s in that way.)
I think cron probably sanitises the environment before running stuff. In particular, stuff like /etc/anacrontab and /etc/cron.d/0hourly seem to specify PATH. (But it is possible I've modified them so check what you have.)
Last edited by cfr (2013-07-15 01:48:00)
CLI Paste | How To Ask Questions
Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L
Offline
oops sorry, I actually did */1 * * * *, I wrote it wrong in my code tags here. :-p
The annoying thing is that it accepts commands in /usr/bin without specifying full path, just not those in /home/jindur/bin.
By what mechanisms do I have to set PATH so that it's really systemwide, including cron?
Also, is anacron a part of cronie? I installed cronie but never anacron, yet it seems to be called by it.
Last but not least, where do I find the cron log file? As I mentioned it is not in /var/log/cron (no such folder).
Last edited by Jindur (2013-07-15 03:18:33)
Offline
Jindur, I lost the bubble here -- did you get it to work? I think that the cron job runs as root, and root is paranoid. On a traditional system, the directories in root's path are limited so that he does not run things that are in places where normal users can create executables without explicitly entering the path. That way, a user cannot create a file that had the same name as a system file in the hope that root will run it with elevated permissions.
In addition to the explicit path, you need to not only ensure that your file is executable, but that it is executable by the process that runs the cron job.
Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way
Offline
Set the PATH in the crontab file, at the top. E.g. for root's "crontab -e":
PATH=/root/bin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
Edit: Check whether cronie has been compiled with --enable-anacron
Last edited by brebs (2013-07-15 04:18:00)
Offline
anacron is part of cronie.
Even though I think you are talking about your user's crontab, the PATH probably still gets set explicitly. Take a look at /etc/anacrontab, for example, or /etc/cron.d/* to trace where the PATH gets set. You can just set the PATH in the crontab, though, as brebs said.
I have /var/log/crond.log but I'm not sure if you need to be using syslog for this so the info might be in the journal instead if you don't use that.
CLI Paste | How To Ask Questions
Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L
Offline
Ok thanks for the pointers, here are my findings:
-I'm pretty sure, and according to articles on the net, commands in a crontab are executed as the user who issued the "crontab -e", would be too easy to exploit root access otherwise ^^.
-In cron.hourly and anacron files in /etc/... are indeed PATH= settings, however:
-I put a simple
echo $PATH > test.txt
into my user's crontab, and lo and behold, the path is only "/usr/bin:/bin", which is even shorter than anything defined in those anacron/cron files in /etc. I actually searched the whole /etc folder and NOWHERE in it is such a short path defined in the form of
PATH="/usr/bin:/bin"
, so this is really weird crap.
-I wasnt aware that you could actually put statements into crontabs oO I tried to insert
export PATH={$HOME}/bin"
but that caused an error message when I tried to save crontab.
-Setting just
PATH={$HOME}/bin
instead, without the exporting "works", as in it doesnt throw an error when trying to save the crontab, but it still doesn't really work: A cron entry
echo `export | grep PATH` > test.txt
will actually result in an empty file that is only 1 Byte long, and a cron entry
echo $PATH > test.txt
will actually output "{$HOME}/bin", without replacing the HOME variable. :-p This is what THE CRON MAN PAGE says, too.
-I just found on the internet another posting where someone explains that cron doesn't use the system's PATH variable at all. Well but which PATH variable does it use? Apparently it's defined nowhere (I searched /etc and /var/spool)
How do I check whether cronie was compiled with --enable-anacron?
SOLUTION:
variables are not resolved in crontabs, path can only be hardcoded.
So I'll do that I guess, no other choice.
The only thing I'm still wondering about where cronie logs to, if at all.
Last edited by Jindur (2013-07-15 23:01:07)
Offline
Ok thanks for the pointers, here are my findings:
-I'm pretty sure, and according to articles on the net, commands in a crontab are executed as the user who issued the "crontab -e", would be too easy to exploit root access otherwise ^^.
Definitely.
-In cron.hourly and anacron files in /etc/... are indeed PATH= settings, however:
-I put a simpleecho $PATH > test.txt
into my user's crontab, and lo and behold, the path is only "/usr/bin:/bin", which is even shorter than anything defined in those anacron/cron files in /etc. I actually searched the whole /etc folder and NOWHERE in it is such a short path defined in the form of
PATH="/usr/bin:/bin"
, so this is really weird crap.
It is longer than my result which is just /usr/bin. Not quite sure about this yet. However, I am guessing jobs are run in subshells and the shell is set as sh rather than bash so... Hmm...
-I wasnt aware that you could actually put statements into crontabs oO I tried to insert
export PATH={$HOME}/bin"
but that caused an error message when I tried to save crontab.
-Setting justPATH={$HOME}/bin
instead, without the "export", works. But then a cron entry
echo `export | grep PATH` > test.txt
will actually result in an empty file that is only 1 Byte long!
What do you expect? You have set PATH to ~/bin! Does ~/bin/echo or ~/bin/export or ~/bin/grep exist? (Maybe echo is a builtin but I'm sure grep is not.)
EDIT: No, you didn't even do that. {$HOME} is not the same as ${HOME}!
Why echo, by the way?
How do I check whether cronie was compiled with --enable-anacron?
Check the pkgbuild? If abs is installed, cat /var/abs/core/cronie/PKGBUILD.
EDIT EDIT: Did you even check journal as suggested for cron log messages? Have you set it up to log rather than send mail? And your "solution" is a load of sbwriel.
REAL SOLUTION: Learn to specify variables in a way the shell understands. Specify a valid path, preferably one which includes the commands you want to use in your crontab.
Last edited by cfr (2013-07-15 23:15:00)
CLI Paste | How To Ask Questions
Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L
Offline
What do you expect? You have set PATH to ~/bin! Does ~/bin/echo or ~/bin/export or ~/bin/grep exist? (Maybe echo is a builtin but I'm sure grep is not.)
EDIT: No, you didn't even do that. {$HOME} is not the same as ${HOME}!
Why echo, by the way?
1) the echo command still worked even though the PATH was set, as you could see when it output the "wrong" $PATH contents
2) oops, {$HOME} should be ${HOME}, as it needs to be specified in /etc/profile
EDIT EDIT: Did you even check journal as suggested for cron log messages? Have you set it up to log rather than send mail? And your "solution" is a load of sbwriel.
REAL SOLUTION: Learn to specify variables in a way the shell understands. Specify a valid path, preferably one which includes the commands you want to use in your crontab.
1) 'man cronie' does not exist, and 'man cron' suggests that logging is done to /var/log/cron. The journal contains no information regarding the PATH problem btw.
2) As I said, the solution is that you _cannot_ specify variables in this case, and what you gave as final solution is exactly what I wrote about, except you might have missed that it needs to be hardcoded (eg /home/jindur/bin in this case); The real solution is that you need to read more carefully.
Last edited by Jindur (2013-07-16 00:11:08)
Offline
Look, if I add
PATH=/usr/bin:/tiddlywinks
to my crontab and a suitable line to write a test file, I get
$ cat /tmp/test.31998
export PATH="/usr/bin:/tiddlywinks"
So clearly it is possible to specify variables. Your code had two issues. First, you did not include /usr/bin in PATH so that the shell could not find grep etc. Second, you included {$HOME} or ${HOME} which will not work because cron quotes the path and escapes special characters (for security reasons?). That does not mean you cannot specify variables: you just have to do it in a way the shell will understand given cron's behaviour.
There are manual pages for cron (which seems not to exist as a command) crond and 2 for crontab. But they are pre-systemd so you need to adjust accordingly or use syslog which will get you /var/log/cron.log if either you have no mailer available or you start crond with the appropriate flag.
EDIT: Maybe we just mean different things by "hardcode" and "variables cannot be specified". I would count the above as specifying PATH (a variable) which is then reflected in cron's handling of the jobs. When you said you had to hardcode the path, I assumed you meant to hardcode the path for every command in a non-standard bin directory but now I think you maybe just meant that you cannot specify the PATH in terms of another variable like HOME because that will get escaped/quoted and you'll end up with something like PATH="/usr/bin:\${HOME}/bin" which obviously won't work.
Last edited by cfr (2013-07-16 00:22:48)
CLI Paste | How To Ask Questions
Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L
Offline