[Pdx-pm] cron or sudo editor interface?
Randal L. Schwartz
merlyn at stonehenge.com
Wed Aug 4 11:41:23 CDT 2004
>>>>> "Chris" == Chris Dawson <cdawson at webiphany.com> writes:
Chris> Does anyone know of a good way to manipulate crontab files or sudo
Chris> files? Usually I use visudo or crontab -e to edit these files, but I
Chris> would like to manipulate them programmatically. I can simply copy the
Chris> files over to the correct place, but I wish there were a simple
Chris> interface to do this so that I could add lines without worrying I am
Chris> overwriting something else that has been added. Nothing stands out
Chris> on CPAN. Does anyone have ways they edit/manipulate these files?
"crontab -e" uses the EDITOR environment variable, calling it with
a temp file name as its first and only parameter, and incorporating
that as the new crontab if the file is updated. Hence, you can
have two scripts. Script A:
#!/usr/bin/perl
$ENV{EDITOR} = "scriptB";
system "crontab", "-e";
Script B:
#!/usr/bin/perl
$^I = "~"; # trigger in-place edit
while (<>) {
print; # copy old lines to new lines
# make your changes here, for example to add at eof:
print ".. .. .. .. new line here .. ..\n" if eof;
}
And that should work just fine.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn at 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!
More information about the Pdx-pm-list
mailing list