Hi Monk's, could somebody please help me. I am trying to make a wrapper script for the linux tmpwatch command, which removes files which havent been accessed for 'x' number of days from certain file systems.
The problem is I need to ssh on to certain hosts to run the tmpwatch command, or it will take forever to remove the files. It's proving hard to get the host name from the data structure I have made. The ssh part does not work because when it tries to retrieve the host name, it doesn't dereference it properly. This is what I have so far.
use warnings;
use vars qw(
$choicesystem
$choicehours
$option
$manager
$host
%hours
$hourkey
$row
);
$host = `hostname`;
our %filesystem = (
1 => {
name => "/filesystema",
host => { namehost1 => 1 },
},
2 => {
name => "/filesystemb",
host => { namehost2=> 2 },
},
3 => {
name => "/filesystemc",
host => { namehost3 => 3 },
},
);
%hours=(1=>"48",2=>"96");
#print Dumper(%filesystem); debug
chomp($host);
print "$host\n";
print "----------------Menu-----------------------------------------\n
+";
print "Please choose from the list of file systems\n";
print "-------------------------------------------------------------\n
+";
for $row (sort keys %filesystem){
my $system=$filesystem{$row};
print "$row\t $system->{ name }\n";
}
print "Please enter number>";
chomp($choicesystem = <STDIN>);
my $system = $filesystem{ $choicesystem };
print "----------------Menu-----------------------------------------\n
+";
print "Please choose the number of hours\n";
print "-------------------------------------------------------------\n
+";
foreach $hourkey (keys %hours){
print "$hourkey\t $hours{$hourkey} \n"
}
print "Please enter number>";
chomp($choicehours = <STDIN>);
my $choicehours = $hours{$choicehours};
if ( not $system->{host}{$host}){
system "/usr/bin/ssh $system->{host}#this part doesn't work, o
+nly brings back reference"; print "/usr/bin/sudo /usr/sbin/tmpwatch -
+f $choicehours $system->{name}\n";
}
else { print "/usr/bin/sudo /usr/sbin/tmpwatch -f $choicehours $system
+->{name}\n";}
I think the data structure that I've used needs to be changed, because the host name is a key rather than a value. I just don't know how to do it.
Any help is appreciated. Thanks.