简体   繁体   中英

create variable from tail -f /var/logmessage

I'm trying to get a variable from /var/log/messages when the string "Attached" appears in /var/log/messages.

I've got so far, and stuck:

 sudo stdbuf -o0 tail -f -n0 /var/log/messages | awk  '{if ($9 == "Attached") print$8}' 

This gives the usb device dev id eg [sdc] when a USB device is plugged in. FRom here I plan to mount the device as exfat. I'm using Centos 7, which does not automount exfat. fuse-exfat and exfat-utils are installed.

You are using 'tail -f' which will never terminate (it will wait for additional log messages). You probably want to 'grep' from the file, and pick the first (or last)

device=$(sudo cat /var/log/messages | awk  '{if ($9 == "Attached") print $8 ; exit}')

The 'exit' can be used to pick the first match.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM