more content
parent
1f3efc2ffc
commit
dddc754516
9 changed files with 269 additions and 0 deletions
103
BCC-Examples.md
Normal file
103
BCC-Examples.md
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
Random examples of using BCC tools
|
||||
|
||||
```
|
||||
$ sudo python2 /usr/share/bcc/tools/biosnoop
|
||||
TIME(s) COMM PID DISK T SECTOR BYTES LAT(ms)
|
||||
0.000019000 ? 0 R -1 8 1.76
|
||||
0.993713000 Chrome_FileThr 3774 sda W 513149392 4096 10.12
|
||||
0.994569000 jbd2/dm-0-8 523 sda W 533988192 57344 0.59
|
||||
1.051730000 kworker/u32:1 17321 sda W 542135576 4096 13.12
|
||||
1.051821000 kworker/u32:1 17321 sda W 546060336 4096 13.21
|
||||
1.051845000 kworker/u32:1 17321 sda W 546060376 8192 13.23
|
||||
1.051867000 kworker/u32:1 17321 sda W 546060392 4096 13.25
|
||||
|
||||
$ sudo python2 /usr/share/bcc/tools/biolatency
|
||||
Tracing block device I/O... Hit Ctrl-C to end.
|
||||
usecs : count distribution
|
||||
0 -> 1 : 0 | |
|
||||
2 -> 3 : 0 | |
|
||||
4 -> 7 : 0 | |
|
||||
8 -> 15 : 0 | |
|
||||
16 -> 31 : 0 | |
|
||||
32 -> 63 : 0 | |
|
||||
64 -> 127 : 0 | |
|
||||
128 -> 255 : 0 | |
|
||||
256 -> 511 : 10 |****************************************|
|
||||
512 -> 1023 : 8 |******************************** |
|
||||
1024 -> 2047 : 2 |******** |
|
||||
2048 -> 4095 : 10 |****************************************|
|
||||
4096 -> 8191 : 0 | |
|
||||
8192 -> 16383 : 1 |**** |
|
||||
|
||||
$ sudo python2 /usr/share/bcc/tools/tcpv4connect
|
||||
PID COMM SADDR DADDR DPORT
|
||||
2237 Socket Threa 192.168.1.72 216.58.218.167 443
|
||||
17224 curl 192.168.1.72 173.194.115.71 80
|
||||
17230 wget 192.168.1.72 192.30.252.131 80
|
||||
17230 wget 192.168.1.72 192.30.252.131 443
|
||||
3778 Chrome_IOThr 192.168.1.72 216.58.218.174 443
|
||||
3778 Chrome_IOThr 192.168.1.72 173.194.17.120 443
|
||||
3778 Chrome_IOThr 192.168.1.72 173.194.17.120 443
|
||||
3778 Chrome_IOThr 192.168.1.72 173.194.17.120 443
|
||||
3778 Chrome_IOThr 192.168.1.72 173.194.17.120 443
|
||||
3778 Chrome_IOThr 192.168.1.72 173.194.17.120 443
|
||||
3778 Chrome_IOThr 192.168.1.72 173.194.17.120 443
|
||||
3778 Chrome_IOThr 192.168.1.72 173.194.17.120 443
|
||||
3778 Chrome_IOThr 192.168.1.72 173.194.17.120 443
|
||||
3778 Chrome_IOThr 192.168.1.72 173.194.17.120 443
|
||||
3778 Chrome_IOThr 192.168.1.72 173.194.17.120 443
|
||||
3778 Chrome_IOThr 192.168.1.72 173.194.17.120 443
|
||||
|
||||
|
||||
$ sudo python2 /usr/share/bcc/tools/opensnoop
|
||||
PID COMM FD ERR PATH
|
||||
17538 <...> 6 0 /sys/kernel/debug/tracing/trace_pipe
|
||||
3811 BrowserBlocking -1 2 /home/tengel/.config/chromium/Default/Storage/ext/fahmaaghhglfm
|
||||
3811 BrowserBlocking 221 0 /home/tengel/.config/chromium/Default/Storage/ext/fahmaaghhglfm
|
||||
3814 BrowserBlocking -1 2 /home/tengel/.config/chromium/Default/Storage/ext/fahmaaghhglfm
|
||||
3814 BrowserBlocking 221 0 /home/tengel/.config/chromium/Default/Storage/ext/fahmaaghhglfm
|
||||
1801 gkrellm 12 0 /proc/meminfo
|
||||
3814 BrowserBlocking 221 0 /home/tengel/.config/chromium/.org.chromium.Chromium.WyKZxd
|
||||
3814 BrowserBlocking 221 0 /home/tengel/.config/chromium/.org.chromium.Chromium.WyKZxd
|
||||
3778 Chrome_IOThread 221 0 /dev/shm/.org.chromium.Chromium.2S3mnm
|
||||
1801 gkrellm 12 0 /proc/meminfo
|
||||
|
||||
$ sudo python2 /usr/share/bcc/tools/funccount 'vfs_*'
|
||||
Tracing 44 functions for "vfs_*"... Hit Ctrl-C to end.
|
||||
ADDR FUNC COUNT
|
||||
ffffffff81229dd1 vfs_lock_file 8
|
||||
ffffffff811e69f1 vfs_create 9
|
||||
ffffffff811e3ca1 vfs_unlink 9
|
||||
ffffffff8120b541 vfs_fsync_range 17
|
||||
ffffffff811de421 vfs_fstat 85
|
||||
ffffffff811d9db1 vfs_writev 91
|
||||
ffffffff811d8731 vfs_open 100
|
||||
ffffffff811de481 vfs_fstatat 493
|
||||
ffffffff811de3f1 vfs_getattr 572
|
||||
ffffffff811de1d1 vfs_getattr_nosec 572
|
||||
ffffffff811d9991 vfs_write 3373
|
||||
ffffffff811d9871 vfs_read 4410
|
||||
Detaching...
|
||||
|
||||
$ sudo python2 /usr/share/bcc/tools/funclatency do_sys_open
|
||||
Tracing 1 functions for "do_sys_open"... Hit Ctrl-C to end.
|
||||
nsecs : count distribution
|
||||
0 -> 1 : 0 | |
|
||||
2 -> 3 : 0 | |
|
||||
4 -> 7 : 0 | |
|
||||
8 -> 15 : 0 | |
|
||||
16 -> 31 : 0 | |
|
||||
32 -> 63 : 0 | |
|
||||
64 -> 127 : 0 | |
|
||||
128 -> 255 : 0 | |
|
||||
256 -> 511 : 0 | |
|
||||
512 -> 1023 : 0 | |
|
||||
1024 -> 2047 : 0 | |
|
||||
2048 -> 4095 : 0 | |
|
||||
4096 -> 8191 : 0 | |
|
||||
8192 -> 16383 : 3 |******************** |
|
||||
16384 -> 32767 : 3 |******************** |
|
||||
32768 -> 65535 : 6 |****************************************|
|
||||
Detaching...
|
||||
```
|
||||
|
||||
10
Bash-Add-fd.md
Normal file
10
Bash-Add-fd.md
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
If you've run out of file descriptors but can manage to get to a shell without needing to open more, bash can handle the rest using built in features.
|
||||
|
||||
```
|
||||
#!/usr/bin/env bash
|
||||
|
||||
builtin read -r NFM < /proc/sys/fs/file-max
|
||||
NFM=$(($NFM+100))
|
||||
builtin echo $NFM > /proc/sys/fs/file-max
|
||||
```
|
||||
|
||||
63
CPU-Stats.md
Normal file
63
CPU-Stats.md
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
Sample the CPU for stats while testing
|
||||
|
||||
```
|
||||
#!usr/bin/env bash
|
||||
|
||||
DTS=$(date +"%Y%m%d")
|
||||
|
||||
if [[ -z "$1" ]]; then
|
||||
echo "Usage: $0 xxx"
|
||||
echo " where xxx is the number of seconds to collect data"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# check deps
|
||||
command -v awk >/dev/null 2>&1 || {
|
||||
echo " awk not installed. Aborting!" >&2; exit 1; }
|
||||
|
||||
command -v bc >/dev/null 2>&1 || {
|
||||
echo " bc not installed. Aborting!" >&2; exit 1; }
|
||||
|
||||
# make sure $1 is an interger
|
||||
[[ "$1" =~ ^-?[0-9]+$ ]] || {
|
||||
echo " Supply an interger and try again." >&2; exit 1; }
|
||||
|
||||
[[ -d $XDG_RUNTIME_DIR ]] &&
|
||||
file=$XDG_RUNTIME_DIR/"stats-$DTS" || file=/tmp/"stats-$DTS"
|
||||
|
||||
[[ -f /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq ]] || {
|
||||
echo " Cannot tell what the CPU current CPU frequency is. Aborting!" >&2; exit 1; }
|
||||
|
||||
function full_exit {
|
||||
[[ ! -r "$file" ]] && exit 1
|
||||
# credit for awk magic goes to
|
||||
# http://stackoverflow.com/questions/6166375/median-of-column-with-awk
|
||||
median=$(sort -n $file | awk ' { a[i++]=$1; } END { x=int((i+1)/2); if (x < (i+1)/2) print (a[x-1]+a[x])/2; else print a[x-1]; }')
|
||||
mean=$(awk '{ sum += $1; n++ } END { if (n > 0) print sum / n; }' $file)
|
||||
min=$(sort -n $file | head -n1)
|
||||
max=$(sort -n $file | tail -n1)
|
||||
|
||||
echo
|
||||
echo "All values in MHz except count which is just the number of measurements..."
|
||||
echo "median : $median"
|
||||
echo "mean : $mean"
|
||||
echo "max : $max"
|
||||
echo "min : $min"
|
||||
echo "count : $(wc -l $file|awk '{print $1}')"
|
||||
|
||||
[[ -f $file ]] && rm -f $file
|
||||
exit 0
|
||||
}
|
||||
trap full_exit SIGHUP SIGINT SIGTERM
|
||||
|
||||
echo "Collecting data for $1 seconds..."
|
||||
TIME=( $(seq 1 1 "$1") )
|
||||
|
||||
for i in "${TIME[@]}"; do
|
||||
sleep 1
|
||||
bc <<< "scale=1; $(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq)/1000" >> "$file"
|
||||
done
|
||||
|
||||
full_exit
|
||||
```
|
||||
|
||||
23
MP3-Get-Tags.md
Normal file
23
MP3-Get-Tags.md
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
Pull out mp3 tags to create a libre.fm import file
|
||||
|
||||
```
|
||||
#!/usr/bin/env bash
|
||||
|
||||
DTB=1251499494 # epoch start time
|
||||
DTS=$(date +%s) # epoch current time
|
||||
DAT="${HOME}/Music"
|
||||
while IFS="" read -r -d $'\000' mp3 <&3; do
|
||||
DTN=$(shuf -i $DTB-$DTS -n 1) # random epoch between
|
||||
ART=$(mid3v2 -l "$mp3" | grep "^TPE1" | cut -d'=' -f2)
|
||||
SNG=$(mid3v2 -l "$mp3" | grep "^TIT2" | cut -d'=' -f2)
|
||||
ALB=$(mid3v2 -l "$mp3" | grep "^TALB" | cut -d'=' -f2)
|
||||
echo -e "$DTN\t$SNG\t$ART\t$ALB\t\t\t"
|
||||
done 3< <(find "$DAT" -mindepth 1 -name \*.mp3 -print0)
|
||||
|
||||
# Use libreimport.py / scrobble.py from here:
|
||||
# http://bugs.foocorp.net/projects/librefm/wiki/LastToLibre
|
||||
#
|
||||
# Connect libre.fm to your last.fm account first, then the scrobbles
|
||||
# import to both services at once for your entire local music library.
|
||||
```
|
||||
|
||||
16
Recursive-Unzip.md
Normal file
16
Recursive-Unzip.md
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
Quick and dirty, probably isn't super safe
|
||||
|
||||
```
|
||||
#!/usr/bin/env bash
|
||||
shopt -s globstar nullglob
|
||||
while set -- **/*.zip; [ $# -ge 1 ] do
|
||||
for z; do
|
||||
( cd -- "$(dirname "$z")" &&
|
||||
z=${z##*/} &&
|
||||
unzip -- "$z" &&
|
||||
rm -- "$z"
|
||||
)
|
||||
done
|
||||
done
|
||||
```
|
||||
|
||||
8
SSL-Certgen.md
Normal file
8
SSL-Certgen.md
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
Generate a SSL self-signed key/cert
|
||||
|
||||
```
|
||||
openssl req -new -newkey rsa:4096 -days 3650 -nodes -x509 -utf8 -sha256 \
|
||||
-subj "/C=US/ST=New York/L=New York/O=MyOrg/CN=myorg.com" \
|
||||
-keyout certificate.key -out certificate.crt
|
||||
```
|
||||
|
||||
22
Split-Disk.md
Normal file
22
Split-Disk.md
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
Cut a disk in half based on sectors, skipping the first 2048
|
||||
|
||||
```
|
||||
#!/usr/bin/env bash
|
||||
|
||||
DISK="/dev/xvdb"; OFFSET=2048 \
|
||||
parted ${DISK} unit s print 2>/dev/null | \
|
||||
grep "^Disk ${DISK}" | \
|
||||
awk -v OFF=${OFFSET} '{gsub(/s$/,"",$3); \
|
||||
printf "STA1=%s\nEND1=%s\nLEN1=%s\nSTA2=%s\nEND2=%s\nLEN2=%s\n",
|
||||
OFF,(($3/2)-OFF),((($3/2)-OFF)-OFF),
|
||||
((($3/2)-OFF)+1),$3,($3-((($3/2)-OFF)+1))
|
||||
}'
|
||||
|
||||
# example output
|
||||
STA1=2048
|
||||
END1=78641152
|
||||
LEN1=78639104
|
||||
STA2=78641153
|
||||
END2=157286400
|
||||
LEN2=78645247
|
||||
```
|
||||
16
YUM-Disablerepos.md
Normal file
16
YUM-Disablerepos.md
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
Disable all yum repos
|
||||
|
||||
```
|
||||
python -c """from ConfigParser import ConfigParser
|
||||
from glob import glob
|
||||
repo_files = glob('/etc/yum.repos.d/*.repo')
|
||||
for file in repo_files:
|
||||
config = ConfigParser()
|
||||
config.read(file)
|
||||
sections = config.sections()
|
||||
for section in sections:
|
||||
config.set(section, 'enabled', 0)
|
||||
f = open(file, 'wb')
|
||||
config.write(f)
|
||||
f.close()"""
|
||||
```
|
||||
|
|
@ -4,8 +4,11 @@
|
|||
- [[Apache wpadmin]]
|
||||
- [[Arch Default Kernel]]
|
||||
- [[Arch Kernel Order]]
|
||||
- [[BCC Examples]]
|
||||
- [[Bash Add fd]]
|
||||
- [[Bash Dump History]]
|
||||
- [[Bash Trim Whitespace]]
|
||||
- [[CPU Stats]]
|
||||
- [[CSS Reset]]
|
||||
- [[DB2 Info]]
|
||||
- [[Debian Upgrade]]
|
||||
|
|
@ -29,6 +32,7 @@
|
|||
- [[LUKS Encrypted Partitions]]
|
||||
- [[Linux Valid Usernames]]
|
||||
- [[Loopback FS]]
|
||||
- [[MP3 Get Tags]]
|
||||
- [[MX Blackhole]]
|
||||
- [[Markdown Samples]]
|
||||
- [[Mount OVA]]
|
||||
|
|
@ -40,14 +44,18 @@
|
|||
- [[RPM Info]]
|
||||
- [[Radeon Temperature]]
|
||||
- [[Recover Deleted ext3]]
|
||||
- [[Recursive Unzip]]
|
||||
- [[Roku Info]]
|
||||
- [[SSL Certgen]]
|
||||
- [[Samba OSX]]
|
||||
- [[Server Notes]]
|
||||
- [[Smem Datamash]]
|
||||
- [[Split Disk]]
|
||||
- [[systemd PID1]]
|
||||
- [[Thunderbird LDAP AD]]
|
||||
- [[uBlock Filters]]
|
||||
- [[udev Hide Partitions]]
|
||||
- [[Weechat Quickstart]]
|
||||
- [[YTM to Textbox]]
|
||||
- [[YUM Disablerepos]]
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue