diff --git a/Bash-Trim-Whitespace.md b/Bash-Trim-Whitespace.md new file mode 100644 index 0000000..b7d13cd --- /dev/null +++ b/Bash-Trim-Whitespace.md @@ -0,0 +1,17 @@ +Trim whitespace in pure bash + +``` +# turn it on +shopt -s extglob +output=" This is a test " + +### Trim leading whitespaces ### +output="${output##*( )}" + +### trim trailing whitespaces ## +output="${output%%*( )}" +echo "=${output}=" + +# turn it off +shopt -u extglob +``` diff --git a/Git-Combine-Repos.md b/Git-Combine-Repos.md new file mode 100644 index 0000000..4c96717 --- /dev/null +++ b/Git-Combine-Repos.md @@ -0,0 +1,28 @@ +Combine repos in git + +``` +# Create a new empty repo and clone it ("origin") +git clone git@gitlab.com:${myname}/newproject.git +cd newproject/ + +# Do basic required config if needed +git config user.name ${myname} +git config user.email ${myemail} + +# Add each remote repo as a subdir (prefix) including commit history +git subtree add --prefix=oldproject_1 \ + git@gitlab.com:${myname}/oldproject_1.git master +git subtree add --prefix=oldproject_2 \ + git@gitlab.com:${myname}/oldproject_2.git master + +# Do any cleanup needed - for example getting rid of a submodule +git rm oldproject_1/somegitsubmodule +git rm oldproject_1/.gitmodules +git commit -m "remove stale submodule" \ + oldproject_1/.gitmodules \ + oldproject_1/somegitsubmodule + +# Commit the results back up to your new project +git push origin master +``` + diff --git a/Loopback-FS.md b/Loopback-FS.md new file mode 100644 index 0000000..1d63f6c --- /dev/null +++ b/Loopback-FS.md @@ -0,0 +1,56 @@ +Creating a loopback filsystem and investigating structures + +``` +dd if=/dev/zero of=msdos.dat bs=4096 count=20480 +dd if=/dev/zero of=gpt.dat bs=4096 count=20480 + +parted ./msdos.dat mktable msdos +parted ./gpt.dat mktable gpt +hexdump -C ./msdos.dat > msdos_table.hex +hexdump -C ./gpt.dat > gpt_table.hex + +parted ./msdos.dat mkpart primary ext3 2048s 100% +parted ./gpt.dat mkpart primary ext3 2048s 100% +hexdump -C msdos.dat > msdos_part.hex +hexdump -C gpt.dat > gpt_part.hex + +sudo losetup -P /dev/loop0 ./msdos.dat +sudo losetup -P /dev/loop1 ./gpt.dat +sudo pvcreate /dev/loop0p1 +sudo pvcreate /dev/loop1p1 +sudo losetup -d /dev/loop0 +sudo losetup -d /dev/loop1 +hexdump -C msdos.dat > msdos_pv.hex +hexdump -C gpt.dat > gpt_pv.hex + +sudo losetup -P /dev/loop0 ./msdos.dat +sudo losetup -P /dev/loop1 ./gpt.dat +sudo pvscan --cache +sudo vgcreate vgmsdos /dev/loop0p1 +sudo vgcreate vggpt /dev/loop1p1 +sudo losetup -d /dev/loop0 +sudo losetup -d /dev/loop1 +hexdump -C msdos.dat > msdos_vg.hex +hexdump -C gpt.dat > gpt_vg.hex + +sudo losetup -P /dev/loop0 ./msdos.dat +sudo losetup -P /dev/loop1 ./gpt.dat +sudo pvscan --cache +sudo lvcreate -l 100%FREE -n lvmsdos vgmsdos +sudo lvcreate -l 100%FREE -n lvgpt vggpt +sudo losetup -d /dev/loop0 +sudo losetup -d /dev/loop1 +hexdump -C msdos.dat > msdos_lv.hex +hexdump -C gpt.dat > gpt_lv.hex + +sudo losetup -P /dev/loop0 ./msdos.dat +sudo losetup -P /dev/loop1 ./gpt.dat +sudo pvscan --cache +sudo mkfs.ext4 -E lazy_itable_init=0,lazy_journal_init=0 /dev/vgmsdos/lvmsdos +sudo mkfs.ext4 -E lazy_itable_init=0,lazy_journal_init=0 /dev/vggpt/lvgpt +sudo losetup -d /dev/loop0 +sudo losetup -d /dev/loop1 +hexdump -C msdos.dat > msdos_ext.hex +hexdump -C gpt.dat > gpt_ext.hex +``` + diff --git a/Mount-OVA.md b/Mount-OVA.md new file mode 100644 index 0000000..a621aa4 --- /dev/null +++ b/Mount-OVA.md @@ -0,0 +1,12 @@ +Mount OVA (VM export file) using vboxmanage + +``` +# mount OVA to examine contents +# - uses vboxmanage (VirtualBox tool) to convert to RAW first + +tar zxf debian_10_pvhvm.ova.gz image.vhd +vboxmanage clonemedium disk image.vhd image.raw --format RAW +sudo fdisk -l ./image.raw # (look for beginning of first partition, it's at 2048 sector) +sudo mount -o offset=$((2048*512)) ./image.raw /mnt +``` + diff --git a/Server-Notes.md b/Server-Notes.md new file mode 100644 index 0000000..96fbf70 --- /dev/null +++ b/Server-Notes.md @@ -0,0 +1,163 @@ +Random server oriented notes, all over the map + +``` +Device Mapper: + lvdisplay|awk '/LV Name/{n=$3} /Block device/{d=$3;sub(".*:","dm-",d);print d,n;}'|sort -nk 3 + dmsetup ls|awk '{n=$1;d=$3;sub(")","",d); printf("dm-%s %s\n",d,n);}'|sort -nk 3 + + +ISO Images with Linux +===================== +genisoimage -f -J -joliet-long -r -allow-lowercase -allow-multidot \ + -o foobar.iso path_to_directory_with_files + + +Notify / inotify +================ +ps $(find /proc/*/fd/* -type l -lname 'anon_inode:inotify' 2>/dev/null \ + | sed 's+/proc/\([^/]*\)/fd/.*+\1+') +echo 1 > /sys/kernel/debug/tracing/events/syscalls/sys_exit_inotify_add_watch/enable +cat /sys/kernel/debug/tracing/tracing_on +grep -c inotify_add_watch /sys/kernel/debug/tracing/trace +echo 0 > /sys/kernel/debug/tracing/events/syscalls/sys_exit_inotify_add_watch/enable + + +VirtualBox +========== +$ vboxmanage showmediuminfo disk source.vhdx +$ vboxmanage clonemedium disk source.vhdx dest.vdi + + +LVM cluster volume work +======================= +https://access.redhat.com/solutions/3618 +vgchange -cn --config 'global {locking_type=0}' vgsan00 + + +Capture bash history of logged in user +====================================== +PID=1234; gdb -batch --eval "set sysroot /" --eval "attach ${PID}" \ + --eval "call write_history(\"/tmp/history-${PID}.txt\")" \ + --eval 'detach' --eval 'q' + + +Add to glibc +============ +MYGLIBC=$(rpm -q --queryformat='%{version}-%{release}\n' glibc | uniq) +yum --showduplicates --disableexcludes=all install nscd-${MYGLIBC} + + +RHEL Cluster check +================== +xmllint -relaxng /usr/share/cluster/cluster.rng /etc/cluster/cluster.conf + + +Tomcat SSL +========== +http://www.digicert.com/ssl-certificate-installation-tomcat.htm +- keyAlias="tomcat" keystoreFile="tomcat.jks" keypass="tomcat" + +# openssl pkcs12 -export -name tomcat -in tomcat.crt -inkey tomcat.key -out tomcat.p12 -CAfile GeoTrust_Inc.cabundle -caname root +# keytool -importkeystore -destkeystore tomcat.jks -srckeystore tomcat.p12 -srcstoretype pkcs12 -alias tomcat +# keytool -list -v -keystore tomcat.jks + + +SSL cert checks +=============== +openssl x509 -in XXX.crt -text | grep CN= +openssl x509 -modulus -noout -in XXXX.crt | openssl md5 +openssl rsa -modulus -noout -in XXXX.key | openssl md5 + + +Oracle nifties +============== +$ lsnrctl status +$ ps -ef|grep pmon |grep -vi grep|grep -vi asm (Oracle ASM) + +$ ps -ef|grep crs (Oracle RAC) +$ su - oracle +$ sqlplus / as sysdba (it will show RAC is installed) +$ select * from gv$active_instances; (verify 100% if there is RAC) + +http://docs.oracle.com/cd/B28359_01/server.111/b31107/asmdiskgrps.htm#CHDIBGGH + + +oracle database size check +------------------------------- +--- Acutal size of segments i.e. tables/indexes +select sum(bytes)/(1024*1024*1024) from dba_segments; +select sum(bytes)/(1024*1024*1024) from dba_data_files; +-- total size of data files + +crosscheck +-------------------------------------- +Login to “rman target backupadmin/pwd@tns catalog cname/passwd@catalog” once you get “RMAN>” prompt, please run the following: +RMAN> Crosscheck ARCHIVELOG ALL; + +oracle query for list of the tablespaces +-------------------------------------- +select tablespace_name, CONTENTS from dba_tablespaces; + +oracle query for list of datafiles +-------------------------------------- +SELECT NAME, FILE#, STATUS, CHECKPOINT_CHANGE# "CHECKPOINT" FROM V$DATAFILE; + +https://docs.oracle.com/cd/B28359_01/server.111/b28310/dfiles010.htm#ADMIN11459 +https://docs.oracle.com/cd/B19306_01/server.102/b14237/dynviews_1076.htm#REFRN30050 + +ASM disk timeouts + +SQL> select name,value,describe from v$asm_hidden_paras; +NAME VALUE DESCRIBE +--------------------------------------- -------- ---------------------------------------------------------------------- +_asm_acd_chunks 1 initial ACD chunks created +[...] +_asm_global_dump_level 267 System state dump level for ASM asserts +_asm_hbeatiowait 15 number of secs to wait for PST Async Hbeat IO return +_asm_hbeatwaitquantum 2 quantum used to compute time-to-wait for a PST Hbeat check + + +SCSI Device Ops +=============== +echo "- - -" > /sys/class/scsi_host/hostX/scan where X is your HBA +echo 1 > /sys/block/sdX/device/rescan where X is your device number +echo 1 > /sys/block/sdX/device/delete where X is your device number + + +MySQL Things +============ +MySQL slave check: +mysql -e "show slave status\G;" | awk '/Slave_IO_Running|Slave_SQL_Running|Seconds_Behind/' + +MySQL killer for AmReg: +for x in `mysqladmin processlist | grep -i select | awk -F"|" ' $7 > 30 { print $2 }'` ; do mysqladmin kill $x ; done + +MySQL real DB size by DB: +SELECT table_schema "Name", sum( data_length + index_length ) / 1024 / 1024 / 1024 "Size in GB" FROM information_schema.TABLES GROUP BY table_ +schema; + +MySQL real DB size by Engine: +select engine,count(*),sum(index_length+data_length)/1024/1024 from information_schema.tables group by engine; + +MySQL table size of a single table: +SELECT table_name,`engine`,ROUND(data_length/1024/1024,2) total_size_mb,ROUND(index_length/1024/1024,2) total_index_size_mb, table_rows FROM +information_schema.TABLES WHERE table_schema = 'threadless' and table_name = 'users'; + +MySQL flush buffers for shutdown: +# mysql -e "flush logs;" +# mysql -e "SET @@global.innodb_max_dirty_pages_pct = 0;" +# mysql -e "show global status like ‘Innodb_buffer_pool_pages_dirty’;" +## mysqladmin ext -i10 | grep dirty + +MySQL increase connections: +gdb -p $(cat /var/run/mysqld/mysqld.pid) -ex "set max_connections=5000" -batch + +Some low disk things + +Low Disk (current directory, w/top 20 on largest directories) +FS="$PWD";resize;clear;date;df -h $FS; echo "Largest Directories:"; nice -n19 find $FS -mount -type d -print0 2>/dev/null|xargs -0 du -k 2>/dev/null|sort -runk1|head -n20|awk -F'\t' '{printf "%8d MB\t%s\n",($1/1024),$NF}';echo "Largest Files:"; nice -n 19 find $FS -mount -type f -print0 2>/dev/null| xargs -0 du -k | sort -rnk1| head -n20 |awk -F'\t' '{printf "%8d MB\t%s\n",($1/1024),$NF}'; + +Low Disk (current directory, takes into account sparse files) +FS='./';resize;clear;date;df -h $FS; echo "Largest Directories:"; du -hcx --max-depth=2 $FS 2>/dev/null | grep [0-9]G | sort -grk 1 | head -15 ;echo "Largest Files:"; nice -n 19 find $FS -mount -type f -print0 2>/dev/null| xargs -0 du -k | sort -rnk1| head -n20 |awk -F'\t' '{printf "%8d MB\t%s\n",($1/1024),$NF}' +``` + diff --git a/Smem-Datamash.md b/Smem-Datamash.md new file mode 100644 index 0000000..6156ed0 --- /dev/null +++ b/Smem-Datamash.md @@ -0,0 +1,7 @@ +Pull memory stats about a multi-process app and feed to datamash + +``` +smem -P "[f]iref" -c "uss pss rss" | datamash -H -W --output-delimiter="," sum 1-3 +smem -P "[c]hrom" -c "uss pss rss" | datamash -H -W --output-delimiter="," sum 1-3 +``` + diff --git a/YTM-to-Textbox.md b/YTM-to-Textbox.md new file mode 100644 index 0000000..9cf9ae1 --- /dev/null +++ b/YTM-to-Textbox.md @@ -0,0 +1,25 @@ +Google Play -> Youtube Music -> Spotlistr + +``` +#!/usr/bin/env bash + +# build import list for spotlistr + +## Screen Scrape to file +# 1. Open YTM playlist in browser +# 2. Scroll down to end, forces "lazy load" to load all tracks +# 3. Ctrl-a, Ctrl-c then Ctrl-v to file +# 4. Delete first few (~8) lines until it starts with first song +# - 4 lines per song (title artist album time) +# 5. Save and run through this script, creates .tbox +# 6. Paste .tbox into https://www.spotlistr.com/search/textbox + +# the screen-scrape saved filename is the input +YTM="$1" + +sed '/:[0-9]\{2\}$/{G;}' "${YTM}" > "${YTM}.tmp" +sed -i 's/,/;/' "${YTM}.tmp" +sed -E 'H;${x;s/(.)\n/\1,/g}' "${YTM}.tmp" | grep -F ',' > "${YTM}.csv" +awk -F, '{OFS=",";print $2 " - " $1}' "${YTM}.csv" > "${YTM}.tbox" +``` + diff --git a/_Sidebar.md b/_Sidebar.md index 6c8237f..1c4e0c6 100644 --- a/_Sidebar.md +++ b/_Sidebar.md @@ -6,11 +6,13 @@ - [[APT WhatProvides]] - [[Apache wpadmin]] +- [[Bash Trim Whitespace]] - [[DB2 Info]] - [[Debian Upgrade]] - [[Dell OpenManage]] - [[Find Examples]] - [[Firefox Tweaks]] +- [[Git Combine Repos]] - [[Git Multi SSH]] - [[Git Rewrite User]] - [[Git Server]] @@ -19,7 +21,9 @@ - [[IPv4 Default Gateway]] - [[Kernel Boot Debug]] - [[LUKS Encrypted Partitions]] +- [[Loopback FS]] - [[MX Blackhole]] +- [[Mount OVA]] - [[Mount qcow2]] - [[Netcat Replacements]] - [[Proxmox Doodads]] @@ -28,8 +32,11 @@ - [[Recover Deleted ext3]] - [[Roku Info]] - [[Samba OSX]] +- [[Server Notes]] +- [[Smem Datamash]] - [[Thunderbird LDAP AD]] - [[uBlock Filters]] - [[udev Hide Partitions]] - [[Weechat Quickstart]] +- [[YTM to Textbox]]