Sunday, May 5, 2024
 Popular · Latest · Hot · Upcoming
6
rated 0 times [  6] [ 0]  / answers: 1 / hits: 8139  / 2 Years ago, sun, july 31, 2022, 7:27:26

I'm working on my bash script to create logical volumes. I have this command which I want to put in a if to check of each of these succeed. What is the easiest way to do that?



 #!/bin/bash
pvcreate /dev/md5

vgcreate vg0 /dev/md5

lvcreate -L 200MB vg0 -n test

More From » bash

 Answers
0
#!/bin/bash

pvcreate /dev/md5 && echo "pvcreate succeeded" || echo "pvcreate failed"

vgcreate vg0 /dev/md5 && echo "vgcreate succeeded" || echo "vgcreate failed"

lvcreate -L 200MB vg0 -n test && echo "lvcreate succeeded" || echo "lvcreate failed"


Logical AND && part will be executed only if the command succeeded(true) else Logical OR || (false) part will be executed.


[#26957] Tuesday, August 2, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
fulerio

Total Points: 172
Total Questions: 124
Total Answers: 109

Location: Hungary
Member since Thu, Aug 6, 2020
4 Years ago
fulerio questions
;