Sponsored Content
Top Forums Shell Programming and Scripting Fdisk and grep command not working in udev trigger Post 303023135 by lxdorney on Wednesday 12th of September 2018 10:24:27 AM
Old 09-12-2018
Fdisk and grep command not working in udev trigger

Hi Guys,

Can someone take a look at my scripts what missing, plugin usb drive the script is running can log all my echo but cannot execute command. Is there any configuration in linux or to my scripts need to add?.

What i want to achieve is every time I plugin the usbdisk automatic mount to /media/usb/test

Code:
cat /etc/udev/rules.d/100-mount-usb.rules

ACTION=="add", SUBSYSTEMS=="usb", ATTR{idVendor}=="8564", ATTR{idProduct}=="1000", RUN+="/bin/bash -c /usr/local/bin/test.sh"

Code:
cat /usr/local/bin/test.sh

#!/bin/bash

LOG_FILE=/opt/weekly_backup.log

DEVNAME=$(fdisk -l |grep FAT16 |awk '{print $1}')

echo "New usb device detected at $DEVNAME" >> $LOG_FILE

echo "mount $DEVNAME /media/usb/test" >> $LOG_FILE

mount $DEVNAME /media/usb/test &>> $LOG_FILE

Reload all rules in udev:
Code:
udevadm control --reload-rules

Trigger all udev rules:
Code:
udevadm trigger

Here the log ouput:
Code:
cat /opt/weekly_backup.log

New usb device detected at
mount  /media/usb/test
mount: can't find /media/usb/test in /etc/fstab or /etc/mtab


Last edited by lxdorney; 09-12-2018 at 12:06 PM..
 

10 More Discussions You Might Find Interesting

1. Linux

udev core 5

installed fedora core 5 on a pc with USB and some usual things. in boot up it is stopped at "Starting udev:". Its harddisk light is busy. is it reconfiguring the kernel?. what do to solve this problem?. (0 Replies)
Discussion started by: GJ2
0 Replies

2. Shell Programming and Scripting

How can I trigger another make command when one is finished?

Hello all I have to run manually make commands in our system the make compilations task's takes very long And I like to be able to run another make task right after one is finished. What is the best way to automate it ? (2 Replies)
Discussion started by: umen
2 Replies

3. Shell Programming and Scripting

Fdisk with grep problem

Hello! rescuecd:/var# fdisk -l | grep stupid Disk /dev/sda doesn't contain a valid partition table Disk /dev/sdb doesn't contain a valid partition table rescuecd:/var# It shows always this statement. Why? :( Raw fdisk -l shows rescuecd:/var# fdisk -l Disk /dev/sda: 750.1 GB,... (4 Replies)
Discussion started by: pug123
4 Replies

4. Shell Programming and Scripting

Grep command is not working when put into cron

Hi, I worte a script which runs perfect when i execute it manually. But when i scheduled into cron the grep command alone is not working. the sample script, /usr/bin/grep FTP $subfile > /tmp/tfsrec.dat tfs=`echo $?` if then echo "FTP FOUND" else echo "FTP NOT FOUND" Where... (5 Replies)
Discussion started by: thiru_cs
5 Replies

5. Filesystems, Disks and Memory

Udev label removes corresponding fdisk, sfdisk or lsvdev entry

I'm curious about the behavior where any udev labeled device causes that corresponding listing to disappear from fdisk, sfdisk, or in the case of RDAC, lsvdev. I have seen this on both EMC clariion and Sun Storagetek/Engenio 6540 arrays. We use RHEL5.1 and udev to create persistent labels for... (2 Replies)
Discussion started by: Radar
2 Replies

6. Shell Programming and Scripting

Pass params with Udev

Hello! I'm sorry if this is the false Forum, didn't really knew where to put it... My question: I have serveral USB-Sticks and wrote several Udev-Rules for theme, each Sticks needs to do something else, but all are using the same script (they have common tasks to do) and only some parts are... (2 Replies)
Discussion started by: al0x
2 Replies

7. Solaris

what is the fdisk -l command of SUN

I use fdisk -l command to see the attached hard disk drives in rhel5 and cntos 5.5 what is the same command for sun 5.9 (4 Replies)
Discussion started by: z_haseeb
4 Replies

8. Shell Programming and Scripting

problem in automating "fdisk" command using send and expect

hi i want to automate fdisk command . i spawned a process containing fdisk command from a process and tried to send the options to fdisk promt from that process. but that spawed process is notstarting itself help me out trying for two days :wall: my code: #!/bin/bash echo... (5 Replies)
Discussion started by: jagak89
5 Replies

9. BSD

OpenBSD fdisk - Linux fdisk compatibility ?

Hello, MBR partition table made by linux fdisk looks certainly not correct when printed by openbsd fdisk: Partition table created on linux (centos 6.3): # fdisk -l /dev/sdc Disk /dev/sdc: 10.7 GB, 10737418240 bytes 255 heads, 63 sectors/track, 1305 cylinders Units = cylinders of 16065 *... (2 Replies)
Discussion started by: vilius
2 Replies

10. UNIX for Beginners Questions & Answers

Grep command is not working

