LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 11-13-2014, 01:45 AM   #1
Gerard Lally
Senior Member
 
Registered: Sep 2009
Location: Leinster, IE
Distribution: Slackware, NetBSD
Posts: 2,179

Rep: Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762
cron - two questions


I have two unrelated questions:

1) I have EDITOR and VISUAL set in my own and root's ~/.profile to emacs. This does not allow me to change crontab, either in X or at the console. I need to "export EDITOR=vim" in order to change cron settings. Why is this?

2) One of the examples in the crontab(1) man page is as follows:

Quote:
To request the last Monday, etc. in a month, ask for the "5th" one. This will always match the last Monday, etc., even if there are only four Mondays in the month:

Code:
# run at 11 am on the first and last Mon, Tue, Wed of each month
0 11 1,5 * mon-wed date
When the fourth Monday in a month is the last, it will match against both the "4th" and the "5th" (it will only run once if both are specified).
Does this sample cron entry not cause the date command to run on the first and fifth day of the month (as long as those days fall in the range Mon-Wed), instead of the first and fifth Monday of the month? I'm not long awake so perhaps I'm missing the obvious!

 
Old 11-13-2014, 04:49 AM   #2
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,897

Rep: Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019
1) If EDITOR is not exported, then it won't be in the environment of the "crontab -e" process. The X environment inheritance is a little hit&miss and will amongst other things depend on how its started. I've added an /etc/xprofile to my system to make things a little more reliable.

2) From just above the examples in the man-page:
Quote:
If you specify both a day in the month and a day of week, it will be interpreted as the Nth such day in the month.
Seems counter intuitive to me (I would have expected it to do the same as what you were expecting), but that seems to suggest that its the latter.

Last edited by GazL; 11-13-2014 at 04:53 AM.
 
Old 11-13-2014, 05:03 AM   #3
Gerard Lally
Senior Member
 
Registered: Sep 2009
Location: Leinster, IE
Distribution: Slackware, NetBSD
Posts: 2,179

Original Poster
Rep: Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762
Quote:
Originally Posted by GazL View Post
1) If EDITOR is not exported, then it won't be in the environment of the "crontab -e" process. The X environment inheritance is a little hit&miss and will amongst other things depend on how its started. I've added an /etc/xprofile to my system to make things a little more reliable.
Perhaps I have this wrong, but print $EDITOR does return /usr/bin/emacs.

From ~/.profile:

Code:
export EDITOR="$(which emacs) -nw"
export VISUAL=$(which emacs)
Quote:
2) From just above the examples in the man-page:

Seems counter intuitive to me (I would have expected it to do the same as what you were expecting), but that seems to suggest that its the latter.
I was so engrossed in the examples I completely missed that! Thanks.
 
Old 11-13-2014, 01:16 PM   #4
saulgoode
Member
 
Registered: May 2007
Distribution: Slackware
Posts: 288

Rep: Reputation: 155Reputation: 155
Quote:
Originally Posted by gezley View Post
Perhaps I have this wrong, but print $EDITOR does return /usr/bin/emacs.
Since 'crontab' is SUID, I'm guessing it starts a new process (that execs emacs) and thus requires that you 'export EDITOR'.

EDIT: Oops! I failed to read your post properly (it must be all that cough syrup I drank earlier). Well, I tried 'export EDITOR' on my machine and it worked fine.

Last edited by saulgoode; 11-13-2014 at 01:28 PM.
 
Old 11-13-2014, 05:46 PM   #5
Gerard Lally
Senior Member
 
Registered: Sep 2009
Location: Leinster, IE
Distribution: Slackware, NetBSD
Posts: 2,179

Original Poster
Rep: Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762
Quote:
Originally Posted by saulgoode View Post
Since 'crontab' is SUID, I'm guessing it starts a new process (that execs emacs) and thus requires that you 'export EDITOR'.

EDIT: Oops! I failed to read your post properly (it must be all that cough syrup I drank earlier). Well, I tried 'export EDITOR' on my machine and it worked fine.
Did you try to change a setting? I should have mentioned that it opens fine in emacs and I can seemingly make changes and write those changes to disk but when I reopen the crontab it has reverted to the default settings.
 
Old 11-13-2014, 06:39 PM   #6
NoStressHQ
Member
 
