Skip to content

Instantly share code, notes, and snippets.

View andy722's full-sized avatar

Andy Belsky andy722

  • as a private person here
  • Russia, Novosibirsk
View GitHub Profile
#
# Remove `line` from `array`.
# If `line` occurs multiple times, only a single occurrence is removed.
#
new_array=()
skipped=0
for value in "${array[@]}"; do
if [ "$value" == "$line" ] && [ $skipped -eq 0 ]; then
skipped=1
else
@andy722
andy722 / uuid.groovy
Created September 24, 2021 10:38
UUIDv4 with custom payload
import com.google.common.base.Preconditions
import java.nio.ByteBuffer
import static com.google.common.base.Preconditions.checkState
// See java.util.UUID#randomUUID
UUID generateV4(byte[] src) {
checkState src.length <= 14
pvcreate /dev/sdc
vgcreate vgstore /dev/sdc
lvcreate -l 100%VG -n biggfsbrick vgstore
mkfs.xfs /dev/vgstore/biggfsbrick
echo '/dev/vgstore/biggfsbrick /export/biggfsbrick/ xfs defaults 1 2' >>/etc/fstab
mkdir /export/biggfsbrick
mount /export/biggfsbrick
gluster volume create big-repl-store replica 3 transport tcp app-01:/export/biggfsbrick/repl-store app-02:/export/biggfsbrick/repl-store app-03:/export/biggfsbrick/repl-store
@andy722
andy722 / gist:accf0dfa91bb4b8c7d0e0069bafa9f15
Created October 28, 2020 11:30
MongoDB: list collection files
db.adminCommand( { listDatabases: 1 } ).databases.forEach(function (otherDb) {
var siblingDb = db.getSiblingDB(otherDb.name);
siblingDb.getCollectionInfos().forEach(function (coll) {
print(otherDb.name + '.' + coll.name + '\t->\t' + siblingDb.getCollection(coll.name).stats().wiredTiger.uri)
})
})
@andy722
andy722 / delete-user.sh
Created April 22, 2020 16:05
ansible / delete user
ansible swarm_dtln -b -m user -a "name=USERNAME state=absent remove=yes force=true"
ansible swarm_dtln -b -m replace -a 'backup=yes dest=/etc/ssh/sshd_config regexp=^(AllowUsers.*)\\b(USERNAME)\\b(.*)$ replace=\\1\\3'
ansible swarm_dtln -b -m replace -a 'backup=yes dest=/etc/ssh/sshd_config regexp=^(Match.*)\\b(USERNAME\,)\\b(.*)$ replace=\\1\\3'
ansible swarm_dtln -b -m service -a "name=sshd state=restarted"
@andy722
andy722 / gist:ca53f60d55c4a493a3d51a5b1b52fcfd
Created January 28, 2020 19:44
Determine which SSH public key was used for access
# /var/log/secure:
...
Jan 28 10:47:22 web01 sshd[17503]: Accepted publickey for <myuser> from <myip> port 56325 ssh2: RSA SHA256:<checksum>
...
# Compute fingerprints from authorized keys.
# Match w/ the one in `secure' log.
# ssh-keygen -lf ~myuser/.ssh/authorized_keys
@andy722
andy722 / tsr_export.sh
Created April 16, 2018 15:31
Quick & dirty script to export YouTrack time spent reports filtered by user
#!/usr/bin/env bash
export YT_COOKIE="" # Get this from browser cookies, looks like "pp71vwl46b0t6ftkmo6bt5xt"
export REPORT_ID="" # Report ID, get this from URI of report page. Looks like 104-110
export USER="" # YouTrack username to filter by.
export YT_HOST="" # YouTrack host, like https://youtrack.mycompany.com.
####################################################################################################
@andy722
andy722 / auto-dump.sh
Created September 5, 2016 06:19
Dumps JVM application stack in case CPU load exceeds allowed threshold
#!/bin/bash
#
# Dumps JVM application stack in case CPU load exceeds allowed threshold.
#
# This script is supposed to be called regularly, e.g. cron entry:
#
# */5 * * * * /opt/apps/stack-dumps/auto-dump.sh
#
@andy722
andy722 / JmxMonitor.groovy
Created September 5, 2016 06:13
Simple monitoring & alert notification script: track JMX properties and send email if values increase
import org.apache.commons.mail.HtmlEmail
import javax.management.remote.JMXConnector
import javax.management.remote.JMXConnectorFactory
import javax.management.remote.JMXServiceURL
// @Grab(group = 'org.apache.commons', module = 'commons-email', version = '1.3.2', transitive = true)
//
@andy722
andy722 / JmxCall.groovy
Last active September 8, 2020 10:50
Simple script to call JMX methods
import javax.management.MBeanServerConnection
import javax.management.ObjectName
import javax.management.remote.JMXConnector
import javax.management.remote.JMXConnectorFactory
import javax.management.remote.JMXServiceURL
final findBean = { MBeanServerConnection server,
String beanName ->
server.queryMBeans(null, null).find { it.name.serializedNameString.contains beanName }
}