-1

i'am running live linux, which run from FAT32 flashdisk since i run a lot of pc using this flashdisk, its difficult to identify which IP for its hostname, since its ip need to be dynamically determined by dhcp, so i want set their hostname by volume label that is set on its flasdisk

i can use blkid | grep sda1 or blkid | grep "vfat"

the results is

#blkid | grep sda1
/dev/sda1: LABEL="SLAX" UUID="FAEB-513E" TYPE="vfat"

#blkid | grep "vfat"
/dev/sda1: LABEL="SLAX" UUID="FAEB-513E" TYPE="vfat"

but how to parse its label and set to my hostname on boot?

uray
  • 235
  • 4
  • 7
  • this is not off topic, i need this to administrate a lot of live usb linux rig, do people even know crypto mining farm running on a lot of disk-less linux machine to do computation using hundreds of GPUs – uray Apr 15 '14 at 20:17

1 Answers1

3
hostname $(blkid | perl -lne '/LABEL="(.*?)".*vfat/ and print $1')

or

hostname $(blkid | perl -lne '/sda1.*LABEL="(.*?)"/ and print $1')

Since you don't have Perl, your grep may not have -P. if it does, try

hostname $(blkid | grep -Po 'LABEL="\K.*?(?=".*vfat)')

or

hostname $(blkid | grep -Po 'sda1: LABEL="\K.*?(?=".*)')

For a pure Bash version:

pattern='sda1.*LABEL="([^"]+)"'    # or: pattern='LABEL="([^"]+)".*vfat'
[[ $(sudo blkid) =~ $pattern ]]
hostname "${BASH_REMATCH[1]}"
Dennis Williamson
  • 60,515
  • 14
  • 113
  • 148