Issue
Objective: to get last mount point in bash shell script
Code:
#!/bin/bash
export mt_pt=`lsblk |grep part|tail -1`
awk '{print (($7))}' | $mt_pt
Expected:
/run/media/ava/KINGSTON
Actual:
./time.sh: line 12: └─sdb1: command not found
lsblk output:
[ava@srvr0 ~]$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 298.1G 0 disk
├─sda1 8:1 0 2G 0 part /boot
├─sda2 8:2 0 32G 0 part /
├─sda3 8:3 0 32G 0 part /data
├─sda4 8:4 0 1K 0 part
├─sda5 8:5 0 32G 0 part /home
├─sda6 8:6 0 32G 0 part /log
├─sda7 8:7 0 32G 0 part /opt
├─sda8 8:8 0 32G 0 part /tmp
├─sda9 8:9 0 32G 0 part /usr
├─sda10 8:10 0 32G 0 part /var
├─sda11 8:11 0 16G 0 part [SWAP]
└─sda12 8:12 0 24.1G 0 part /index
sdb 8:16 1 28.9G 0 disk
└─sdb1 8:17 1 28.9G 0 part /run/media/ava/KINGSTON
sr0 11:0 1 1024M 0 rom
Please guide me in getting last mount point.
Solution
You could save the 7th field in a variable for each line where the 6th field equals part
and print the saved value in the END
block.
lsblk | awk '$6=="part"{ p=$7 } END{ print p }'
Answered By - Freddy Answer Checked By - Marie Seifert (WPSolving Admin)