Skip to content

Instantly share code, notes, and snippets.

@NiceRath
NiceRath / sendmail.py
Created January 21, 2025 17:01
Python3 sendmail cli with attachment
#!/usr/bin/env python3
import smtplib
from email.message import EmailMessage
from pathlib import Path
from os.path import basename
from argparse import ArgumentParser
REQUIRE_FROM_DOMAIN = '@test.com'
@NiceRath
NiceRath / mssql-agent-job-monitoring.txt
Created December 22, 2024 08:31
How to Monitor MSSQL Agent-Jobs
# discover all existing agent-jobs
SELECT name, step_name, jobs.job_id FROM msdb.dbo.sysjobsteps job_steps INNER JOIN msdb.dbo.sysjobs jobs ON jobs.job_id = job_steps.job_id
# get status for each job
SELECT subsystem, database_name, command, last_run_outcome, last_run_duration, last_run_date, last_run_time FROM msdb.dbo.sysjobsteps WHERE step_name = '{#STEP_NAME}' AND job_id = '{#JOB_ID}'
# check the status and trigger if not ok
## json query: $..last_run_outcome.first()
## error if last_run_outcome=0
@NiceRath
NiceRath / pve-shutdown-all-vms-cts.sh
Last active December 21, 2024 09:13
Proxmox - Shutdown all VMs and Containers
#!/bin/bash
vms="$(qm list | sed 's|^\s*||g' | cut -d ' ' -f1 | tail -n +2)"
for vm in $vms
do
echo "Shutdown vm $vm"
qm shutdown "$vm"
done
cts="$(pct list | sed 's|^\s*||g' | cut -d ' ' -f1 | tail -n +2)"
@NiceRath
NiceRath / windows-rds-temp-user-fw-rule-cleanup.ps1
Last active October 5, 2024 10:09
Windows RDS - Script to gracefully reboot the server (notify users)
# Task Scheduler
# General
# Use local service-user of SYSTEM
# Enable 'Run whether user is logged in or not'
# Enable 'Do not store password'
# Enable 'Run with highest privileges'
#
# Action
# Program: C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe
# Arguments: -File C:\scripts\GracefulReboot.ps1
@NiceRath
NiceRath / windows-rds-temp-user-fw-rule-cleanup.ps1
Last active October 5, 2024 10:06
Windows RDS - Script to scheduled remove temporary user-firewall-rules
# Task Scheduler
# General
# Select user SYSTEM (admin user will not work correctly)
# Enable 'Run with highest privileges'
#
# Action
# Program: C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe
# Arguments: -File C:\scripts\RemoveUserFWRules.ps1
# NOTE: to get the rule-names you need to execute 'Get-NetFirewallRule' as SYSTEM-USER - some rules have other display-names in that context..
@NiceRath
NiceRath / windows-rds-temp-profile-cleanup.ps1
Last active October 5, 2024 10:05
Windows RDS - Script to scheduled clean-up temporary user profiles
# Task Scheduler
# General
# Use local service-user of SYSTEM
# Enable 'Run whether user is logged in or not'
# Enable 'Do not store password'
# Enable 'Run with highest privileges'
#
# Action
# Program: C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe
# Arguments: -File C:\scripts\rds\RemoveTmpProfiles.ps1
@NiceRath
NiceRath / ssl-validate.sh
Last active October 14, 2024 20:26
Script to validate certificate of service
#!/bin/bash
if [ -z "$1" ]
then
echo 'Provide the target hostname!'
exit 1
fi
TARGET="$1"
@NiceRath
NiceRath / ssl-ocsp-check.sh
Created September 30, 2024 15:33
Script to check if website has OCSP enabled or issues with it
#!/bin/bash
if [ -z "$1" ]
then
echo 'Provide a hostname of a website to check!'
exit 1
fi
if [ -z "$2" ]
then
@NiceRath
NiceRath / port_check.py
Created September 4, 2024 10:49
Python3 Port Check Script
#!/usr/bin/env python3
from sys import argv as sys_argv
from socket import socket, AF_INET, AF_INET6, SOCK_STREAM
if len(sys_argv) < 3:
raise ValueError("""
You need to provide two arguments:
1 > Target IP
2 > Target port (only TCP)
@NiceRath
NiceRath / ansible-decrypt-vault-pipe-to-parent-process.sh
Last active August 27, 2024 13:48
Ansible - Decrypt Vault and Pipe output to parent process
# this can be useful in CI environments if you need to process config or secrets and pipe them to the parent process in a secure manner
# example file: secrets.yml
> my_secret1: !vault |
> $ANSIBLE_VAULT;1.1;AES256
> ...
> service_xyz: !vault |
> $ANSIBLE_VAULT;1.1;AES256
> ...