Re: Easiest Way in Perl to check Whether a Disk is Mounted

[email protected] (Jesús Lozano Mosterín) Thu, 6 Jun 2024 08:27:10 +0200
Newsgroups perl.beginners
Organization Lozano Mosterín Patrimonio, CB
Message-ID <[email protected]>
El 5/6/24 a las 22:28, Mike escribió:
>
> I sure couldn't figure out how to test for a mount
> with that module.  And I did go to 'man 2 mount'.
> Still couldn't figure it out.
>
>
> Mike
>
>
> On 6/1/24 18:29, Jeff P via beginners wrote:
>>
>>
>>
>>> Of course, I can use system calls and call the unix mount
>>> or mountpoint applications but is there a proper perl way to do
>>> this since system calls are not as elegant?  Thank you.
>>
>> How about this module from metacpan?
>> https://metacpan.org/pod/Sys::Linux::Mount
>>
>> regards.
>>
>

Try:


my $out = `mount | tail -n 1` ;

if ( $out =~ /\/dev\/sdb1/ ) {

          say '/dev/sdb1 mounted!';

}else{

          die "Mount failed";

}


Best regards,


Jesús