Skip to content

Instantly share code, notes, and snippets.

@Lirt
Lirt / lines-from-pattern.sh
Last active May 4, 2018 11:00
Sed examples
# Print lines from line which match pattern to end of file
pattern=""
sed -n "/$pattern/,$ p" file.txt
# Example
pattern="mnop"
str="$(echo -e "abcd\nefgh\nijkl\nmnop\nqrst\nuvw\nxyz" | sed -n "/$pattern/,$ p")"
echo $str
# Remove lines before line LINE including LINE
@Lirt
Lirt / bash-options.sh
Last active March 22, 2017 15:19
Bash specific function and syntax cheatsheet
# Exit on error
set -e
# Exit if variable was not set
set -u
# Exit when command in pipe fails
set -o pipefail
# Print every command executed with variable interpolation
set -x
@Lirt
Lirt / interfaces.sh
Last active August 8, 2023 07:15
Useful things with linux networking
# Debian default gateway /etc/network/interfaces
up route add default gw 62.210.123.1
# Force interface eth0 to 10 Gbit speed
ethtool -s <device> speed 10000 duplex full autoneg off
# For the setting to be persistent across reboots
# edit "/etc/udev/rules.d/71-ethtool.rules"ff and
# add "SUBSYSTEM=="net", ACTION=="add", NAME=="<device>", RUN+="/sbin/ethtool <device> -s speed 100 duplex full autoneg off"
@Lirt
Lirt / images.sh
Last active December 11, 2017 08:31 — forked from smoser/gist:4756561
boot a cloud image in kvm
## Install a necessary packages
sudo apt-get install kvm cloud-utils genisoimage
modprobe kvm && modprobe kvm-intel
## URL to most recent cloud image of 16.04
img_url="http://cloud-images.ubuntu.com/server/releases/16.04/release"
img_url="${img_url}/ubuntu-16.04-server-cloudimg-amd64-disk1.img"
## download the image
wget $img_url -O disk.img.dist
@Lirt
Lirt / digital-ocean.sh
Last active August 30, 2018 19:15
Phoronix test suite, Google PerfKit
# Install doctl
# https://github.com/digitalocean/doctl
cd /tmp && wget -qO - https://github.com/digitalocean/doctl/releases/download/v1.6.0/doctl-1.6.0-linux-amd64.tar.gz | tar -xzvf -
sudo mv /tmp/doctl /usr/local/bin/
# Install elasticsearch package for pushing data to ES
sudo pip install elasticsearch
ES_URI=''
# Setup credentials and access to DO
@Lirt
Lirt / vbox-mod-sign.sh
Last active February 3, 2019 10:54
Sign VirtualBox kernel modules to run with SecureBoot
#!/usr/bin/env bash
#
# Script for guide:
# https://gorka.eguileor.com/vbox-vmware-in-secureboot-linux-2016-update/
#
# Verification:
# dmesg | grep "EFI:.*cert.*${cert_name}"
#
set -eu
set -o pipefail
+-----------------+------------+-------------+
| ip_address | state_code | login_count |
+-----------------+------------+-------------+
| 41.63.176.___ | AO | 8 |
| 200.80.227.___ | AR | 41 |
| 120.146.134.___ | AU | 18 |
| 79.132.239.___ | BE | 15 |
| 184.149.27.___ | CA | 1 |
| 24.37.20.___ | CA | 13 |
| 70.28.77.___ | CA | 21 |
ip_address state_code login_count
41.63.176.___ AO 8
200.80.227.___ AR 41
120.146.134.___ AU 18
79.132.239.___ BE 15
184.149.27.___ CA 1
24.37.20.___ CA 13
70.28.77.___ CA 21
70.25.65.___ CA 23
IPs Country
214 US
28 GB
17 IT
15 ES
15 CA
8 DE
4 IE
+--------+
| 214 US |
| 28 GB |
| 17 IT |
| 15 ES |
| 15 CA |
| 8 DE |
| 4 IE |
| 3 KW |
| 3 IN |