Operating System - HP-UX
1836527 Members
3951 Online
110101 Solutions
New Discussion

cannot edit crontab within script sessions

 
Ben Dehner
Trusted Contributor

cannot edit crontab within script sessions

This one's got me baffled. I've got crontab set up for some normal users. If you invoke 'crontab -e', you can modify and save the crontab file as normal. However, if you are within a 'script' session, that is

script somefile
crontab -e

crontab still invokes the editor (vi) as normal, but when you try to exit, it gives an error message

crontab: can't create your crontab file in the cdrontab directory.

Funny thing, I have no problems on our 11.23 system, but I see this problem on our 11.11 systems. And yes, I know capturing the output of a vi editor in a script is of dubious value, but that's another matter.
Trust me, I know what I'm doing
8 REPLIES 8
Peter Godron
Honored Contributor

Re: cannot edit crontab within script sessions

Ben,
when you run crontab -e it uses a temporary file to edit in vi. On exit it writes the data back to the original file.

Have you compared privs on /usr/bin/crontab ?
Ben Dehner
Trusted Contributor

Re: cannot edit crontab within script sessions

Priviledges on /usr/bin/crontab was one of the first things I checked; looks fine. (Perm 4555, owner/group = root/bin). I also checked the permission on the /var/spool/cron/crontabs directory, and those all look good.
Trust me, I know what I'm doing
Peter Nikitka
Honored Contributor

Re: cannot edit crontab within script sessions

Hi,

I definitly would not call "crontab -e" in a script.
Let another file be processed by your script, initialized via
crontab -l >tmpfile

After all modifications are done, perform something like

if crontab tmpfile
then rm tmpfile
else
# do error processing, tmpfile kept
fi

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Jonathan Fife
Honored Contributor

Re: cannot edit crontab within script sessions

/usr/bin/script doesn't have setuid, does it?

If you start script can you do a 'crontab -l > my.cron', then 'crontab my.cron', or do you get the error then, too?

If not, you could script a
crontab -l > my.cron && vi my.cron && crontab my.cron
command.
Decay is inherent in all compounded things. Strive on with diligence
Ben Dehner
Trusted Contributor

Re: cannot edit crontab within script sessions

Weird.

If I do

crontab -l > tmpfile
... edit tmpfile
crontab tmpfile

it works and I don't get the error.
Trust me, I know what I'm doing
A. Clay Stephenson
Acclaimed Contributor

Re: cannot edit crontab within script sessions

In any event, the 3 step process is, by far, the better approach. crontab -e is an accident waiting to happen and I never use it.
If it ain't broke, I can fix that.
Ben Dehner
Trusted Contributor

Re: cannot edit crontab within script sessions

I'm still confused, but I guess I have a suitable workaround. Thanks.
Trust me, I know what I'm doing
Ben Dehner
Trusted Contributor

Re: cannot edit crontab within script sessions

Using crontab -l > file will work for me.
Trust me, I know what I'm doing