Skip to content

Instantly share code, notes, and snippets.

@valtoni
valtoni / count.awk
Created June 6, 2023 11:31
Group By Count Using awk
find . -name 'message-*.csv' -exec wc -l {} \; | awk -F'[[:space:]-]' '
NR == 1 { print; next }
{
id = $3;
qty = $1;
if (qty < 289) {
reads[id] = qty;
}
} END {
for (r in reads) {
#!/bin/bash
if [ $(dpkg-query -W -f='${Status}' socat 2>/dev/null | grep -c "ok installed") -eq 0 ]; then
apt-get install socat;
else
echo "*** Package socat already installed"
fi
MAPPINGS=("1231,10.0.12.1,123" "1232,10.0.12.2,123")
@valtoni
valtoni / mysql_used_memory.sql
Created January 3, 2023 13:27
Show MySQL 8.0.x used memory
CREATE DEFINER=`valtoni`@`%` PROCEDURE `get_memory`()
BEGIN
DECLARE var VARCHAR(64);
DECLARE val VARCHAR(1024);
DECLARE done INT;
#Variables for storing calculations
DECLARE GLOBAL_SUM DOUBLE;
DECLARE PER_THREAD_SUM DOUBLE;
DT = data.table(A=c("Peter Parker", "Bruce Wayne", "Barry Allen", "Diana", "Clark Kent"),
B=c("Spiderman", "Batman", "Flash", "Wonderwoman", "Superman"),
C=c("Dr. Octopus", "Joker", "Magenta", "Baroness Paula von Gunther", "Lex Luthor"))
d1 <- copy(DT)
d2 <- copy(DT)
d3 <- copy(DT)
setorder(d1, A)
@valtoni
valtoni / aws_orphan_snapshots.py
Created July 4, 2022 22:17
AWS List of snapshots without AMI (Boto3)
import boto3
from boto3 import ec2
import datetime
import re
from datetime import date
def is_attached(image, snapshot):
for mapping in image['BlockDeviceMappings']:
# Is it a machine ephemeral device?
@valtoni
valtoni / find_executable.PS1
Created November 23, 2021 12:59
Powershell find file in path
:: simple version
$env:path.Split(';') | gci -Filter application.exe
:: expanded version
$env:path.Split(';') | select -Unique | ? {$_ -and (test-path $_)} | gci -Filter application.exe
@valtoni
valtoni / move_structure.ps1
Created October 10, 2021 13:15
Move founded files with structure (PowerShell)
$OldBase="C:\src\main\java"
$NewBase="C:\src\main\resources"
$HibernateFiles=Get-ChildItem $OldBase -Include *.xml -Recurse
foreach ($file in $HibernateFiles) {
Write-Host $file.FullName
$Directory=$file.Directory.ToString()
$Directory=$Directory.replace($OldBase, $NewBase)
$OldFile=$file.FullName
$NewFile=$OldFile.replace($OldBase, $NewBase)
New-Item $Directory -ItemType Directory -ea 0
#!/bin/bash
stats=””
echo "% user"
echo "============"
# collect the data
for user in `ps aux | grep -v COMMAND | awk '{print $1}' | sort -u`
do
stats="$stats\n`ps aux | egrep ^$user | awk 'BEGIN{total=0}; \
@valtoni
valtoni / linux_redirect_syslog.sh
Created March 22, 2021 10:57
Output log to syslog in linux (init.d scripts)
# Original: https://serverfault.com/questions/341919/how-to-find-error-messages-from-linux-init-d-rc-d-scripts
# Reference: http://urbanautomaton.com/blog/2014/09/09/redirecting-bash-script-output-to-syslog/
exec 1> >(logger -s -t $(basename $0)) 2>&1
cat >/tmp/demo-space-separated.sh <<'EOF'
#!/bin/bash
POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-e|--extension)