Skip to content

Instantly share code, notes, and snippets.

View polsala's full-sized avatar
💭
https://www.youtube.com/watch?v=ShtIRODxvmc

PSala polsala

💭
https://www.youtube.com/watch?v=ShtIRODxvmc
  • GISCE-TI
  • Girona
View GitHub Profile
#!/bin/bash
# Create necessary directories if they do not exist
mkdir -p /opt/node_exporter/metrics_folder/
mkdir -p /opt/node_exporter/ram_consumption/
# Create the script file with the given content
cat << 'EOF' > /opt/node_exporter/ram_consumption/ram_p.sh
#!/bin/bash
#!/bin/bash
# Conexión a MongoDB
DATABASE="tuBaseDeDatos"
COLLECTION="tg_profile"
MONGO_HOST="localhost"
MONGO_PORT="27017"
# Obtener el mínimo y máximo _id
MIN_ID=$(mongo --quiet --host $MONGO_HOST --port $MONGO_PORT $DATABASE --eval "printjson(db.$COLLECTION.find().sort({_id: 1}).limit(1).toArray()[0]._id)")
@polsala
polsala / check_restapi_log_calls.sh
Created April 18, 2024 13:03
Revisar las llamadas y numero de veces de cada llamada para los logs de la restapi en un intervalo de tiempo
#!/bin/bash
#./check_restapi_log_calls.sh /home/erp/var/log/restapi.log 'Apr 18 12:11:00 2024' 'Apr 18 12:25:00 2024'
# Input variables
file_path=$1
start_date="$2"
end_date="$3"
# Convertir las fechas de inicio y fin a formato 'date' para comparar
start_timestamp=$(date -d "$start_date" '+%s')
end_timestamp=$(date -d "$end_date" '+%s')
@polsala
polsala / clean_redis_keys.py
Created July 17, 2023 11:48
Clean not used redis keys since x seconds
def clean_idle_redis_keys(redis_host='192.168.0.4', redis_port=6379, db=0, startswithkey='rq', idletime=604800):
import redis
from tqdm import tqdm
r = redis.StrictRedis(host=redis_host, port=redis_port, db=db)
for key in tqdm(r.scan_iter("*")):
idle = r.object("idletime", key)
# idle time is in seconds.
if idle > idletime and key.startswith(startswithkey):
print("Deleting {}".format(key))
r.delete(key)
@polsala
polsala / download_latest_release_assets.sh
Created June 14, 2023 07:12
Download assets from last release of private/public github repo [only custom assets]
#!/bin/bash
export GITHUB_TOKEN=******************************
export OWNER=********
export REPO=******
EE=$(curl -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer $GITHUB_TOKEN" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/$OWNER/$REPO/releases/latest | grep https://api.github.com/repos/$OWNER/$REPO/releases/assets/. | cut -d : -f 2,3 | tr -d \" | tr -d ,)
for URL in $EE
do
echo $URL
name=$(curl -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer $GITHUB_TOKEN" -H "X-GitHub-Api-Version: 2022-11-28" $URL | grep '"name":.' | cut -d : -f 2,3 | tr -d \" | tr -d ,)