Parameter from udev rule does not go into perl script

I am trying to create a udev rule that hides blocking devices (like usb drives) smaller than 64GB

The rule looks like this:

BUS=="usb", SUBSYSTEM=="block", ACTION=="add", PROGRAM="/data/diskSizeCheck.pl %k", RESULT!="ok", ENV{UDISKS_PRESENTATION_HIDE}="1", GOTO="usb_mount_end"

      

Where usb_mount_end

is just a label at the end of my rules file. %k

should be the kernel of the device (like sdb). But even when I hardcode 'sdb' as a parameter, this parameter never makes it for my perl script, and the disk always fails when checking the size, even if it's big enough. However, when I pass sdb via command line, it works.

Here is the perl script I am using:

#!/usr/bin/perl
use strict;
my $MINIMUM_DISK_SIZE = 64000000000;
my $kernel = $ARGV[0];
my $diskSize = `blockdev --getsize64 /dev/$kernel`;
chomp($diskSize);

if ($diskSize > $MINIMUM_DISK_SIZE) {
    print "ok";
} else {
    print "no";
}

      

The script is marked as executable and that's it, but when I wrote $kernel

to the text file, the text file looked empty, making me think that the variable is never passed.

How do %k

I pipe to my perl script?

Edit to add: I run everything as root.

Edit for further addition: I think the real problem is that RESULT is not displaying the output of my script correctly for some reason.

+3


source to share


1 answer


using

KERNEL=="sdc", SUBSYSTEMS=="block", ACTION=="add", PROGRAM="/usr/local/diskSizeCheck.pl %k", RESULT!="ok", ENV{UDISKS_PRESENTATION_HIDE}="1"

      

With diskSizeCheck.pl:



#!/usr/bin/perl
use strict;
use warnings;
open FH,">/tmp/diskSizeCheck";
print FH "Disk Size Check\n"; 

my $MINIMUM_DISK_SIZE = 64000000000;
my $kernel = $ARGV[0];
my $diskSize = `sudo blockdev --getsize64 /dev/$kernel`;
chomp($diskSize);

print FH "kernel = $kernel, $diskSize\n";

if ($diskSize > $MINIMUM_DISK_SIZE) {
    print FH "ok\n";
} else {
   print FH "no\n";
}

      

When inserting the USB stick, I got / tmp / diskSpaceSize:

Disk Size Check
sdc, 2005925888
no

      

+2


source







All Articles