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.

In reply to A wrapper script for tmpwatch in Linux written in Perl by wishartz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.