I have made a program that reads a text file and checks for palindromic words and then outputs them. They each appear on a new line with a count of the number of occurences beside each of the words. Requirements for being classed as palindrome are that the word must have at least 3 letters and... (7 Replies)
Discussion started by: greenhouse91
7 Replies
sane-usb(5)						   SANE Scanner Access Now Easy 					       sane-usb(5)

NAME
sane-usb - USB configuration tips for SANE DESCRIPTION
This manual page contains information on how to access scanners with a USB interface. It focusses on two main topics: getting the scanner detected by the operating system kernel and using it with SANE. This page applies to USB most backends and scanners, as they use the generic sanei_usb interface. However, there is one exceptions: USB Scanners supported by the microtek2 backend need a special USB kernel driver, see sane-microtek2(5) for details. QUICK START
This is a short HOWTO-like section. For the full details, read the following sections. The goal of this section is to get the scanner detected by sane-find-scanner(1). Run sane-find-scanner. If it lists your scanner with the correct vendor and product ids, you are done. See section SANE ISSUES for details on how to go on. sane-find-scanner doesn't list your scanner? Does it work as root? If yes, there is a permission issue. See the LIBUSB section for details. Nothing is found even as root? Check that your kernel supports USB and that libusb is installed (see section LIBUSB). USB ACCESS METHODS
For accessing USB devices, the USB library libusb is used. There used to exist another method to access USB devices: the kernel scanner driver. The kernel scanner driver method is deprecated and shouldn't be used anymore. It may be removed from SANE at any time. In Linux, the kernel scanner driver has been removed in the 2.6.* kernel series. Only libusb access is documented in this manual page. LIBUSB
SANE can only use libusb 0.1.6 or newer. It needs to be installed at build-time. Modern Linux distributions and other operating systems come with libusb. Libusb can only access your scanner if it's not claimed by the kernel scanner driver. If you want to use libusb, unload the kernel driver (e.g. rmmod scanner under Linux) or disable the driver when compiling a new kernel. For Linux, your kernel needs support for the USB filesystem (usbfs). For kernels older than 2.4.19, replace "usbfs" with "usbdevfs" because the name has changed. This filesystem must be mounted. That's done automatically at boot time, if /etc/fstab contains a line like this: none /proc/bus/usb usbfs defaults 0 0 The permissions for the device files used by libusb must be adjusted for user access. Otherwise only root can use SANE devices. For Linux, the devices are located in /proc/bus/usb/ or in /dev/bus/usb, if you use udev. There are directories named e.g. "001" (the bus name) con- taining files "001", "002" etc. (the device files). The right device files can be found out by running scanimage -L as root. Setting per- missions with "chmod" is not permanent, however. They will be reset after reboot or replugging the scanner. Usually udev or for older distributions the hotplug utilities are used, which support dynamic setting of access permissions. SANE comes with udev and hotplug scripts in the directory tools/udev and tools/hotplug. They can be used for setting permissions, see /usr/share/doc/sane-backends-1.0.24/README.linux, tools/README and the README in the tools/hotplug directory for more details. For the BSDs, the device files used by libusb are named /dev/ugen*. Use chmod to apply appropriate permissions. SANE ISSUES
This section assumes that your scanner is detected by sane-find-scanner. It doesn't make sense to go on, if this is not the case. While sane-find-scanner is able to detect any USB scanner, actual scanning will only work if the scanner is supported by a SANE backend. Informa- tion on the level of support can be found on the SANE webpage (http://www.sane-project.org/), and the individual backend manpages. Most backends can detect USB scanners automatically using "usb" configuration file lines. This method allows to identify scanners by the USB vendor and product numbers. The syntax for specifying a scanner this way is: usb VENDOR PRODUCT where VENDOR is the USB vendor id, and PRODUCT is the USB product id of the scanner. Both ids are non-negative integer numbers in decimal or hexadecimal format. The correct values for these fields can be found by running sane-find-scanner, looking into the syslog (e.g., /var/log/messages) or under Linux by issuing the command "cat /proc/bus/usb/devices". This is an example of a config file line: usb 0x055f 0x0006 would have the effect that all USB devices in the system with a vendor id of 0x55f and a product id of 0x0006 would be probed and recog- nized by the backend. If your scanner is not detected automatically, it may be necessary to edit the appropriate backend configuration file before using SANE for the first time. For a detailed description of each backend's configuration file, please refer to the relevant backend manual page (e.g. sane-mustek_usb(5) for Mustek USB scanners). Do not create a symlink from /dev/scanner to the USB device because this link is used by the SCSI backends. The scanner may be confused if it receives SCSI commands. ENVIRONMENT
SANE_DEBUG_SANEI_USB If the library was compiled with debug support enabled, this environment variable controls the debug level for the USB I/O subsys- tem. E.g., a value of 128 requests all debug output to be printed. Smaller levels reduce verbosity. Values greater than 4 enable libusb debugging (if available). Example: export SANE_DEBUG_SANEI_USB=4. SEE ALSO
sane(7), sane-find-scanner(1), sane-"backendname"(5), sane-scsi(5) AUTHOR
Henning Meier-Geinitz <henning@meier-geinitz.de> 14 Jul 2008 sane-usb(5)
All times are GMT -4. The time now is 02:56 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy