You are not logged in.

#1 2014-11-13 07:29:10

cyberpsych0sis
Member
Registered: 2014-11-02
Posts: 47

Bash Scripting - Opening and Closing LVM on LUKS

I've been working a bash script to automate the process of opening and closing an LVM over LUKS external hard drive. However I continue to receive errors on line 28:

$(vgchange -a n ; cryptsetup luksClose vol)

The error I receive:

$ sudo ./encryption.sh -l
Locking System..............
./encryption.sh: line 28: 0: command not found
System Locked!

Here is the rest of the code for reference:

 
if [ $1 = -u ] ; then
    $(cryptsetup luksOpen /dev/sdb2 vol)
    echo "Unlocking.................." | pv -qL 10
    $(mount /dev/mapper/vol-lvroot /mnt ; mount /dev/mapper/vol-lvvar /mnt/var ; mount /dev/mapper/vol-lvhome /mnt/home ; mount /dev/sdb1 /mnt/boot)
    echo "System Mounted!" | pv -qL 10
#   exit 0
fi

if [ $1 = -l ] ; then
    $(umount /mnt/var ; umount /mnt/home ; umount /mnt/boot ; umount /mnt/)
    echo "Locking System.............." | pv -qL 10
    $(vgchange -a n ; cryptsetup luksClose vol)
    echo "System Locked!" | pv -qL 10
    exit 0
fi

Other information:

1. I receive no apparent error when running the command in question by itself interactively. However running the troubled code interactively does provide this output:

0 logical volume(s) in volume group "vol" now active

2. I'm new to writing bash, so any recommendations and constructive criticism is appreciated.

3. The process appears to complete successfully, but I don't understand the error or how to make them go away.

Offline

#2 2014-11-13 13:59:01

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: Bash Scripting - Opening and Closing LVM on LUKS

Your problems are self-inflicted from wrapping commands arbitrarily in $(). Don't do that.

http://mywiki.wooledge.org/CommandSubstitution

Last edited by falconindy (2014-11-13 14:11:04)

Offline

#3 2014-11-13 18:03:44

cyberpsych0sis
Member
Registered: 2014-11-02
Posts: 47

Re: Bash Scripting - Opening and Closing LVM on LUKS

falconindy wrote:

Your problems are self-inflicted from wrapping commands arbitrarily in $(). Don't do that.

http://mywiki.wooledge.org/CommandSubstitution

Thanks

Offline

Board footer

Powered by FluxBB