[英]Parameter from udev rule not passing into perl script
I'm trying to create a udev rule that hides block devices (ie usb drives) with a size less than 64 GB 我正在尝试创建一个隐藏块设备(即usb驱动器)的udev规则,其大小小于64 GB
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. 其中
usb_mount_end
只是我的规则文件末尾的标签。 %k
is supposed to be the device kernel (ie sdb). %k
应该是设备内核(即sdb)。 But even when I hardcode 'sdb' as a parameter, that parameter never makes it to my perl script, and the disk always fails the size check even if it's large enough. 但即使我将'sdb'硬编码为参数,该参数也永远不会进入我的perl脚本,并且即使磁盘足够大,磁盘也始终无法通过大小检查。 When I pass sdb in via the command line, though, it works.
但是,当我通过命令行传递sdb时,它可以工作。
Here is the perl script I'm using: 这是我正在使用的perl脚本:
#!/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 everything, but when I wrote $kernel
to a text file, the text file came up blank, leading me to believe the variable is never passed in. 该脚本被标记为可执行文件和所有内容,但是当我将
$kernel
写入文本文件时,文本文件显示为空白,这使我相信该变量永远不会被传入。
How do I pass in %k
to my perl script? 如何将
%k
传递给我的perl脚本?
Edit to add: I'm running everything as root. 编辑添加:我以root身份运行所有内容。
Edit to further add: I think the real problem is that RESULT isn't properly capturing the output of my script for some reason. 编辑以进一步添加:我认为真正的问题是RESULT由于某种原因没有正确捕获我的脚本的输出。
using 运用
KERNEL=="sdc", SUBSYSTEMS=="block", ACTION=="add", PROGRAM="/usr/local/diskSizeCheck.pl %k", RESULT!="ok", ENV{UDISKS_PRESENTATION_HIDE}="1"
With diskSizeCheck.pl: 使用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";
}
On inserting a USB stick I got /tmp/diskSpaceSize: 在插入USB记忆棒时我得到/ tmp / diskSpaceSize:
Disk Size Check
sdc, 2005925888
no
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.