get only a COMMAND column in cygwin for ps command - macos

In Cygwin, I can get the list of running processes by following command:
PID PPID PGID WINPID TTY UID STIME COMMAND
13160 1 13160 13160 ? 197609 13:42:18 /usr/bin/mintty
S 15404 2852 15404 16776 pty2 197609 13:59:29 /usr/bin/vi
2852 12912 2852 11244 pty2 197609 13:42:54 /usr/bin/bash
9864 1 9864 9864 ? 197609 13:11:32 /usr/bin/mintty
S 10500 2852 1692 1452 pty2 197609 14:09:42 /usr/bin/less
S 17644 2852 17644 11880 pty2 197609 14:00:15 /usr/bin/vi
12912 1 12912 12912 ? 197609 13:42:54 /usr/bin/mintty
8432 2852 8432 12020 pty2 197609 14:10:05 /usr/bin/ps
17092 13160 17092 14720 pty1 197609 13:42:18 /usr/bin/bash
However, I just want the COMMAND column but not all columns like this:
COMMAND
/usr/bin/mintty
/usr/bin/vi
/usr/bin/bash
/usr/bin/mintty
/usr/bin/less
/usr/bin/vi
/usr/bin/mintty
/usr/bin/ps
/usr/bin/bash
In MAC, I can do this by the following command:
ps -o command
The same command is not working for cygwin in windows because the -o option is not there in ps for cygwin.

you can use awk to print only the selected column.
$ ps |awk '{ if (NF==8) {print $8} else {print $9}}'
COMMAND
/usr/bin/ps
/usr/bin/bash
/usr/bin/mintty
For more learning:
http://www.grymoire.com/Unix/Awk.html#uh-17

Related

Using sed to print content of files in columns

