Category Archives: quickies

TermRecord self-contained HTML Video!

Terminal session recorder that outputs self-contained HTML!

You can then email it to anyone to show them how to do something via command line.

They open it in a browser and it plays like movie.

Download it here https://github.com/theonewolf/TermRecord

or if you have pip installed use ” pip install TermRecord ”

usage: TermRecord [-h] [-b {script,ttyrec}] [-c COMMAND] [-d h w] [–json]
[–js] [-m TEMPLATE_FILE] [-o OUTPUT_FILE] [-s SCRIPT_FILE]
[-t TIMING_FILE]

Stores terminal sessions into HTML.

optional arguments:
-h, –help            show this help message and exit
-b {script,ttyrec}, –backend {script,ttyrec}
use either script or ttyrec
-c COMMAND, –command COMMAND
run a command and quit
-d h w, –dimensions h w
dimensions of terminal
–json                output only JSON
–js                  output only JavaScript
-m TEMPLATE_FILE, –template-file TEMPLATE_FILE
file to use as HTML template
-o OUTPUT_FILE, –output-file OUTPUT_FILE
file to output HTML to
-s SCRIPT_FILE, –script-file SCRIPT_FILE
script file to parse
-t TIMING_FILE, –timing-file TIMING_FILE
timing file to parse

 

grep for an IPv4 address

grep for an ip address and sort it with a count

lastb | grep -Eo '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | sort | uniq -c | sort -k 1 -g

or

to show login attempts

grep -E '[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}' /var/log/secure | grep -i authentication

find excluding whole or partial paths (like grep -v)

” | wc -l ” to show the number of files found

[root@titan ~]# find / -iname ‘*.tgz’ | wc -l
269

[root@titan ~]# find / -iname ‘.tgz’ -a ! -path “backups*” | wc -l
38

[root@titan ~]# find / -iname ‘.tgz’ -a ! -path “b*” | wc -l
15

[root@titan ~]# find / -iname ‘.tgz’ -a ! -path “x*” | wc -l
241

OR with -prune ( ignore a directory and the files under it )

find / -name “backup” -prune -o -name ‘.pdf’ -print

find / -path /backups -prune -o -iname *?.rpm?* find all your rpmnew and rpmsave files but ignore your backup directory

find / -name “.tgz” -print -o -path ‘/home’ -prune -print -o -path ‘/www’ -prune

find . -iname “.pdf” -print -o -path “Accounts” -prune

this works as well

find / -name “.tgz” -o -path ‘/home’ -prune -o -path ‘/www’ -prune -o -path ‘/backups’ -prune

‘/home’ excludes home and anything under it.

‘*/www’ excludes any path with www in it.

Find and Copy with xargs

find . -name *.log -print0 | xargs -I{} -0 cp -v {} /tmp/log-files

Find and Move with xargs

find /mnt/cloud_drive/tarballs/./* -size -14M -print0 | xargs -0 -I {} mv -iv {} /path/to/new/dir

ffmpeg: error while loading shared libraries: libavdevice.so.56:

On CentOS 7 I got this error trying to run ffmpeg

ffmpeg: error while loading shared libraries: libavdevice.so.56: cannot open shared object file: No such file or directory

doing ldd $(which ffmpeg) gave me this

[root@titan ~]# ldd $(which ffmpeg)
linux-vdso.so.1 =>  (0x00007fffa2dfe000)
libavdevice.so.56 => not found
libavfilter.so.5 => not found
libavformat.so.56 => not found
libavcodec.so.56 => not found
libpostproc.so.53 => not found
libswresample.so.1 => not found
libswscale.so.3 => not found
libavutil.so.54 => not found
libm.so.6 => /lib64/libm.so.6 (0x00007fb7084e5000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fb7082c9000)
libc.so.6 => /lib64/libc.so.6 (0x00007fb707f07000)
/lib64/ld-linux-x86-64.so.2 (0x00007fb708805000)

find gave me this

[root@titan ~]# find / -name “libavdevice.so.56*”
/usr/local/lib/libavdevice.so.56.3.100
/usr/local/lib/libavdevice.so.56
[root@titan ~]#

I added

/usr/local/lib/

to the /etc/ld.so.conf

so it now reads

[root@titan ~]# cat /etc/ld.so.conf
include ld.so.conf.d/*.conf
/usr/local/lib/

update with

[root@titan ~]# ldconfig

Now it works fine!

Math with bash

must be in double quotes * / % – +

echo “$(( 81712196 / 1024 ))”

79797

echo “$(( 81712196 * 1024 ))”

83673288704

echo “$(( 81712196 % 1024 ))”

68

OR pipe it through bc

echo ‘scale=6; 12*613-894/3.5’ | bc and the answer is 7100.571429

OR

echo “scale=6; (3*3-6+4*5-2)/7*2” | bc -i
bc 1.06.95
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty’.
scale=6; (3*3-6+4*5-2)/7*2
6.000000

OR

Simply use tcalc…

who’s been ftp’ing

if you run the following from the command line you’ll get a nice colourful screen output of ftp access

awk '{print $2,$3,$4, "direction="$12," user="$14," complete="$18," fromIP="$7," size="$8, " FileName="$9}' /var/log/xferlog | grep --color 'direction=\|user=\|complete=\|fromIP=\|size=\|FileName='