|
Home > Archive > Unix administration > November 2005 > su and crontab
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| FrankNatoli 2005-11-21, 5:53 pm |
| Need to invoke "crontab" while running as "root" but setup a cron table
for another user. Tried the following:
su - <username> -c "crontab <filename>"
And get a message back "cannot read your cron file", i.e., as if the
<filename> argument was ignored and "-l" presumed instead.
Is there a way to do this?
Thanks.
| |
|
| FrankNatoli wrote:
> Need to invoke "crontab" while running as "root" but setup a cron table
> for another user. Tried the following:
>
> su - <username> -c "crontab <filename>"
>
> And get a message back "cannot read your cron file", i.e., as if the
> <filename> argument was ignored and "-l" presumed instead.
>
> Is there a way to do this?
>
> Thanks.
>
As root, crontab -e <user>
eg, crontab -e lp
| |
| FrankNatoli 2005-11-21, 5:53 pm |
| Thanks, but I'm afraid I left out a key requirement, i.e., that the
solution works in a shell script. "crontab -e lp" of course opens a
console edit session which is NG.
| |
| Chris F.A. Johnson 2005-11-21, 5:53 pm |
| On 2005-11-21, FrankNatoli wrote:
> Thanks, but I'm afraid I left out a key requirement,
Requirement for what?
Please read: <http://cfaj.freeshell.org/google>
> i.e., that the solution works in a shell script. "crontab -e lp" of
> course opens a console edit session which is NG.
--
Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence
| |
| FrankNatoli 2005-11-22, 5:56 pm |
| Found what was wrong.
su - <username> -c "crontab <filename>"
needs a full path for <filename>. Current directory is NG. Even
"./filename" doesn't work. Need full path.
| |
| Dave Hinz 2005-11-22, 5:56 pm |
| On 21 Nov 2005 14:58:33 -0800, FrankNatoli <FrankNatoli@worldnet.att.net> wrote:
> Thanks, but I'm afraid I left out a key requirement, i.e., that the
> solution works in a shell script. "crontab -e lp" of course opens a
> console edit session which is NG.
You're... editing a crontab...from within a script.
First: why?
Second: why not just, then, read it in, make the changes, and write it
out as a file? crontab -e gives you syntax checking, but the crontab
is, after all, just a file. You may even have some option for crontab
which is "validate syntax of existing crontab file".
| |
| FrankNatoli 2005-11-22, 5:56 pm |
| The script is installing a software package. One element of the
installation is setting up a crontab entry. Although the installation
is being run as "root", the software package will run as an ordinary
user, hence the need to setup a crontab entry while installing as root
for a non-root user.
Had I not found what was wrong with my original arguments, i.e., the
need to specify a full path for the crontab argument, I would probably
have done as you suggest, i.e., directly edit the system cron file.
| |
| Barry Margolin 2005-11-29, 2:50 am |
| In article <1132670316.645959.169760@g14g2000cwa.googlegroups.com>,
"FrankNatoli" <FrankNatoli@worldnet.att.net> wrote:
> Found what was wrong.
>
> su - <username> -c "crontab <filename>"
>
> needs a full path for <filename>. Current directory is NG. Even
> "./filename" doesn't work. Need full path.
You're probably confused about what the current directory is when the
crontab command is being run. I don't think su changes to the target
user's home directory, so it's looking for <filename> in root's home
directory.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
| |
| Mark Rafn 2005-11-29, 5:58 pm |
| > "FrankNatoli" <FrankNatoli@worldnet.att.net> wrote:
Barry Margolin <barmar@alum.mit.edu> wrote:[vbcol=seagreen]
>You're probably confused about what the current directory is when the
>crontab command is being run. I don't think su changes to the target
>user's home directory, so it's looking for <filename> in root's home
>directory.
I think the '-' parameter to su DOES cause it to change to the target user's
home directory. If that's different than the current directory, you'll need a
more complete path to <filename>.
--
Mark Rafn dagon@dagon.net <http://www.dagon.net/>
|
|
|
|
|