I have an file , my file name is lookup.txt. Sometimes this file content is 100 lines , so everything scroll while printing. Thats why i like to print it on screen in 2 or more columns.
my bash doesnt support commands like pr or columns.Need to be in old fashion shell.
Content of lookup file is:
1-Top Scores
2-Last Scores
3-Username
4-Birthday
5-Last Meal today
6-Coronavirus in Italy
7-Lets Stay Home
8-Winner
9-Germany and Belgium
10-Alfa
11-Bravo
12-Charlie and delta
For printing in columns i use this command found here on stackoverflow:
cat lookup.txt | xargs printf '%-24s\n' | sed '$p;N;s/\n//;$p;N;s/\n//'
and this is the print in columns:
1-Top Scores 2-Last
Scores 3-Username 4-Birthday
5-Last Meal today
6-Coronavirus in Italy
7-Lets Stay Home
8-Winner 9-Germany and
Belgium 10-Alfa 11-Bravo
12-Charlie and delta
What i need is to let sed not split the words into different columns but just the line.
1-Top Scores 6-Coronavirus in Italy 11-Bravo
2-Last Scores 7-Lets Stay Home 12-Charlie and delta
3-Username 8-Winner
4-Birthday 9-Germany and Belgium
5-Last Meal today 10-Alfa
if the 3 columns are to width then x chars then print in 2 columns (this last is optional)
thanks in advance
Available tools:
/bin:
ash gunzip ping
base64 gzip ping6
bash hostname ps
bash.bash ionice ps.procps
busybox kill pwd
busybox.nosuid kill.procps rm
busybox.suid kmod rmdir
cat ln run-parts
chattr login sed
chgrp login.shadow setserial
chmod ls sh
chown lsattr sleep
cp lsmod stat
cttyhack lsmod.kmod stty
date mkdir su
dd mknod su.shadow
df mktemp sync
dmesg more tar
dnsdomainname mount touch
echo mount.util-linux true
editor mountpoint true.coreutils
egrep mountpoint.sysvinit umount
fake-hwclock mpstat uname
false mv usleep
false.coreutils netstat vi
fatattr nice vi.sh
fgrep pidof watch
getopt pidof.procps watch.procps
grep pidof.sysvinit zcat
/sbin:
arp ifup mkfs.ext4 runlevel.sysvinit
blkid init mkswap setconsole
blkid.util-linux init.sysvinit modinfo shutdown
bootlogd inotifyd modinfo.kmod shutdown.sysvinit
bridge insmod modprobe start-stop-daemon
depmod insmod.kmod modprobe.kmod stb-hwclock
depmod.kmod ip mount.cifs sulogin
devmem ip.iproute2 mount.fuse sulogin.util-linux
e2fsck iwconfig mount.ntfs swapoff
e2label iwgetid mount.ntfs-3g swapon
flock iwlist nologin switch_root
flock.util-linux iwpriv nologin.shadow sysctl
fsck.ext2 iwspy poweroff sysctl.procps
fsck.ext3 killall5 poweroff.sysvinit syslogd
fsck.ext4 klogd reboot telinit
fstab-decode ldconfig reboot.sysvinit tunctl
fstrim loadkmap rmmod tune2fs
getty logread rmmod.kmod udhcpc
halt losetup route uevent
halt.sysvinit lsmod routef vigr
hdparm mdev routel vigr.shadow
ifcfg mke2fs rtmon vipw
ifconfig mkfs.ext2 rtpr vipw.shadow
ifdown mkfs.ext3 runlevel
/usr/bin:
[ realpath
[[ renice
alsamixer reset
ar resize
awk rpcclient
basename rtmpdump
bdpoll scp
bsdcat scsi_logging_level
bunzip2 scsi_mandat
bzcat scsi_readcap
c_rehash scsi_ready
chage scsi_satl
cheetah scsi_start
cheetah-analyze scsi_stop
cheetah-compile scsi_temperature
chfn sdparm
chfn.shadow seq
chrt setsid
chsh sexp-conv
chsh.shadow sg
cifsdd sg_compare_and_write
clear sg_copy_results
cmp sg_dd
crontab sg_decode_sense
curl sg_emc_trespass
cut sg_format
dbclient sg_get_config
dbus-cleanup-sockets sg_get_lba_status
dbus-daemon sg_ident
dbus-launch sg_inq
dbus-monitor sg_logs
dbus-run-session sg_luns
dbus-send sg_map
dbus-update-activation-environment sg_map26
dbus-uuidgen sg_modes
dc sg_opcodes
diff sg_persist
dirname sg_prevent
dlist_test sg_raw
dos2unix sg_rbuf
dotlockfile sg_rdac
du sg_read
easy_install sg_read_attr
easy_install-2.7 sg_read_block_limits
eject sg_read_buffer
enigma2 sg_read_long
enigma2.sh sg_readcap
env sg_reassign
expiry sg_referrals
expr sg_rep_zones
faillog sg_requests
find sg_reset
flip sg_reset_wp
free sg_rmsn
free.procps sg_rtpg
fuser sg_safte
fusermount sg_sanitize
get_device sg_sat_identify
get_driver sg_sat_phy_event
get_module sg_sat_read_gplog
gpasswd sg_sat_set_features
grab sg_scan
groups sg_senddiag
groups.shadow sg_ses
gst-inspect-1.0 sg_ses_microcode
gst-launch-1.0 sg_start
gst-stats-1.0 sg_stpg
gst-typefind-1.0 sg_sync
head sg_test_rwbuf
hotplug_e2_helper sg_timestamp
id sg_turs
killall sg_unmap
last sg_verify
last.sysvinit sg_vpd
lastb sg_wr_mode
lastb.sysvinit sg_write_buffer
lastlog sg_write_long
ldbadd sg_write_same
ldbdel sg_write_verify
ldbedit sg_xcopy
ldbmodify sg_zone
ldbrename sginfo
ldbsearch sgm_dd
less sgp_dd
llmnrd sha1sum
lockfile-check sha256sum
lockfile-create sha3sum
lockfile-remove sha512sum
lockfile-touch shellinaboxd
logger showiframe
logname shuf
lsof skill
lspci skill.procps
lsusb slabtop
mail-lock smbcacls
mail-touchlock smbclient
mail-unlock smbcquotas
md5sum smbget
mesg smbspool
mesg.sysvinit smbtar
mid3cp smbtree
mid3iconv snice
mid3v2 snice.procps
mkfifo sort
moggsplit ssh
mutagen-inspect strings
mutagen-pony systool
nc tail
ndg_httpclient taskset
nettle-hash tee
nettle-lfib-stream telnet
nettle-pbkdf2 test
newgidmap time
newgrp timeout
newgrp.shadow tload
newuidmap toix
nmap toms
nohup top
nslookup top.procps
ntfs-3g tr
ntfs-3g.probe traceroute
ntpdate-sync traceroute6
od truncate
odhcp6c tty
ofgwrite ulockmgr_server
ofgwrite_bin uniq
ofgwrite_test unix2dos
openssl unlink
opkg unxz
opkg-check-config unzip
passwd update-alternatives
passwd.shadow uptime
patch uptime.procps
pgrep users
pgrep.procps utmpdump
pilconvert.py utmpdump.sysvinit
pildriver.py vlock
pilfile.py vmstat
pilfont.py volname
pilprint.py w
pkcs1-conv wall
pkill wall.sysvinit
pkill.procps wc
pmap wget
pmap.procps which
printf who
pwdx whoami
pwdx.procps whois
python wpa_passphrase
python-config xargs
python2 xmlcatalog
python2-config xmllint
python2.7 xzcat
python2.7-config yes
readlink
/usr/sbin:
addgroup grpconv pwck
adduser grpunconv pwconv
alsactl hddtemp pwunconv
automount i2cdetect rdate
avahi-daemon i2cdump rdev
chgpasswd i2cget readprofile
chpasswd i2cset rfkill
chpasswd.shadow ifplugd run-postinsts
chroot inetd setlogcons
crond logoutd sfdisk
delgroup mkfs.ubifs telnetd
deluser mtd_debug ubiattach
dropbear mtdinfo ubiblock
dropbearconvert mtdpart ubicrc32
dropbearkey nanddump ubidetach
dropbearmulti nandtest ubiformat
ether-wake nandwrite ubimkvol
ethtool newusers ubinfo
fbset nl-class-add ubinize
flash_erase nl-class-delete ubirename
flash_eraseall nl-class-list ubirmvol
flash_lock nl-classid-lookup ubirsvol
flash_otp_dump nl-cls-add ubiupdatevol
flash_otp_info nl-cls-delete unix_chkpwd
flash_otp_lock nl-cls-list unix_update
flash_otp_write nl-link-list update-ca-certificates
flash_unlock nl-pktloc-lookup update-rc.d
flashcp nl-qdisc-add useradd
ftpd nl-qdisc-delete userdel
genl-ctrl-list nl-qdisc-list usermod
groupadd ntpd vsftpd
groupdel ntpdate wpa_action
groupmems odhcp6c-update wpa_cli
groupmod parted wpa_supplicant
grpck partprobe
root#xp1000max:~#
Not claiming complete credit, you can modify this andlrc's answer on In bash how can I split a column in several column of fixed dimension to your requirement.
Instead of appending the columns with a whitespace, you can use sprintf() to custom print your column strings. Tested on GNU awk
awk '
BEGIN {
# Numbers of rows to print
n=5;
}
{
# Add to array with key = 0, 1, 2, 3, 4, 0, 1, 2, ..
l[(NR-1)%n] = sprintf("%s%-24s", l[(NR-1)%n], $0)
};
END {
# print the array
for (i = 0; i < length(l); i++) {
print l[i];
}
}
' file
Try this:
cat lookup.txt | tr '\n' '\0' | xargs -0 -n 2 printf '%-24s %-24s\n'
The tr command will convert newlines to nul chars.
Then we tell xargs to take nul-separated args and pass two at a time to the command.

How do i get the Windows PPID of a procces running out of cygwin?

I need to kill a windows procces that were started by the programm called from cygwin.
Here's what I do:
${wccoaDirNix}/bin/WCCILpmon.exe -proj ${projName} -user root: &
This process creates other windows process:
$ ps -W
PID PPID PGID WINPID TTY UID STIME COMMAND
1960 1 1960 1960 ? 197609 19:21:57 /usr/bin/mintty
7316 0 0 7316 ? 0 19:21:57 C:\Windows\System32\conhost.exe
1700 1960 1700 1576 pty1 197609 19:21:57 /usr/bin/bash
I 10760 9840 10760 7560 pty0 197609 19:25:47 /usr/bin/bash
32 10760 10760 32 pty0 197609 19:26:28 /cygdrive/c/Siemens/Automation/WinCC_OA/3.14/bin/WCCILpmon
6264 0 0 6264 ? 0 19:26:28 C:\Siemens\Automation\WinCC_OA\3.14\bin\WCCILpmon.exe
8420 0 0 8420 ? 0 19:26:29 C:\Siemens\Automation\WinCC_OA\3.14\bin\WCCILdata.exe
6336 0 0 6336 ? 0 19:26:29 C:\Windows\System32\conhost.exe
2808 0 0 2808 ? 0 19:26:30 C:\Siemens\Automation\WinCC_OA\3.14\bin\WCCILevent.exe
6784 0 0 6784 ? 0 19:26:30 C:\Windows\System32\conhost.exe
2972 0 0 2972 ? 0 19:26:30 C:\Siemens\Automation\WinCC_OA\3.14\bin\WCCOActrl.exe
11004 0 0 11004 ? 0 19:26:30 C:\Windows\System32\conhost.exe
9536 0 0 9536 ? 0 19:26:31 C:\Siemens\Automation\WinCC_OA\3.14\bin\WCCILsim.exe
7372 0 0 7372 ? 0 19:26:31 C:\Windows\System32\conhost.exe
9128 0 0 9128 ? 0 19:26:31 C:\Siemens\Automation\WinCC_OA\3.14\bin\WCCOAui.exe
3964 0 0 3964 ? 0 19:27:48 C:\Siemens\Automation\WinCC_OA\3.14\bin\WCCILdatabg.exe
How can i kill them?
I tried to kill them by the following command:
ps -W | grep "WCC" | awk '{print $1}' | xargs kill -f;
But it does not work as it should, it kills all processes in which name there are letters WCС, and I need to terminate only the child processes of WCCILpmon.exe
I also read the question on cygwinlist about same problem
And it upset me, is there no way to realize it?
As you need to kill a NOT cygwin process, it is better to use
windows specific program.
One example is:
https://learn.microsoft.com/en-us/sysinternals/downloads/pskill

LINUX error in scripting with shell| awk: syntax error near line 1

i'm trying to build a small script that cut only the file names i want and move them to another mos file.
when the grep is executing i get the error (look down the code)
Last MO: 4592. Loaded 4592 MOs. Total: 4593 MOs.
pls enter RBS number eg LTE8824,: LTE1976
L1976> l cd
New directory: /home/yesumim
L1976> l cd /home/yesumim/LTE_INT/
New directory: /home/yesumim/LTE_INT
L1976> $path = `ls |grep $RbsNumber`
$path = LTE1976_6083
L1976> l echo $path
LTE1976_6083
L1976> l cd $path
New directory: /home/yesumim/LTE_INT/LTE1976_6083
L1976> !ls *BB* |grep -v "xml"|awk '{print "run " $0}'|sort>command.mos
awk: syntax error near line 1
awk: illegal statement near line 1
L1976> run commands.mos
L1976>
L1976>
L1976>
L1976> confb-
L1976> l cat commands.mos
L1976>
if i'll take only this line:
!ls *BB* |grep -v "xml"|awk '{print "run " $0}'|sort>command.mos
and try to execute it i will get the following:
L1976> l cat command.mos
run 01_L1976_TN_SCTP_PTP_L16_for_BB_v1.mos
run 02_L1976_ENodeBFunction_MME_EUtranFrequency_L16_for_BB_v1.mos
run 03_L1976_1_Radio_Config_Optic_2x2_L16_for_BB_v1.mos
run 03_L1976_3_Radio_Config_Optic_2x2_L16_for_BB_v1.mos
run 04_L1976_1_SectorCarrier_EUtranCellFDD_L16_for_BB_v1.mos
run 04_L1976_3_SectorCarrier_EUtranCellFDD_L16_for_BB_v1.mos
run 10_L1976_Feature_Qos_SUP_External_L16_for_BB_v1.mos
L1976>
and this is the whole script code:
confb+
lt all
$RbsNumber = readinput(pls enter RBS number eg LTE8824,: )
l cd
l cd /home/yesumim/LTE_INT/
$path = `ls |grep $RbsNumber`
l echo $path
l cd $path
!ls *BB* |grep -v "xml"|awk '{print "run " $0}'|sort>command.mos
run commands.mos
confb-
can someone tell me why i get this error while i'm scripting and while i'm running the cmd as he is it's OK?

Unable to get "exclude" option working with unarchive module

I have a tar/gzip file I am extracting to a list of hosts using the ansible unarchive module.
The following is a partial list of the contents of configs.tgz:
-rw-rw-r-- ian/ian 1295 2015-09-25 15:27 Makefile
-rw-rw-r-- ian/ian 16 2016-06-21 09:24 .configs
drwxrwxr-x ian/ian 0 2016-02-24 10:18 .bash/
-rw-rw-r-- ian/ian 336 2015-09-25 15:27 .bash/apt.b
-rw-rw-r-- ian/ian 367 2015-09-25 15:27 .bash/gcloud.b
drwxrwxr-x ian/ian 0 2016-06-21 09:22 .vim/
drwxrwxr-x ian/ian 0 2016-06-21 09:22 .vim/plugin/
-rw-rw-r-- ian/ian 3327 2016-06-21 09:17 .vim/plugin/scratch.vim
drwxrwxr-x ian/ian 0 2015-09-25 15:27 .vim/ftplugin/
-rw-rw-r-- ian/ian 521 2015-09-25 15:27 .vim/ftplugin/dokuwiki.vim
-rw-rw-r-- ian/ian 2456 2015-09-25 15:27 .vim/ftplugin/nagios.vim
drwxrwxr-x ian/ian 0 2015-09-25 15:27 .vim/ftdetect/
-rw-rw-r-- ian/ian 149 2015-09-25 15:27 .vim/ftdetect/nagios.vim
-rw-rw-r-- ian/ian 111 2015-09-25 15:27 .vim/ftdetect/zsh-profile.vim
-rw-rw-r-- ian/ian 554 2015-09-25 15:27 .zshrc
drwxrwxr-x ian/ian 0 2015-09-25 15:27 .mutt/
lrwxrwxrwx ian/ian 0 2015-09-25 15:27 .mutt/profile.active -> profile.gmail
-rw-rw-r-- ian/ian 863 2015-09-25 15:27 .mutt/everyone.lst
-rw-rw-r-- ian/ian 310 2015-09-25 15:27 .mutt/vimrc4mail
-rw-rw-r-- ian/ian 11559 2015-09-25 15:27 .mutt/muttrc
-rw-rw-r-- ian/ian 441 2015-09-25 15:27 .screenrc
-rw-rw-r-- ian/ian 131 2015-09-25 15:27 .tmux.conf
-rwxrwxr-x ian/ian 1439 2015-09-25 15:27 xmake
I'd like to extract everything except the .mutt directory, but I can't seem to get the exclude option to work correctly.
Here is what I am getting:
% ansible --version
ansible 2.1.0.0
config file = /home/ian/Playbooks/ansible.cfg
configured module search path = Default w/o overrides
% rm -rf /tmp/a; mkdir /tmp/a && ansible localhost -m unarchive -a "src=configs/configs.tgz dest=/tmp/a/ exclude='.mutt'" -vvv
Using /home/ian/Playbooks/ansible.cfg as config file
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: ian
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1466558533.54-272347310038797 `" && echo ansible-tmp-1466558533.54-272347310038797="` echo $HOME/.ansible/tmp/ansible-tmp-1466558533.54-272347310038797 `" ) && sleep 0'
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1466558533.64-181689590644032 `" && echo ansible-tmp-1466558533.64-181689590644032="` echo $HOME/.ansible/tmp/ansible-tmp-1466558533.64-181689590644032 `" ) && sleep 0'
<localhost> PUT /tmp/tmp9TwX54 TO /home/ian/.ansible/tmp/ansible-tmp-1466558533.64-181689590644032/stat
<localhost> EXEC /bin/sh -c 'LANG=C LC_ALL=C LC_MESSAGES=C /usr/bin/python /home/ian/.ansible/tmp/ansible-tmp-1466558533.64-181689590644032/stat; rm -rf "/home/ian/.ansible/tmp/ansible-tmp-1466558533.64-181689590644032/" > /dev/null 2>&1 && sleep 0'
<localhost> PUT configs/configs.tgz TO /home/ian/.ansible/tmp/ansible-tmp-1466558533.54-272347310038797/source
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1466558533.94-189956548033565 `" && echo ansible-tmp-1466558533.94-189956548033565="` echo $HOME/.ansible/tmp/ansible-tmp-1466558533.94-189956548033565 `" ) && sleep 0'
<localhost> PUT /tmp/tmp2xgO6E TO /home/ian/.ansible/tmp/ansible-tmp-1466558533.94-189956548033565/unarchive
<localhost> EXEC /bin/sh -c 'LANG=C LC_ALL=C LC_MESSAGES=C /usr/bin/python /home/ian/.ansible/tmp/ansible-tmp-1466558533.94-189956548033565/unarchive; rm -rf "/home/ian/.ansible/tmp/ansible-tmp-1466558533.94-189956548033565/" > /dev/null 2>&1 && sleep 0'
<localhost> EXEC /bin/sh -c 'rm -f -r /home/ian/.ansible/tmp/ansible-tmp-1466558533.54-272347310038797/ > /dev/null 2>&1 && sleep 0'
localhost | FAILED! => {
"changed": false,
"failed": true,
"invocation": {
"module_args": {
"backup": null,
"content": null,
"copy": true,
"creates": null,
"delimiter": null,
"dest": "/tmp/a/",
"directory_mode": null,
"exclude": [
".mutt"
],
"extra_opts": [],
"follow": false,
"force": null,
"group": null,
"keep_newer": false,
"list_files": false,
"mode": null,
"original_basename": "configs.tgz",
"owner": null,
"regexp": null,
"remote_src": null,
"selevel": null,
"serole": null,
"setype": null,
"seuser": null,
"src": "/home/ian/.ansible/tmp/ansible-tmp-1466558533.54-272347310038797/source"
}
},
"msg": "path /tmp/a/.mutt/profile.active does not exist",
"path": "/tmp/a/.mutt/profile.active",
"state": "absent"
}
I've tried various iterations of the "exclude" option, including
exclude='[ ".mutt" ]'
exclude='[ ".mutt", ".mutt/*" ]'
These appear to work, but I always end up with the entire contents of the .mutt directory being extracted.
Where am I going wrong?
Per the comments, there is a bug logged for this issue.
The work-around is to use a YAML list for the exclusions and to make sure the list exactly matches the path/file stored in the archive.
vars:
exclusions:
- ./.mutt
and
unarchive: src=configs/configs.tgz dest=/tmp/a exclude={{ exclusions }}

BASH/shell script, blkid fails with newlines in drive labels

I have a BASH/shell script, running on Linux, but it sometimes has a problem getting the drive labels, using blkid.. blkid gets the drive labels nad UUIDs of the given drive.
Example of blkid output:
# blkid /dev/sda1
/dev/sda1: LABEL="Home" UUID="f1e5e82b-1c75-4fd7-8841-6ad766152dcf" TYPE="ext2"
The problem occurs when the drive label has a newline character... I have included the relevant function. The problem seems to be with the eval command.. Can someone help me?
blkid_name_generator() {
#Gather blkid output and filter out required device
if [ ! -f /tmp/blkid.txt ]; then
blkid -c /dev/null > /tmp/blkid.txt
fi
blkid_cleaner &
LABEL=""
LABEL1=""
eval $( cat /tmp/blkid.txt | grep "$#:" | cut --delimiter=" " -f 2- | sed -e 's/ /;/g')
LABEL1=${LABEL//;/ } # akita beta4 fix: remove newlines below
LABEL=`echo $LABEL1 | tr -d '\n'` # akita beta5 fix, remove newlines from drive label
#Generate drive label
[ "$LABEL" = "" ] && ONEDRVLABEL="$#\n \n " || ONEDRVLABEL="${LABEL}\n($#)\n "
echo "${LABEL}" and "${ONEDRVLABEL}"
}
blkid_name_generator /dev/sda1
Here's my bash snippet:
while read curline; do
if [[ ${curline:0:1} == "/" ]]; then
[[ $prevline ]] && echo "$prevline"
prevline="$curline"
else
prevline+="$curline"
fi
done < $INPUTFILE
[[ $prevline ]] && echo "$prevline"
Here's my test file:
/dev/sda1: LABEL="Boot" UUID="fdc5e51d-3da6-4edf-bf07-6397b1765797" TYPE="ext2"
/dev/sda2: LABEL="Root" UUID="f883df24-1b93-46fb-8990-840774c380c4" TYPE="ext4"
/dev/sda3: LABEL="Usr" UUID="ba759de3-e0e4-4603-a324-f11dc25fa784" TYPE="reiserfs"
/dev/sdb1: LABEL="Persis
tents" UUID="50b81ef0-a38b-4677-b9d9-9548b29ce2bb" TYPE="ext4"
/dev/sdc1: LABEL="Tempo
raries" UUID="a649c535-1a8a-4b2b-b0a0-4afbdc60a3bc" TYPE="reiserfs"
/dev/sdd1: LABEL="Usr
Portage" UUID="a228148e-6405-4bbe-990f-df6eaebb1b1d" TYPE="reiserfs"
/dev/sda1: LABEL="Boot" UUID="fdc5e51d-3da6-4edf-bf07-6397b1765797" TYPE="ext2"
/dev/sda2: LABEL="Root" UUID="f883df24-1b93-46fb-8990-840774c380c4" TYPE="ext4"
Here's my test file after processed by the bash snippet:
/dev/sda1: LABEL="Boot" UUID="fdc5e51d-3da6-4edf-bf07-6397b1765797" TYPE="ext2"
/dev/sda2: LABEL="Root" UUID="f883df24-1b93-46fb-8990-840774c380c4" TYPE="ext4"
/dev/sda3: LABEL="Usr" UUID="ba759de3-e0e4-4603-a324-f11dc25fa784" TYPE="reiserfs"
/dev/sdb1: LABEL="Persistents" UUID="50b81ef0-a38b-4677-b9d9-9548b29ce2bb" TYPE="ext4"
/dev/sdc1: LABEL="Temporaries" UUID="a649c535-1a8a-4b2b-b0a0-4afbdc60a3bc" TYPE="reiserfs"
/dev/sdd1: LABEL="UsrPortage" UUID="a228148e-6405-4bbe-990f-df6eaebb1b1d" TYPE="reiserfs"
/dev/sda1: LABEL="Boot" UUID="fdc5e51d-3da6-4edf-bf07-6397b1765797" TYPE="ext2"
/dev/sda2: LABEL="Root" UUID="f883df24-1b93-46fb-8990-840774c380c4" TYPE="ext4"
Hope this helps!
I don't see exactly what your script is intending to do (apart from the missing bits).
Here's what I came up with:
blkid | perl -ne 'print "$1\n" if m/LABEL="(.*?)"/o'
It will show this (on my system):
test^J123
WIN7VIRT
TEMP
Note how the newline in the label is depicted as ^J ? Viewing through a hex encoder shows that it is indeed a two-character combination 0x5e 0x4a
Hope you can get some further with that.
PS: 'proof' that the newline is in fact correctly in the volume label
tune2fs /dev/sdc1 -l
tune2fs 1.41.14 (22-Dec-2010)
Filesystem volume name: test
123
Last mounted on: /media/9868d90c-aede-4e7a-b105-d9312f8b17ab
Filesystem UUID: 9868d90c-aede-4e7a-b105-d9312f8b17ab
Filesystem magic number: 0xEF53
Filesystem revision #: 1 (dynamic)
...
and on block level:
dd if=/dev/sdc1 count=10 | xxd | grep 123
0000470: b105 d931 2f8b 17ab 7465 7374 0a31 3233 ...1/...test.123
Thanks to this question... I could find a solution for another problem. Example (sda2 = ntfs partition):
blkid /dev/sda2
Segmentation Fault (core dump)
Hard to find troubleshooting guide for this issue (ubuntu based OS or any other)
The reason behind is a malformed LABEL in NTFS partition.
(of course, mal-formation we cant see, as newlines ;-)
Solution: Clear LABEL with GParted; then rewrite it or set a new LABEL.

Resources