Re: Easiest Way in Perl to check Whether a Disk is Mounted
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 -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Easiest Way in Perl to check Whether a Disk is Mounted
You can check if something is mounted by comparing which device a specific directory is on and comparing it to its parent directory. $ cat chk_mount.pl #!/usr/bin/perl -w use strict; use Fcntl ':mode'; my $A = $ARGV[0] // "/"; my $B = $ARGV[1] // "/var"; my @Ast = stat $A; my @Bst = stat $B; if ( S_ISDIR($Ast[2]) && S_ISDIR($Bst[2]) ) { if ($Ast[0] == $Bst[0]) { print "$Ast[0], $Bst[0]: same filesystem\n"; } else { print "$Ast[0], $Bst[0]: different filesystem\n"; } } else { print "not directories\n"; } $ ./chk_mount.pl / /usr 2306, 2308: different filesystem $ ./chk_mount.pl /usr/bin /usr 2308, 2308: same filesystem $ Regards, /Karl Hammar -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Easiest Way in Perl to check Whether a Disk is Mounted
* Martin McCormick [24-06/01=Sa 09:25 -0500]: > [...] determine whether a file system is mounted such as > $ mount |grep horseradish > [...] I think perl -e 'print grep m[/horseradish],`mount`' is hard to beat for its simplicity. Note I'm using Perl's built-in grep; there's no need to run the system's grep. You can code something like if( grep m[/horseradish],`mount` ){ useMountedHorseradish(); }else{ dealWithUnmountedHorseradish(); } because Perl's grep will return an empty string if 'horseradish' isn't found in `mount`, and an empty string is logically false, whereas any nonempty string is logically true. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Easiest Way in Perl to check Whether a Disk is Mounted
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.
Re: Easiest Way in Perl to check Whether a Disk is Mounted
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. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Easiest Way in Perl to check Whether a Disk is Mounted
In unix-like OS's, there are the mount and mountpoint commands that can help one determine whether a file system is mounted such as $ mount |grep horseradish. If there is a file system defined in fstab which might look like UUID="B159-BB80" /horseradish vfat rw,user,noauto 0 0 and it is not presently mounted, the mount command should not have any output containing the name horseradish. If the device with the correct UUID is mounted, the command of mount which shows all mounted file systems will contain the horseradish line and also where it is mounted and so forth but the big difference is that you get a string if /horseradish is mounted and zilch if it is not. There is also a unix command of mountpoint which will say that horseradish, in this case, is not a mount point if it is not mounted or that it is a mountpoint if it has a FS mounted on it. The perl script I am working on should check to see if a device is mounted with the requested name and do one thing if it is and something else if it is not. 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. Martin McCormick -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/