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
I'm setting up a machine that's going to be used to test randomly connected tape drives one at a time, and as such, I'm writing the test routine using mt in a bash script, for user-friendliness. The problem is the block device name changes on occasion as tape drives are swapped out and busses are rescanned, so I can't "hard code" a block name into the script.
I know programs like lsscsi and hwinfo will give you block device names as part of their output, but I can't seem to grep anything in such a way as to have the final output be just the block name (ie /dev/st2, or optimally 'st2'), so that I can just have the script read said output, and drop it into the necessary variable.
I changed my menu.lst to use root=UUID=<long uuid string> instead of the good old root=/dev/sd...
I did that because, if I boot with a usb drive attached to my computer, sda become sdb and therefor nothing works anymore since my friend Kernel can't mount it's root partition. BTW, it works wonders using the UUIDs. The story darkens each time there is a kernel update, dist-upgrade resets my menu.lst back using the /dev/sd... format. and BANG... no more booting again. I am good to change my menu.lst back each time.
I realized that my understanding of UUIDs in Linux to specifying hard disk partitions may be erroneous.
The proverbial wisdom is that one should not use hard-coded device specifications in fstab and in the boot menu.lst, such as /dev/sda1 etc. The reason normally given is that if hard disk order changes or the order of partitions change, then the entries will be incorrect since they are hardcoded to partitions following a specific order.
So my understanding was that using hard disk labels, in the form of LABEL=xxxx, or UUIDs in the form of UUID=some-uuid, would prevent these problems when disk order or partition order changed.
I decided to avoid the use of LABEL in case I wanted to change the LABEL on a partition to make the names of partitions more easily identifiable. I then thought that UUID was ideal since it never changed for a partition no matter even if I moved that partition to another drive or added another hard drive and thus changes the order of hard drives on my computer. I essentially thought that once UUID was determined for a partition, it never changed but was somehow part of the partition in the hardware of my computer.
Then I became curious of how a UUID was determined. I did this because I often make backups of partitions on external SATA drives and wanted to make sure that somehow the backup would not duplicate whatever Linux considers the UUID of a partition and present a Linux distribution with two UUIDS which are somehow the same and therefore confuse the Linux distribution to the point that I could not use it. I am aware that UUID means a unique id, but I wanted to make sure I understand how that unique id is determined in Linux. This is especially true since the tool I use to make backups of an entire partition is a Windows application, and not a Linux application, and I wanted to make sure that the backup partition UUID would not duplicate that of an existing partition.
In my very brief research in how a UUID is generated under Linux it appears that it is not something that is part of the hardware of the partition itself but rather a number generated by some parameters of the partition, one of which is the partition order.
If it is, it means to me that if I move a partition from one place to another, even on the same hard drive, or to another hard drive, a Linux distribution will no longer find the partition based on the UUID. In that case it seems as if the UUID is subject to the same weakness as the device specification in fstab and menu.lst in that the order of a partition or the placement of a partition on a particular hard drive will cause the designation to no longer refer to the same partition. In which case it appears to me that only the LABEL parameter is not subject to this weakness and as long as I keep distinct labels for all partitions on my hard drive I could theoretically move them around at will and a Linux distribution will find them correctly. I am aware of course that my computer must always find the boot partition to be able to boot a Linux distribution, so moving Linux parttions where I want them is subject to the ability of my computer to find them from the MBR of my hard drives. But in the main it now appears to me that the best way to insure that moving partitions does not keep a Linux distribution from botting correctly is to use LABEL, and not UUID, in fstab and menu.lst, and of course to make sure that if I decide to change the LABEL of a partition that I must change its entry in fstab and possibly menu.lst before rebooting that distribution.
If I have been wrong in my latest surmises I would appreciate being corrected, as the information I found on UUIDs and how they are generated may not be correct. Also if there is more exact information on exactly how partition UUIDs are generated in Linux I would appreciating anyone pointing it out to me.
I'm trying to read content of file to variable and use this variable in for loop. The problem is, when I have c++ comment style in file - /*. Spaces in line are also interpreted as separated lines.
For example:
Code:
Changing $files to "$files" eliminate these problems but causes that whole content of variable is treated as one string (one execution of loop).
my script has a variable which comes in the form +00.00 +0.00 -00.00 or -0.00 (the numbers can be any in that form) for any that have a + symbol I need to remove the +, but if it has a - symbol it needs to stay.
i need to make a new variable with the string from the old variable btut without any plus sign. I have tried a lot of different ways with no success, each thing I tried either left the + or removed the entire string. I think this should work but doesn't
I want to know how to set variable in procmailrc action block or condition block I want to set a variable as a random file name to store emails but I don't know how to set a variable in procmailrc action block or condition block .this is my example:Quote:
Is there any C function that will translate UUIDs into device names? I have a little graphical mount tool that can read user-mountable device names from /etc/fstab and lets you cycle through the list and mount or unmount them. But it doesn't work with UUIDs, which are preferred these days. Is there any way around this?
I am very much new to Linux programming. My question is Is there any way to read UUID of a device or partition in linux programatically. Is there any c/c++ API for user-space applications. I found some commands "sudo vol_id --uuid /dev/sda1", "sudo blkid", "ls -l /dev/disk/by-uuid/". But all are commands which we need to run in terminal. But I need to achieve this from a c/c++ program. (FYI: I need to read uuid of root filesystem ("/") where Linux has been installed.)
I am very much new to Linux programming. My question is Is there any way to read UUID of a device or partition in linux programatically. Is there any c/c++ API for user-space applications. I found some commands "sudo vol_id --uuid /dev/sda1", "sudo blkid", "ls -l /dev/disk/by-uuid/". But all are commands which we need to run in terminal. But i need to achieve this from a c/c++ program. Can some one help me in this problem.(FYI: I need to read uuid of root filesystem ("/") where Linux has been installed.)
I tried to get a block of lines in awk, but unfortunately it returns output of one line only. I don't state the code here, because it's too short and too poor. What exactly I wanted to do: from file "/boot/grub/menu.lst" get blocks of lines, starting by title and ending by Now I have just
I have one password text file: username<tab>password, I want to wrote any bash script to check if certain user exist at this file, if did exist print out the password. I get stocked at password value to AWK if block:
#!/bin/bash FILE="$1" if [ ! -e "$FILE" ] then
[code]....
it not work , but if I change toassword=$(awk < $FILE -F\t '{ if (test $1=="JIMMY2") print $2;}') it works, anything wrong $1==$user_name? $FILE is the password file, -F\t is use tab as delimiter.
I need to replace JAVA_OPTS= with JAVA_OPTS=<some_value>.I need to give "" value at the end of the replacement. I have tried with the following but it is not working: sed -e "s|JAVA_OPTS= |JAVA_OPTS=<some_value>"
how shall I print each variable separately using a generalized form. I tried writing the following within a for loop...Code:echo $(echo a$(echo $i)$(echo $j))which did yield no result. So what shall I write??
Event 1............................................................ full_name: JENNY_JENNINGS genre: f age: 32
[code]....
But as you can see in the input, in the 2nd "Event", the line containing "age" is not present, but in the output my code is printing the 1rst age value twice. The correct output should be blank in the age field for 2nd line in the output like this:
i'm trying to execute a shell script, i'm trying to use the values in an array for use in a sed command:
sed -n '/Sales ID: ${array[$i]}/,/Totals:/p'
that command creates empty files. so my guess is that its not recognizing the array as an array but as text? how would i be able to utilize the array in the command? i got it, didnt think that if i doubled up the single quotes that it would work, but this worked: