I wanted to play around with virtual filesystems and I also was working on huge tar files at that time. Untaring some file just to copy out all of it content (more tar files) and then cleaning up was a bit PITA, so I decided to see if I can write a virtual filesystem that will show the insides of the tar file without wasting space.
I decided to do this using FUSE and I only cared about extracting data so the filesystem is read-only.
The script is here. It is using the llfuse python module.
It was a very nice way to understand a bit better how filesystems in *NIX environments work.
Usage for the script is straight forward:
$ ./fuse_tar.py -h
usage: fuse_tar.py [-h] [--mountpoint MOUNTPOINT] [--debug] [--debug-fuse]
tarfile
positional arguments:
tarfile tarfile to mount
optional arguments:
-h, --help show this help message and exit
--mountpoint MOUNTPOINT
Where to mount the file system
--debug Enable debugging output
--debug-fuse Enable FUSE debugging output
By default it can handle tar, tgz, tar.bz2 and tar.xz. Obviously access times will differ between the different formats. If the mount point is not specified it tries to create a folder in a current working directory with the name of file but without the suffix.
chrooted brain
simple tmux helper script to work simultaneously on many ssh sessions
I recently found a nice way to work on multiple servers using tmux and OpenSSH (not only, but who uses something else?).
The script looks like this:
#!/bin/sh
if [ $# -gt 0 ]; then
OK="0"
for host in $(egrep '^host' ~/.ssh/config | grep -v '\*' | pcregrep -o "\s+$1\S*?(\s|$)")
do
OK="1"
STYLE=$(pcregrep -A1 "\s$host(\s|$)" ~/.ssh/config | grep -o 'tmux-style: .*' | cut -d' ' -f2-)
tmux send-keys "ssh $host $2" \; select-pane -P "$STYLE" \; split-window \; select-layout tiled
done
if [ $OK = "1" ]; then
tmux set-window-option synchronize-panes \; send-keys ENTER
tmux kill-pane \; select-layout tiled
fi
fi
The script reads your ~/.ssh/config file and based on host entries it creates panes in a single tmux window and synchronises inputs to them. This allows for a simultaneous work done on multiple machines.
It also supports for setting styles for different hosts in your ~/.ssh/config file.
Usage:
Assuming you have a ~/.ssh/config file that looks like this:
host abc-*
User root
host abc-prod
# tmux-style: bg=red
Hostname 192.168.0.1
host abc-dr
# tmux-style: bg=blue
Hostname 192.168.0.2
host def-vm-*
User admin
host def-vm-1
Hostname 192.168.0.11
host def-vm-2
Hostname 192.168.0.12
host def-vm-3
Hostname 192.168.0.13
host def-vm-4
Hostname 192.168.0.14
host def-vm-5
Hostname 192.168.0.15
And also assuming that you saved the script in ~/bin/st then running this command:
$ st abc
will spawn to synchronised panes in your current window one with red and one with blue background
if you run:
$ st def-vm
or
$ st def-
it will spawn five panes to each one of the def-vm machines.
The script looks like this:
#!/bin/sh
if [ $# -gt 0 ]; then
OK="0"
for host in $(egrep '^host' ~/.ssh/config | grep -v '\*' | pcregrep -o "\s+$1\S*?(\s|$)")
do
OK="1"
STYLE=$(pcregrep -A1 "\s$host(\s|$)" ~/.ssh/config | grep -o 'tmux-style: .*' | cut -d' ' -f2-)
tmux send-keys "ssh $host $2" \; select-pane -P "$STYLE" \; split-window \; select-layout tiled
done
if [ $OK = "1" ]; then
tmux set-window-option synchronize-panes \; send-keys ENTER
tmux kill-pane \; select-layout tiled
fi
fi
The script reads your ~/.ssh/config file and based on host entries it creates panes in a single tmux window and synchronises inputs to them. This allows for a simultaneous work done on multiple machines.
It also supports for setting styles for different hosts in your ~/.ssh/config file.
Usage:
Assuming you have a ~/.ssh/config file that looks like this:
host abc-*
User root
host abc-prod
# tmux-style: bg=red
Hostname 192.168.0.1
host abc-dr
# tmux-style: bg=blue
Hostname 192.168.0.2
host def-vm-*
User admin
host def-vm-1
Hostname 192.168.0.11
host def-vm-2
Hostname 192.168.0.12
host def-vm-3
Hostname 192.168.0.13
host def-vm-4
Hostname 192.168.0.14
host def-vm-5
Hostname 192.168.0.15
And also assuming that you saved the script in ~/bin/st then running this command:
$ st abc
will spawn to synchronised panes in your current window one with red and one with blue background
if you run:
$ st def-vm
or
$ st def-
it will spawn five panes to each one of the def-vm machines.
simple JSON pretty printer that you can easily copy paste
Simple JSON pretty printer that you can easily copy paste. Useful when you need to read a big JSON output and you are on a remote machine on which you can not install a lot.
python -c 'import sys; import json; import pprint; pprint.pprint(json.loads(sys.stdin.read()))'
Usage:
somecommand_that_generates_json_output | python -c 'import sys; import json; import pprint; pprint.pprint(json.loads(sys.stdin.read()))'
Subscribe to:
Posts (Atom)