Results 1 to 8 of 8
I am new to linux scripting, but I have programming experience.
I need to save the UUID for /dev/sda1 as a variable, lets call it id
I am sure there ...
- 07-22-2010 #1Just Joined!
- Join Date
- Jul 2010
- Posts
- 11
[SOLVED] UUID save as a variable
I am new to linux scripting, but I have programming experience.
I need to save the UUID for /dev/sda1 as a variable, lets call it id
I am sure there is a way to do this with the awk and blkid commands, but I do not know any of this well enough yet to figure it out and after a couple of hours of reading I am still lost as to exactly how I would put this together
I need to save the uuid as a variable so that I can run an if statement with it
if [ -f /media/$id/file ]
then
echo "copy successful"
else
echo "oh crap!"
honestly all I need the uuid for but I cant check this by doing the same if with /dev/sda1/file so I need to be able to save the uuid into a variable
thanks
- 07-22-2010 #2Linux User
- Join Date
- Jan 2007
- Location
- cleveland
- Posts
- 452
welcome to the forum
something like this might work--
id=`vol_id /dev/sda1 | grep ID_FS_UUID | head -n -1 | cut -b 12-`the sun is new every day (heraclitus)
- 07-23-2010 #3Just Joined!
- Join Date
- Jul 2010
- Posts
- 11
I tried the above exactly as typed, when I echo $id I get the entire thing as one long char string, the commands inside of that ' ' are completely ignored and considered just text.
I took out the ' ' as well as adding the file path in front of vol_id so the compiler knows where to find it, but even with a sudo before id=........ When I echo the variable nothing happens
- 07-23-2010 #4Linux Guru
- Join Date
- Nov 2007
- Posts
- 1,695
Google: bash scripting
Backticks
Code:id=`vol_id -u /dev/sda1`
- 07-23-2010 #5Just Joined!
- Join Date
- Jul 2010
- Posts
- 11
I always get a command not found on vol_id I dont think the live linux disc I am using has that command on it.
if I use blkid /dev/sda1 -s UUID
I get almost what I need
/dev/sda1: UUID="C888848E88847D26"
anyone able to show me how to use awk or grep to just get what is in the quotes?
I am willing to learn but the articles I find on how to use the commands dont show how to use them in the way I need to, and I don't have the time here at work to dig through 100 google search results to find the information I need.
- 07-23-2010 #6Linux Guru
- Join Date
- Nov 2007
- Posts
- 1,695
Code:man cut
Code:blkid /dev/sda1 -s UUID | cut -d \" -f 2
- 07-23-2010 #7Just Joined!
- Join Date
- Jul 2010
- Posts
- 11
THANK YOU
This gets me exactly the 1 piece of information I need.
The only issue I have left is that for whatever reason it is not saving it into the variable (code I am using below)
uid= sudo blkid /dev/sda1 -s UUID |cut -d\" -f 2
the line seems to ignore the uid= command and just displays the information, so when I try to echo the variable it is empty. If anyone has an idea let me know. otherwise I am 99% there and can probably figure it out on my own with a little tweaking
- 07-23-2010 #8Just Joined!
- Join Date
- Jul 2010
- Posts
- 11



