Skip to content

Instantly share code, notes, and snippets.

View stefanlasiewski's full-sized avatar

Stefan Lasiewski stefanlasiewski

  • LBNL (Lawrence Berkeley National Laboratory)
  • Berkeley, CA
View GitHub Profile
@stefanlasiewski
stefanlasiewski / hieravalidate.sh
Last active April 23, 2017 10:54
Puppet validate hiera #1
#!/bin/sh
# Search the module path for all key values used in a hiera_array lookup, and then perform the equivalent of a hiera_array() from puppet.
# Borrowed from https://ask.puppetlabs.com/question/10999/hiera-how-can-i-tell-which-class-triggered-expected-array-and-got-nilclass/?answer=11006#post-id-11006
# The original:
# ```
# for y in $(for x in $(puppet config print modulepath | sed -e "s/:/ /g"); do grep -PIRho "(?<=hiera_array\(['|\"|$])([^'|^\"|^,|^\)]+)" $x; done); do echo hiera -d -a -c $(puppet config print confdir)/hiera.yaml $y <key=value pairs as needed for your hiera.yaml>; done
# ```
@stefanlasiewski
stefanlasiewski / gist:456bdb5476ecce9cdfee67127c42d92b
Created September 27, 2017 19:24
DNS for SFDPH.ORG doesn't resolve. www.SFDPH.ORG does
# Tested from a Mac command-line
$ dig +noall +answer SFDPH.ORG
$ dig +noall +answer www.SFDPH.ORG
www.sfdph.org. 1638 IN CNAME evqf8.x.incapdns.net.
evqf8.x.incapdns.net. 29 IN A 199.83.131.153
$
@stefanlasiewski
stefanlasiewski / logging-test.bash
Last active March 6, 2018 22:27
Easy logging for any bash script
#!/usr/bin/env bash
# A handy way to redirect script output to syslog
# Way more granular then adding a bunch of `/usr/bin/logger` stanzas
# Thanks to http://urbanautomaton.com/blog/2014/09/09/redirecting-bash-script-output-to-syslog/ &
# Eric at https://twitter.com/lindvall/status/509054237267853312
echo "writing to stdout, before the I/O redirection"
#!/usr/bin/env bash
#set -xv
# Update MacPorts base to latest released version using 'selfupdate'
# Then upgrade all outdated ports (upgrade outdated), and uninstall old version of each port (-u),
# following these guides:
# http://guide.macports.org/#using.common-tasks.updating
# http://guide.macports.org/#using.port.upgrade
@stefanlasiewski
stefanlasiewski / gist:1d71ee0ece9c65bd1365968c954422c0
Created May 22, 2018 23:53
Removing MySQL Server wants to remove postfix, cronie, redhat-lsb-core & more
[root@devdb ~]# yum remove mysql-commercial\*
Loaded plugins: fastestmirror, priorities, ps, security, versionlock
Setting up Remove Process
Resolving Dependencies
--> Running transaction check
---> Package mysql-commercial-client.x86_64 0:5.7.22-1.1.el6 will be erased
---> Package mysql-commercial-common.x86_64 0:5.7.22-1.1.el6 will be erased
---> Package mysql-commercial-libs.x86_64 0:5.7.22-1.1.el6 will be erased
--> Processing Dependency: mysql-libs for package: 2:postfix-2.6.6-6.el6_5.x86_64
---> Package mysql-commercial-libs-compat.x86_64 0:5.7.22-1.1.el6 will be erased
[root@devdb ~]# yum list --quiet mysql-community-server mysql-community-client mysql-community-libs mysql-community-common mysql-community-libs-compat
Available Packages
mysql-community-client.x86_64 5.7.22-1.el6 mysql57-community
mysql-community-common.x86_64 5.7.22-1.el6 mysql57-community
mysql-community-libs.x86_64 5.7.22-1.el6 mysql57-community
mysql-community-libs-compat.x86_64 5.7.22-1.el6 mysql57-community
mysql-community-server.x86_64 5.7.22-1.el6 mysql57-community
[root@devdb ~]# yum --quiet downgrade mysql-community-libs-5.7.22-1.el6.x86_64 mysql-community-common-5.7.22-1.
el6.x86_64 mysql-community-client-5.7.22-1.el6.x86_64 mysql-community-libs-compat-5.7.22-1.el6.x86_64 mys
ql-community-server-5.7.22-1.el6.x86_64
# List all network interfaces on my Mac
```
$ networksetup -listallnetworkservices
An asterisk (*) denotes that a network service is disabled.
Display Ethernet
Thunderbolt Ethernet
Wi-Fi
Display FireWire
Bluetooth PAN
@stefanlasiewski
stefanlasiewski / gist:d64bbc4a7a81079b4958b7f87472ea2e
Last active January 26, 2020 16:23
Using DD & PV for disk cloning with progress
# Coreutils 8.24+ ships with dd with the status=progress option
root@host:~# dd if=/dev/sdb conv=sync,noerror status=progress | lz4 > disk.img.lz4
1430323712 bytes (1.4 GB, 1.3 GiB) copied, 41 s, 34.9 MB/s
# pv (Pipeview) can also show a nice progress bar
root@host:~# dd if=/dev/sdb conv=sync,noerror | pv -tpreb | lz4 > ~stefanl/touch.img.lz4
472MiB 0:00:14 [36.0MiB/s] [ <=> ]
@stefanlasiewski
stefanlasiewski / git-branch-and-cat.txt
Created May 22, 2020 01:29
Print all git branches without needing to quit or needing to remember yet another flag
By default, `git branch` by default uses a pager, which requires that you quit out of the pager, which erases the results fmor your screen
stefanl@stefanl:zfs git branch --all
* master
remotes/origin/HEAD -> origin/master
remotes/origin/master
remotes/origin/top
remotes/origin/zfs-0.6.3-stable
(END)^C
@stefanlasiewski
stefanlasiewski / journalctl-and-less.txt
Created May 22, 2020 01:34
Use journalctl (systemd) with less, cat or tail
By default, `journalctl` will print the logs through a pager which can hide results from you. This can be annoying when trying to capture a screenshot:
root@docker01:~# journalctl -xe -u docker
May 21 23:25:40 docker01 dockerd[123]: time="2020-05-21T23:25:40.376573968Z" level=info msg="ign
May 22 00:45:37 docker01 dockerd[123]: time="2020-05-22T00:45:37.971043364Z" level=info msg="ign
lines 1006-1046/1046 (END)
Instead, pipe `journalctl` through `less`, `cat` or `tail` to quickly get familiar features such as wrapped lines:
root@docker01:~# journalctl -xe -u docker