|
Home > Archive > Unix Shell > April 2004 > How to edit a crontab file within a script when not root
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]
| Author |
How to edit a crontab file within a script when not root
|
|
|
| I am looking for an automated way to edit a crontab, as root I can use sed
and modify the file. As a non root user I am not allowed to edit the file.
IS there a way to create a shell script that my userid can execute, that
will have root privileges to modify the command. I want to send this to all
the workstations when installing some software?
Thansk
| |
| Chris F.A. Johnson 2004-04-25, 1:34 pm |
| On Sun, 25 Apr 2004 at 16:19 GMT, Tom wrote:
> I am looking for an automated way to edit a crontab, as root I can use sed
> and modify the file. As a non root user I am not allowed to edit the file.
>
> IS there a way to create a shell script that my userid can execute, that
> will have root privileges to modify the command. I want to send this to all
> the workstations when installing some software?
You don't need root privileges. Just edit a file and use crontab
to install it:
crontab -l > $HOME/crontab
fix_up $HOME/crontab ## script to edit crontab file
crontab $HOME/crontab
--
Chris F.A. Johnson http://cfaj.freeshell.org/shell
========================================
===========================
My code (if any) in this post is copyright 2004, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License
| |
| Randal L. Schwartz 2004-04-25, 1:34 pm |
| >>>>> "Tom" == Tom <tcarmich@nortelnetworks.com> writes:
Tom> I am looking for an automated way to edit a crontab, as root I can use sed
Tom> and modify the file. As a non root user I am not allowed to edit the file.
Tom> IS there a way to create a shell script that my userid can execute, that
Tom> will have root privileges to modify the command. I want to send this to all
Tom> the workstations when installing some software?
If this is vixie cron, just set an env var to your script:
EDITOR=/your/script crontab -e
/your/script will get invoked with /tmp/some-name containing the crontab.
Just rewrite the file, and exit clean. If the crontab is syntax-valid,
then it gets installed as the new crontab.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment PERL training!
|
|
|
|
|