2012-10-10 5 views
7

में तर्क के रूप में ATTR {idVendor} पास करें मेरे पास एक स्क्रिप्ट है जो विक्रेता 1004 द्वारा यूएसबी डिवाइस से कनेक्ट होने पर चलती है। Udev नियम मैं काम का उपयोग कर रहा हूँ और इस तरह दिखता है।udev स्क्रिप्ट

SUBSYSTEM=="usb", ATTR{idVendor}=="1004", RUN+="/var/www/beta/trigger.php" 

अब जब भी कोई यूएसबी डिवाइस कनेक्ट होता है, तो मैं इस स्क्रिप्ट को चलाने की इच्छा रखता हूं, और विक्रेता आईडी को पैरामीटर के रूप में पास करता हूं। (तो स्क्रिप्ट तय कर सकते हैं कि क्या यह चलाने के लिए है या नहीं।)

एक पैरामीटर जो स्क्रिप्ट में पहुँचा जा सकता है अब तक काम किया है जोड़ना:

SUBSYSTEM=="usb", RUN+="/var/www/beta/trigger.php myparam" 

किसी कृपया मुझे बताओ कैसे बदलने के लिए कर सकते हैं ATTR {idVendor} के मूल्य के साथ "myparam"? मैंने सभी प्रकार के संयोजनों की कोशिश की है, लेकिन मुझे अपेक्षित परिणाम कभी नहीं मिला ...

बहुत बहुत धन्यवाद!

+0

कृपया संपादित आपके प्रश्न "कुछ प्रकार के संयोजन" को शामिल करने के लिए मुश्किल है यह बताना मुश्किल है कि आप कैसे हैं आ रहा है, और आप किस उपकरण का उपयोग करने की कोशिश की है। सौभाग्य। – shellter

उत्तर

7

udev आपके लिए कई पर्यावरण चर जो आप उपयोग कर सकते हैं, ID_VENDOR के बीच सेट कर सकते हैं। उस छोटी सी स्क्रिप्ट का प्रयास करें:

#!/bin/bash 

echo "Called by udev" >> /tmp/testenv 
env >> /tmp/testenv 
echo "Vendor id is $ID_VENDOR" >> /tmp/testenv 

इसे एक नियम में रखें, और आप देखेंगे कि आपके लिए कितनी चीजें स्थापित की गई हैं।

+1

बहुत बहुत धन्यवाद! PHP में मैं इन पर्यावरणीय चरों को $ _SERVER के माध्यम से एक्सेस कर सकता था, इसलिए मैंने उदा। विक्रेता आईडी के लिए $ _SERVER ['ID_VENDOR_ID'] '। – joshtucker

+0

मैं इस चर का परीक्षण करता हूं लेकिन फ़ाइल में मुद्रित कुछ भी नहीं! –

17

बस इस उत्तर को जोड़ने के लिए, udev आपको RUN और PROGRAM पर तर्क देने देता है।

udev आदमी पृष्ठ से:

The NAME, SYMLINK, PROGRAM, OWNER, GROUP, MODE and RUN fields support simple 
    printf-like string substitutions. The RUN format chars gets applied after 
    all rules have been processed, right before the program is executed. It 
    allows the use of device properties set by earlier matching rules. For all 
    other fields, substitutions are applied while the individual rule is being 
    processed. 

उदाहरण के लिए, अगर आप इस तरह एक नियम हो सकता है:

# Passes major, minor and serial number as parameters to script. 
ACTION=="add", SUBSYSTEM=="usb", RUN+="/tmp/test.sh %M %m $attr{serial}" 

उपलब्ध प्रतिस्थापन हैं:

$kernel, %k 
     The kernel name for this device. 

    $number, %n 
     The kernel number for this device. For example, ´sda3´ has kernel number 
     of ´3´ 

    $devpath, %p 
     The devpath of the device. 

    $id, %b 
     The name of the device matched while searching the devpath upwards for 
     SUBSYSTEMS, KERNELS, DRIVERS and ATTRS. 

    $driver 
     The driver name of the device matched while searching the devpath 
     upwards for SUBSYSTEMS, KERNELS, DRIVERS and ATTRS. 

    $attr{file}, %s{file} 
     The value of a sysfs attribute found at the device, where all keys of 
     the rule have matched. If the matching device does not have such an 
     attribute, follow the chain of parent devices and use the value of the 
     first attribute that matches. If the attribute is a symlink, the last 
     element of the symlink target is returned as the value. 

    $env{key}, %E{key} 
     A device property value. 

    $major, %M 
     The kernel major number for the device. 

    $minor, %m 
     The kernel minor number for the device. 

    $result, %c 
     The string returned by the external program requested with PROGRAM. A 
     single part of the string, separated by a space character may be 
     selected by specifying the part number as an attribute: %c{N}. If 
     the number is followed by the ´+´ char this part plus all remaining 
     parts of the result string are substituted: %c{N+} 

    $parent, %P 
     The node name of the parent device. 

    $name 
     The current name of the device node. If not changed by a rule, it 
     is the name of the kernel device. 

    $links 
     The current list of symlinks, separated by a space character. The 
     value is only set if an earlier rule assigned a value, or during a 
     remove events. 

    $root, %r 
     The udev_root value. 

    $sys, %S 
     The sysfs mount point. 

    $tempnode, %N 
     The name of a created temporary device node to provide access to the 
     device from a external program before the real node is created. 

    %% 
     The ´%´ character itself. 

    $$ 
     The ´$´ character itself.