Error while running xterm in telnet script - bash

This is error while running the telnet script.
Language: Shell script
Error:
Type xterm -help for a full description.
xterm: Explicit shell already was /root/Desktop/stage2/./close_telnet.sh
xterm: bad command line option "192.168.0.1 25"
usage: xterm [-/+132] [-C] [-Sccn] [-T string] [-/+ah] [-/+ai] [-/+aw]
[-b number] [-/+bc] [-bcf milliseconds] [-bcn milliseconds] [-bd color]
[-/+bdc] [-bg color] [-bw number] [-/+cb] [-cc classrange] [-/+cjk_width]
[-class string] [-/+cm] [-/+cn] [-cr color] [-/+cu] [-/+dc]
[-display displayname] [-e command args ...] [-fa pattern] [-fb fontname]
[-/+fbb] [-/+fbx] [-fd pattern] [-fg color] [-fi fontname] [-fn fontname]
[-fs size] [-/+fullscreen] [-fw fontname] [-fwb fontname] [-fx fontname]
[%geom] [#geom] [-geometry geom] [-help] [-/+hm] [-/+hold] [-iconic]
[-/+ie] [-/+im] [-into windowId] [-/+j] [-/+k8] [-kt keyboardtype] [-/+l]
[-/+lc] [-lcc path] [-leftbar] [-lf filename] [-/+ls] [-/+maximized]
[-/+mb] [-mc milliseconds] [-/+mesg] [-/+mk_width] [-ms color] [-n string]
[-name string] [-nb number] [-/+nul] [-/+pc] [-/+pob] [-report-colors]
[-report-fonts] [-rightbar] [-/+rv] [-/+rvc] [-/+rw] [-/+s] [-/+samename]
[-/+sb] [-selbg color] [-selfg color] [-/+sf] [-sh number] [-/+si] [-/+sk]
[-sl number] [-/+sm] [-/+sp] [-/+t] [-ti termid] [-title string]
[-tm string] [-tn name] [-/+u8] [-/+uc] [-/+ulc] [-/+ulit] [-/+ut] [-/+vb]
[-version] [-/+wc] [-/+wf] [-xrm resourcestring] [-ziconbeep percent]
Type xterm -help for a full desc
Please suggest any idea to solve this error.

The likely problem is that $window_id is an empty value. That would produce the error message from xterm.
In a quick check, I have the output from wmctrl -lp as
$ wmctrl -lp
0x00400023 0 1036 localhost.localdomain [!./bar] - vile
0x00a0000a 0 3981 localhost.localdomain xclock xclock
but the output of the expression with xprop is 0x0400023 (a different number of leading zeros).
If I change the fragment
awk '{print $5}' | sed 's/,//' | sed 's/^0x/0x0/'
to
awk '{sub(",","",$5);printf("%#010x",$5);}'
it gives a usable result (for my machine: ymmv).

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.

Issue in ansible playbook command?

I am trying to execute a command on docker on other machine from my machine. When I execute this command:
- name: Add header
command: docker exec cli bash -l -c "echo '{"payload":{"header":{"channel_header":{"channel_id":"gll", "type":2}},"data":{"config_update":'$(cat jaguar_update.json)'}}}' | jq . > jaguar_update_in_envelope.json"
through ansible playbook, I am getting the error shown below.
fatal:[
command-task
]:FAILED! =>{
"changed":true,
"cmd":[ ],
"delta":"0:00:00.131115",
"end":"2019-07-11 17:32:44.651504",
"msg":"non-zero return code",
"rc":4,
"start":"2019-07-11 17:32:44.520389",
"stderr":"mesg: ttyname
failed: Inappropriate ioctl for device\nparse error: Invalid numeric
literal at line 1, column 9",
"stderr_lines":[
"mesg: ttyname failed:
Inappropriate ioctl for device",
"parse error: Invalid numeric literal
at line 1, column 9"
],
"stdout":"",
"stdout_lines":[
]
}
But if I manually execute command in the docker container, it works fine and I don't get any issue.
EDIT:
As suggested i tried with shell module
shell: docker exec cli -it bash -l -c "echo '{"payload":{"header":{"channel_header":{"channel_id":"gll", "type":2}},"data":{"config_update":'$(cat jaguar_update.json)'}}}' | jq . > jaguar_update_in_envelope.json"
But i get below error as
fatal: [command-task]: FAILED! => {"changed": true, "cmd": "docker
exec cli -it bash -l -c echo
'{\"payload\":{\"header\":{\"channel_header\":{\"channel_id\":\"gll\",
\"type\":2}},\"data\":{\"config_update\":'$(cat
jaguar_update.json)'}}}' | jq . > jaguar_update_in_envelope.json",
"delta": "0:00:00.110341", "end": "2019-07-12 10:21:45.204049", "msg":
"non-zero return code", "rc": 4, "start": "2019-07-12
10:21:45.093708", "stderr": "cat: jaguar_update.json: No such file or
directory\nparse error: Invalid numeric literal at line 1, column 4",
"stderr_lines": ["cat: jaguar_update.json: No such file or directory",
"parse error: Invalid numeric literal at line 1, column 4"], "stdout":
"", "stdout_lines": []}
All the files 'jaguar_update.json' present in the working directory. I have confirmed the working directory.
Above commands works if i put it in a shell script file then execute the shell script from ansible.
As everyone has mentioned this does need you to use shell instead of command. Now you want to simplify this command so it can run first in bash. Which can be done easily using printf
$ printf "%s%s%s" '{"payload":{"header":{"channel_header":{"channel_id":"gll", "type":2}},"data":{"config_update":' $(<jaguar_update.json'}}}' | jq . > jaguar_update_in_envelope.json
$ cat jaguar_update_in_envelope.json
{
"payload": {
"header": {
"channel_header": {
"channel_id": "gll",
"type": 2
}
},
"data": {
"config_update": {
"name": "tarun"
}
}
}
}
So now our commands runs without issues. Next is to move it with bash -l -c format. So instead using -c which requires us to pass the whole command as one parameter, we use the multiline commands
$ bash -l <<EOF
printf "%s%s%s" '{"payload":{"header":{"channel_header":{"channel_id":"gll", "type":2}},"data":{"config_update":' $(<jaguar_update.json) '}}}' | jq . > jaguar_update_in_envelope.json
EOF
But this fails with an error
{"payload":{"header":{"channel_header":{"channel_id":"gll", "type":2}},"data":{"config_update":{bash: line 2: name:: command not found
bash: line 3: syntax error near unexpected token `}'
bash: line 3: `} '}}}' | jq . > jaguar_update_in_envelope.json'
This is because the EOF format will treat each new line as a different command. So we need to replace all new line characters
bash -l <<EOF
printf "%s%s%s" '{"payload":{"header":{"channel_header":{"channel_id":"gll", "type":2}},"data":{"config_update":' $(sed -E 's|"|\\"|g' jaguar_update.json | tr -d '\n') '}}}' | jq . > jaguar_update_in_envelope.json
EOF
And now in ansible
- name: a play that runs entirely on the ansible host
hosts: 127.0.0.1
connection: local
tasks:
- name: Solve the problem
shell: |
bash -l <<EOF
printf "%s%s%s" '{"payload":{"header":{"channel_header":{"channel_id":"gll", "type":2}},"data":{"config_update":' $(sed -E 's|"|\\"|g' jaguar_update.json | tr -d '\n') '}}}' | jq . > jaguar_update_in_envelope.json
EOF
And the result
$ ansible-playbook test.yml
PLAY [a play that runs entirely on the ansible host] *********************************************************************************************************************************
TASK [Gathering Facts] ***************************************************************************************************************************************************************
ok: [127.0.0.1]
TASK [Solve the problem] *************************************************************************************************************************************************************
changed: [127.0.0.1]
PLAY RECAP ***************************************************************************************************************************************************************************
127.0.0.1 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
$ cat jaguar_update_in_envelope.json
{
"payload": {
"header": {
"channel_header": {
"channel_id": "gll",
"type": 2
}
},
"data": {
"config_update": {
"name": "tarun"
}
}
}
}
To avoid any complexity, try as in this question to wrap your command in a script, and call that script (with command or shell)
- name: Add header
raw: /path/to/script/docker-add-header.sh
And in /path/to/script/docker-add-header.sh:
docker exec cli -it bash -l -c "echo '{"payload":{"header":{"channel_header":{"channel_id":"gll", "type":2}},"data":{"config_update":'$(cat jaguar_update.json)'}}}' | jq . > jaguar_update_in_envelope.json
Try to make the script work first alone (no Ansible).
See (if it is not working, even outside any Ansible call), to escape nested double-quotes:
docker exec cli -it bash -l -c "echo '{\"payload\":{\"header\":...
c.f. the docs -
The command(s) will not be processed through the shell, so variables like $HOME and operations like "<", ">", "|", ";" and "&" will not work. Use the shell module if you need these features.
shell pretty literally submits a script to the sh command parser.
Another note - you end the single-quote before the $(cat jaguar_update.json) and restart it after, but don't use any double quoting around it. Your output may handle that, but I wanted to call attention in case it matters.

calling command with some arguments works but not with others but works from console

The following code works and outputs details of 10 processes.
package main
import (
"os/exec"
)
func main() {
print(top())
}
func top() string {
app := "/usr/bin/top"
cmd := exec.Command(app, "-n 10", "-l 2")
out, err := cmd.CombinedOutput()
if err != nil {
return err.Error() + " " + string(out)
}
value := string(out)
return value
}
However, when I try the same with an additional argument of "-o cpu" (e.g. cmd := exec.Command(app, "-o cpu", "-n 10", "-l 2")). I get the following error.
exit status 1 invalid argument -o: cpu
/usr/bin/top usage: /usr/bin/top
[-a | -d | -e | -c <mode>]
[-F | -f]
[-h]
[-i <interval>]
[-l <samples>]
[-ncols <columns>]
[-o <key>] [-O <secondaryKey>]
[-R | -r]
[-S]
[-s <delay>]
[-n <nprocs>]
[-stats <key(s)>]
[-pid <processid>]
[-user <username>]
[-U <username>]
[-u]
But the command "top -o cpu -n 10 -l 2" from my console works fine. Also I'm using OS X 10.9.3.
Separate your arguments.
top -o cpu -n 10 -l 2 is not what you are executing. What you're passing as arguments to the command is equivalent to using top "-o cpu" "-n 10" "-l 2" in a shell (which if you try, it will give you the exact same output).
Most commands will strictly parse that as 3 arguments. Since POSIX arguments don't require a space, top splits off the -o as the first option, and uses the rest as its argument. This works for the numerical arguments mostly by accident, but the for -o it looks for a field named " cpu", which there isn't.
Instead, use
exec.Command(app, "-o", "cpu", "-n", "10", "-l", "2")

Can't run tmux in OS X Mavericks

Trying to run tmux on OS X Mavericks.
Here is my ~/.tmux.conf
# Keybindings
unbind c
unbind C-b
unbind C-a
unbind %
unbind ,
unbind .
unbind n
unbind p
unbind '"'
unbind l
unbind &
unbind "'"
# set-option -g prefix C-a # C-a for perfix just like screen
set -g prefix `
bind-key ` send-prefix
bind-key n new-window
bind-key C-a last-window
bind-key | split-window -h
bind-key \ split-window -h
bind-key - split-window -v
bind-key x kill-pane
bind-key X kill-window
# bind-key q confirm-before kill-session
bind-key q confirm-before kill-server
bind-key , previous-window # <
bind-key . next-window # >
bind-key < swap-window -t :-
bind-key > swap-window -t :+
# bind-key Escape copy-mode -u
# bind-key Up copy-mode -u
bind-key r source-file ~/.tmux.conf\; display-message " ✱ ~/.tmux.conf was reloaded"
bind-key R refresh-client
# bind-key a send-key C-a
# set status bar
set-option -g status-utf8 on
set-option -g status-bg colour232
set-option -g status-fg colour235
# set-option -g status-left '⣿'
# set-option -g status-right '⡇ #[bold]❐ #S:#I#[default] ⡇ #[bold]#(whoami) ● #H#[default] '
# set-option -g status-right '⡇ ❐ #S ⡇ ❖ #(rvm tools identifier) ⡇ #(whoami) ● #H '
set-option -g status-left '⣿'
set-option -g status-right '#(whoami) ● #H#[default] '
set-option -g status-right-length 60
set-option -g status-left-length 60
# highlight active window
set-window-option -g window-status-current-bg colour10
set-window-option -g window-status-current-fg colour234
I get the following error when I execute tmux:
/Users/levelone/.tmux.conf:2: unknown key: c [0/0]
/Users/levelone/.tmux.conf:3: unknown key: C-b
/Users/levelone/.tmux.conf:4: unknown key: C-a
/Users/levelone/.tmux.conf:5: unknown key: %
/Users/levelone/.tmux.conf:6: unknown key: ,
/Users/levelone/.tmux.conf:7: unknown key: .
/Users/levelone/.tmux.conf:8: unknown key: n
/Users/levelone/.tmux.conf:9: unknown key: p
/Users/levelone/.tmux.conf:10: unknown key: "
/Users/levelone/.tmux.conf:11: unknown key: l
/Users/levelone/.tmux.conf:12: unknown key: &
/Users/levelone/.tmux.conf:13: unknown key: '
/Users/levelone/.tmux.conf:16: bad key: `
/Users/levelone/.tmux.conf:17: unknown command: send-prefix
/Users/levelone/.tmux.conf:19: unknown command: new-window
/Users/levelone/.tmux.conf:20: unknown command: last-window
/Users/levelone/.tmux.conf:21: usage: split-window [-dhvP] [-c start-directory] [-F format] [-p percentage|-l size] [-t target-pane] [command]
/Users/levelone/.tmux.conf:22: usage: split-window [-dhvP] [-c start-directory] [-F format] [-p percentage|-l size] [-t target-pane] [command]
/Users/levelone/.tmux.conf:23: usage: split-window [-dhvP] [-c start-directory] [-F format] [-p percentage|-l size] [-t target-pane] [command]
/Users/levelone/.tmux.conf:24: unknown command: kill-pane
/Users/levelone/.tmux.conf:25: unknown command: kill-window
/Users/levelone/.tmux.conf:35: unknown command: refresh-client
/Users/levelone/.tmux.conf:39: bad value: on
/Users/levelone/.tmux.conf:40: bad colour: colour232
/Users/levelone/.tmux.conf:41: bad colour: colour235
/Users/levelone/.tmux.conf:49: value is invalid: 60
/Users/levelone/.tmux.conf:50: value is invalid: 60
/Users/levelone/.tmux.conf:53: bad colour: colour10
/Users/levelone/.tmux.conf:54: bad colour: colour234
/Users/levelone/.tmux.conf:56: bad attributes: dim
/Users/levelone/.tmux.conf:60: bad value: off
/Users/levelone/.tmux.conf:61: bad value: on
/Users/levelone/.tmux.conf:62: bad value: on
/Users/levelone/.tmux.conf:65: bad value: on
/Users/levelone/.tmux.conf:67: bad value: off
/Users/levelone/.tmux.conf:69: bad attributes: normal
/Users/levelone/.tmux.conf:75: bad value: on
/Users/levelone/.tmux.conf:76: unknown value: vi
/Users/levelone/.tmux.conf:77: unknown value: on
/Users/levelone/.tmux.conf:84: bad colour: yellow
/Users/levelone/.tmux.conf:85: bad colour: white
/Users/levelone/.tmux.conf:88: value is invalid: 2000
/Users/levelone/.tmux.conf:92: unknown value: vi
/Users/levelone/.tmux.conf:93: usage: select-pane [-lDLRU] [-t target-pane]
/Users/levelone/.tmux.conf:94: usage: select-pane [-lDLRU] [-t target-pane]
/Users/levelone/.tmux.conf:95: usage: select-pane [-lDLRU] [-t target-pane]
/Users/levelone/.tmux.conf:96: usage: select-pane [-lDLRU] [-t target-pane]
/Users/levelone/.tmux.conf:102: unknown command: copy-mode
/Users/levelone/.tmux.conf:103: unknown command: paste-buffer
/Users/levelone/.tmux.conf:107: unknown command: begin-selection
/Users/levelone/.tmux.conf:119: value is invalid: 1
I suspect that your file has CR+LF line endings; tmux expects normal Unix-style LF-only line endings.
perl -pi -e 's/\r$//' ~/.tmux.conf
You may also use dosu2unix (available through MacPorts)

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