ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
uuid=($(echo "$block_new" | awk 'BEGIN{RS="UUID="}/-/{gsub(/ .*/,"");print}'))
for d in ${uuid[@]}; do
dev=$(blkid | grep $d | awk 'BEGIN{FS=":"} {print $1}');
if [[ -z $dev ]]; then
echo $dev
else
echo "uuid $uuid not found in list of devices"
fi;
done
Pherhaps I understand right.
I run su or sudo then run blkid else it says blkid not found
This operations under super user mode.
blkid I use offten to get informations like dev,uuid and label
blkid -U uuid searches the concrete device.
I god output:
uuid eab515e9-bc3e-4024-9f01-55fddaa0fb1c
e12487ff-6d6f-44c4-9e03-33f545b3b798 not found
That's right
However
I don't know how to make from e.g. /dev/sda3 the hd(0,2) ... Should I use awk to generate?
Edit:
But the last code I posted dosn't work right :-(
It should to show:
/dev/sda3
uuid e12487ff-6d6f-44c4-9e03-33f545b3b798 not found
1. contidion -z fail
2. the d var. is array not a string?
Edit:
Yeah the d var contains this sting or array
eab515e9-bc3e-4024-9f01-55fddaa0fb1c
e12487ff-6d6f-44c4-9e03-33f545b3b798
not separated... Bad too bad
Thanks for the info, I too get results when using the sudo, but can use the -U option as normal user.
Yes it will return an array unless there is only one device attached (unlikely in modern systems)
Another issue you might face may be if someone has a RAID/LVM setup (like mine) and the output is even less useful:
I am confused from your blkid list :-(
For the 2nd uuid of your list on 1st column it returns:
/dev/mapper/isw_cehbidjbfj_RaidME2
So how this corresponds with your menu.lst if is this a system device?
I ask about your menu.lst root=??? argument
I was just thinking (sometimes this can be bad lol) you are going to a lot of trouble to alter an already unique identifier.
Just wondering if this is the best course of action??
OLD_IFS=$IFS; IFS="|";
content=($(awk 'BEGIN{RS=""; ORS="|"}/^title/' /boot/grub/menu.lst))
i=-1;
for block in ${content[@]}; do; block= block_new ; ... done;
Edit
This is the block from my last thread.
I just wonder why there is not IFS=$"|"; And why I don't see "|" on output when I run echo $IFS. It shows " "
By default IFS is whitespace. If you run the following you will see what it is set to:
Code:
$>set | grep IFS
IFS=$' \t\n'
This is the output on my test machine. It behaves like an or for each item. So by default my machine would split on
a space or a tab or a new line.
Therefore doing echo $IFS will only show you an empty line.
Quote:
Problem found with IFS
Cannot see why this would be the case??
I presume you are doing a for within a for loop, the first would split content so block = stanza.
awk would then work on block and return a new array .... ahhh there it is ... took me a little bit,
because the new array has zero pipes in it it says that all data, ie both uuid's and new lines are one field.
Tricky
Maybe you need to rethink exactly what it is you want to change in menu.lst, ie is it necessary to break up each stanza
or maybe make your necessary replacements in place???
A really nasty hack would be to alter the IFS backward and forward in the loop, but I see this as potentially very messy and
may just run into more trouble if you expand further.
Just one extra word ... and i know this isn't really your fault per se, but if you are going to test something, like the code we have been
working on in this thread, you should first test in isolation and then add into your script, then we would have come across this issue
as putting it together with older script and not bashing our heads on whether or not it is doing the right thing, which it was.
Just a thought
IFS=$OLD_IFS; # In outer loop should be IFS="|";
uuid=$( echo $block_new | awk '/.*UUID=/{ x=gensub(/.*UUID=([^ ]+).*/,"\\1","g"); print x}')
# TATO VARIANTA ZACHOVÁ JEN PRVNÍ VÝSKYT UUID. (simplest way to get the first uuid to be 2 simple subs)
# uuid=$( echo "$block_new" | awk '/UUID/{sub(/.*root=UUID=/,"");sub(/ .*/,"");print}')
clear
uuid=($(echo "$block_new" | awk 'BEGIN{RS="UUID="}/-/{gsub(/ .*/,"");print}'))
for d in ${uuid[@]}; do
dev=$(blkid | grep $d | awk 'BEGIN{FS=":"} {print $1}');
if [[ ! -z $dev ]]; then
echo $dev
else
echo "uuid $d nenalezeno v seznamu zarizeni"
fi;
done
Now I try to prepare the hd(?,?) string. I have some code but I don't know how to define and when should be hd0 and when hd1. Is there always hd0 | hd1 or hd0 | hd1 | hd2 | hd3 according to sda/hda | sdb/hdb | sdc/hdc | sdd/hdd ? What posibilities we have?
I just had a thought and would like to back up a little
We seem to have missed the point that in any single menu.lst file there would only ever be a handful of UUIDs.
Meaning, root (/) will be assigned a UUID and the same for any other systems on the single machine, but, the UUID for root
would always be the same (as it is unique and only assigned to one value) and therefore you could now parse the entire file
for that UUID and change it and so on for the other UUIDs.
I thought it worth mentioning as, for example, the menu.lst you sent me had 20+ stanzas, but ultimately everywhere that root
is being referred to will have the same UUID.
So if the only reason to break the menu.lst into stanzas and then get the UUIDs to then be changed into hdx,y - I think this may be able to be done easier.
Let me know what you think or if you don't understand, ask me and I will see if I can draft a suggestion.
As for your recent post:
Quote:
Is there always hd0 | hd1 or hd0 | hd1 | hd2 | hd3 according to sda/hda | sdb/hdb | sdc/hdc | sdd/hdd ?
In a "normal" computer I would imagine it unlikely to have more than say 3 or 4 drives, but ultimately I am guessing there is no finite limit
if you could get your computer to have enough connections for a hundred drives I guess it is possible.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.