###
### Copyright 2000-2007 University of Illinois Board of Trustees
### All rights reserved.
###
### PSGConf::Action::RemoveCrontab - remove action type for psgconf
###
### Campus Information Technologies and Educational Services
### University of Illinois at Urbana-Champaign
###
package PSGConf::Action::RemoveCrontab;
use strict;
use PSGConf::Action;
use PSGConf::Util;
our @ISA = qw(PSGConf::Action);
###############################################################################
### check method
###############################################################################
sub check
{
my ($self) = @_;
if (-e $self->{fullpath} || -l $self->{fullpath})
{
$self->{changed} = 1;
return 1;
}
return 0;
}
###############################################################################
### diff method
###############################################################################
sub diff
{
my ($self) = @_;
print "###############################################################################\n";
print "### DIFF FOR $self->{name}\n";
print "###############################################################################\n";
print "- REMOVE CRONTAB: $self->{name}\n\n";
}
###############################################################################
### do() method
###############################################################################
sub do
{
my ($self, $psgconf) = @_;
my ($cmd, $rc);
$cmd .= "su $self->{name} -c \""
if ($self->{name} ne 'root');
$cmd .= 'crontab -r" > /dev/null 2>&1';
###
### If the crontab -r command fails, then assume that cron
### actually does not know about the file and just remove
### it via unlink
###
if (($rc=PSGConf::Util::RunCommand($cmd, 1))) {
$rc=unlink ($self->{fullpath})
if ( -f $self->{fullpath} );
}
return !$rc;
}
###############################################################################
### documentation
###############################################################################
1;
__END__
=head1 NAME
PSGConf::Action::RemoveCrontab - crontab removal action class for PSGConf
=head1 SYNOPSIS
use PSGConf::Action::RemoveCrontab;
$psgconf->register_actions(
PSGConf::Action::RemoveCrontab->new(
'name' => '/path/to/crontab',
...
),
...
);
=head1 DESCRIPTION
The B<PSGConf::Action::RemoveCrontab> module provides a B<PSGConf> action class
for removing an entry from the filesystem (regular file, directory,
symlink, etc).
The B<PSGConf::Action::RemoveCrontab> class is derived from the
B<PSGConf::Action> class, but it defines/overrides the
following methods:
=over 4
=item check()
Checks to see if the file currently exists.
=item diff()
Prints a message indicating that the file needs to be removed.
=item do()
Removes the crontab entry.
=back
=head1 SEE ALSO
L<perl>
C<CE<lt>crontab(1)E<gt>>
L<PSGConf>
L<PSGConf::Action>
L<PSGConf::Util>
=cut
syntax highlighted by Code2HTML, v. 0.9.1