Fdisk and grep command not working in udev trigger

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Fdisk and grep command not working in udev trigger
# 15  
Old 09-12-2018
Ah, bajeezus.. I somehow forgot this was about udev! Are there any errors in the system logs (dmesg, etc.)?
# 16  
Old 09-12-2018
Here what happened when issued run
udevadm trigger


cat 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

and here the logs also when plugin my usb to the server, which is I get sameoutput in my log.

cat 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

Im running in Centos 6.9


------ Post updated at 08:20 PM ------

no error in dmesg sir
# 17  
Old 09-12-2018
OK, well apologies for the slight tangent I sent us off on, but again it comes back to this "DEVNAME" thing.

Before, or after, when you call fdisk..

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

can you add some debug to the log file?

fdisk -l |grep FAT16 |awk '{print $1}' 2>&1 >> $LOG_FILE

It seems that's not doing what you think it should be. Again, as previously suggested, you should fully qualify the commands (/usr/bin/grep, etc.) - shouldn't make any assumptions about the environment udev is using when it does stuff.

If you change all of the ">> $LOG_FILE" to "&>> $LOG_FILE", you'll also log all the errors, if there are any.
# 18  
Old 09-13-2018
cat  /usr/local/bin/test.sh



DEVNAME=$(/sbin/fdisk -l |/bin/grep FAT16 |awk '{print $1}') 2>&1 >> $LOG_FILE

#fdisk -l |grep FAT16 |awk '{print $1}' 2>&1 >> $LOG_FILE

sleep 2

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

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

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

running this command
udevadm trigger

is working here the output of log

cat /opt/weekly_backup.log

New usb device detected at /dev/sdb1
mount /dev/sdb1 /media/usb/test

pluging the usb here the output:

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

but if I put manually the

and plugin the usb is working
# 19  
Old 09-13-2018
I'll agree with Scott. It looks like something is not being set, or is not mounted to set. Maybe if you post the output of "mount" and "fdisk -l" we can see what's missing.
# 20  
Old 09-13-2018
Here's the output

fdisk -l

Disk /dev/sdb: 8019 MB, 8019509248 bytes
255 heads, 63 sectors/track, 974 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x78a9e380

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *           1         975     7830528    c  FAT16
Partition 1 has different physical/logical endings:
     phys=(973, 254, 63) logical=(974, 250, 44)

# 21  
Old 09-13-2018
Try "enhanced logging":

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

and post the log file. Will that be the only disk having the FAT16 type?

Please also print the user that the script is executed under.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
Login or Register to Ask a Question

Featured Tech Videos