Registered: Apr 2010
Location: Geneva - Switzerland ( Bordeaux - France / Montreal - QC - Canada)
Distribution: Slackware 14.2 - 32/64bit
Posts: 609

Rep: Reputation: 221Reputation: 221Reputation: 221
Nope...

The 1 is a "well unknown" feature... I stuck on this many times as a emacs user...

Same for SUDO I think...

I go through nano (sorry I don't know enough VI to be vim at ease)

Problem is the cron edition use a "jailed" version of the file, which have a "static" uid (inode?) anyway, when you save with emacs this effectivelly "duplicate" the file and replace it... So the "hard linked" link to the edited file remains untouched... And when you leave the "cron edition process" doesn't see a change so your changes are simply lost...

Use an editor that saves files 'inplace' (the real physical file) not juggling with copies, renaming, backups...

I don't know if we can force emacs to act like this. But nano does (vim does too ).

So:
Code:
$ EDITOR=nano crontab -e
Should do too.

OR... like you did:
Code:
$ EDITOR=vim crontab -e
So in short: it's an emacs behavior... Not a problem with environment variable or anything.

Cheers.

Last edited by NoStressHQ; 11-13-2014 at 06:42 PM.
 
Old 11-13-2014, 06:59 PM   #7
Gerard Lally
Senior Member
 
Registered: Sep 2009
Location: Leinster, IE
Distribution: Slackware, NetBSD
Posts: 2,179

Original Poster
Rep: Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762
Quote:
Originally Posted by NoStressHQ View Post
Problem is the cron edition use a "jailed" version of the file, which have a "static" uid (inode?) anyway, when you save with emacs this effectively "duplicate" the file and replace it... So the "hard linked" link to the edited file remains untouched... And when you leave the "cron edition process" doesn't see a change so your changes are simply lost...
Great explanation. Thanks for that. It works fine in NetBSD by the way. In Slackware I can just about get by with vim for occasional crontab editing if I have to!



 
Old 11-13-2014, 07:06 PM   #8
NoStressHQ
Member
 
Registered: Apr 2010
Location: Geneva - Switzerland ( Bordeaux - France / Montreal - QC - Canada)
Distribution: Slackware 14.2 - 32/64bit
Posts: 609

Rep: Reputation: 221Reputation: 221Reputation: 221
Quote:
Originally Posted by gezley View Post
It works fine in NetBSD by the way
Well, if I "see well" the problem, I didn't dig into the code to see why and if we can blame anybody, I don't care, once I understood, the workaround was faster that trying to fix it.

I'd suspect that was somehow the emacs way of doing things, but it can be coupled with which kind of file system do the job and how the 'driver' handles it... Also one who can be "blamed" is the 'crontab -e' (or sudoers editor) which keep a hard link to the file during the "external edition process" instead of reloading it from name after edition is done, which, I think would have been more "robust", and simpler for everybody...

Cheers

Garry.

PS/ Haha I always "C-x C-s" before submitting those messages...
 
Old 11-13-2014, 09:02 PM   #9
thirdm
Member
 
Registered: May 2013
Location: Massachusetts
Distribution: Slackware, NetBSD, Debian, 9front
Posts: 317

Rep: Reputation: Disabled
Quote:
Originally Posted by gezley View Post
I have two unrelated questions:

I have EDITOR and VISUAL set in my own and root's ~/.profile to emacs.
Computers are pretty fast these days, but you probably would be happier using emacsclient for such things. See the emacs manual for more info.
 
Old 11-15-2014, 03:11 PM   #10
Gerard Lally
Senior Member
 
Registered: Sep 2009
Location: Leinster, IE
Distribution: Slackware, NetBSD
Posts: 2,179

Original Poster
Rep: Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762
Quote:
Originally Posted by thirdm View Post
Computers are pretty fast these days, but you probably would be happier using emacsclient for such things. See the emacs manual for more info.
Yep I do use it in certain situations. Thanks.
 
  


Reply



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
Cron Daemon questions arashi256 Linux - Newbie 2 08-21-2013 09:28 AM
cron questions darkleaf Debian 2 06-21-2005 01:23 PM
cron job questions.... chunlee Linux - Software 1 02-18-2005 05:51 AM
rc.local and cron questions wenberg Slackware 17 07-31-2004 11:18 PM
Two cron questions downinthemine Linux - Software 5 01-11-2004 02:35 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 02:27 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