Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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.
hey guys, im trying to write a script that gets a .csv file and creates lvm's and mount points , mount the lvm to the mount points and writing into /etc/fstab,
but it seems that the for loop isnt working for me and it prints insted of creating my
variables , can someone give it a look and tell me where are my mistakes?
First, as has been said you need to understand reading from a file and loops.
In your script you use the same line read and process it 3 different times, creating 3 different LVs with each.
Since you read one line, process that one line each time through the loop. The second time through the loop you process the second line, etc.
You also need to understand how LVM names and accesses LVs.
Although it is possible to mount things like you did, the standard way of referencing an LV for mounting is like any other partition.
"mount /dev/mapper/$vgname-$lvname /mount/point"
Why are you creating an lv for what appears to be a simple mount point for the second and 3rd LVs? Will it also contain data or is it a simple mount point?
After the LV is created it needs to be formatted with a file system before mounting.
"mkfs.ext4 /dev/mapper/$vgname-$lvname"
After the first LV is created and mounted, before you create the mount point for the second and subsequent LVs (inside it) you should make certain the first is actually mounted so the rest of the structure creation is done properly
The processes you are performing requires that this script be executed with root (sudo) privledges.
CSV files use "," for separators; not ", " (comma-space)
cut does quite nicely for taking part of a line. No need for multiple cuts or sed on those simple lines.
Your intention was to use backquotes instead of normal quote characters. Hard to see the mistake, since they look so similar. Better use $(cat list.csv). You make the same mistake repeatedly in the loop body.
Next, the for loop doesn't assign entire lines to $i, but words. For this reason, your echo | cut pipelines won't work.
Finally, you create logical volumes, but you don't format them as filesystems. Thus, they can't be mounted.
And I don't understand what the sed commands are for.
$ shellcheck myscript
Line 4:
for i in 'cat list.csv'
^-- SC2034: i appears unused. Verify use (or export if used externally).
^-- SC2041: This is a literal string. To run as a command, use $(..) instead of '..' .
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.