Skip to content

Instantly share code, notes, and snippets.

@filipnet
filipnet / ADDS_Checks.ps1
Created February 15, 2025 18:10
Active Directory Domain Services (AD DS) Health and User Reports.
<#
.SYNOPSIS
Active Directory Domain Services (AD DS) Health and User Reports.
.DESCRIPTION
This script performs various AD DS health checks, DNS diagnostics, replication status checks,
and extracts domain admin and password expiry reports.
.PARAMETER LogPath
Directory to store log and report files (default: C:\ADDS_Checks).
@filipnet
filipnet / Get-RebootEvents.ps1
Created February 15, 2025 10:35
PowerShell script saved as Get-RebootEvents.ps1 that retrieves system shutdown and reboot events for both single and multiple servers.
<#
.SYNOPSIS
Tracks system shutdown and reboot events.
.DESCRIPTION
This script retrieves event ID 1074 from the System log to identify shutdown and reboot events.
It can generate reports for a single server or multiple servers.
.PARAMETER Computer
The target computer name (default: local computer).
@filipnet
filipnet / Get-LogonHistory.ps1
Created February 15, 2025 10:25
Retrieves logon (7001) and logoff (7002) events from the system event log of a local or remote computer Displays the results in a formatted table Allows filtering based on a specified time period (default: 10 days)
<#
.SYNOPSIS
Retrieves logon and logoff events from a local or remote computer.
.DESCRIPTION
This script queries the Windows Event Log for logon (7001) and logoff (7002) events.
The results are sorted in descending order by date and displayed in a table.
.PARAMETER Computer
The target computer name (Default: Local computer).
@filipnet
filipnet / maildir_report.sh
Created February 13, 2025 07:11
This script extracts all home directories from /etc/passwd, regardless of their location. It then checks if each home directory contains a Maildir folder. If a Maildir exists, the script displays the total size of the home directory along with the size of the Maildir and its subdirectories.
#!/bin/bash
# Get all home directories from /etc/passwd
HOMEDIRS=$(awk -F: '$6 !~ /^$/ {print $6}' /etc/passwd | sort -u)
# Loop through each home directory
for dir in $HOMEDIRS; do
MAILDIR="$dir/Maildir"
# Check if the Maildir exists
@filipnet
filipnet / check_service_syntax.sh
Last active December 11, 2024 21:16
This script checks the configuration syntax of various services on a Linux system. It executes predefined check commands for each service, verifies the output, and reports whether the service configuration is valid or not. The script supports common services like Nginx, Apache, SSH, and others. The script is easily expandable—services can be add…
#!/bin/bash
# ===========================
# Service Configuration
# ===========================
# Format: "<Service Name>;<Check Command>;<Expected String>"
SERVICES=(
"apache;apachectl configtest;Syntax OK"
#"haproxy;haproxy -c -f /etc/haproxy/haproxy.cfg;Configuration file is valid"
"nginx;nginx -t;syntax is ok"
@filipnet
filipnet / generate-pkg-report.sh
Created November 17, 2024 17:48
This script checks for available system updates, reports if a reboot is required, lists enabled repositories, and sends an email notification to specified recipients with the update details.
#!/bin/bash
# Configuration: Define recipients (space-separated emails)
RECIPIENTS="[email protected]"
# Constants
DASHES="##############################"
# Function: Check for updates
check_updates() {
@filipnet
filipnet / set_temporary_password.sh
Created November 1, 2024 11:51
The set_temporary_password.sh script is designed to set a temporary password for a specified user account on a Linux system. The password will be valid for a predefined duration, after which it will expire. Users can define parameters such as the username, expiration time in minutes, and the desired password length. The script also verifies the …
#!/bin/bash
# Define parameters at the top
USERNAME="max.mustermann" # Username for which to set the password
USER_PASSWORD="" # Leave empty to generate a password automatically
EXPIRATION_MINUTES=60 # Password expiration time in minutes
PASSWORD_LENGTH=6 # Length of the generated password
USE_SPECIAL=false # Set to false to exclude special characters in the password
# Function to check if the user exists and provide output
@filipnet
filipnet / set_homedir_permissions.sh
Created October 31, 2024 20:26
This Bash script scans the system's /etc/passwd file to list user accounts with their real names, associated groups, and home directories. It allows filtering based on home directory names and user groups. Additionally, it can modify the ownership and permissions of home directories recursively.
#!/bin/bash
# Filter parameter for the home directory
filter_string="home"
# Optional filter parameter for the user group (default is empty)
group_filter="users"
# Default dry-run flag (true)
dry_run=true
# Function to display usage information
@filipnet
filipnet / sync_remote_to_local.sh
Created October 31, 2024 19:55
This Bash script automates the process of synchronizing files from a remote server to a local directory using rsync. It includes options for preserving file permissions, ownership, and group ownership, while also providing options for compression, deletion of old files, and recursive copying of directories.
#!/bin/bash
# Parameters
REMOTE_PATH="/home" # Source path on the remote server
LOCAL_PATH="/mnt/sdb/" # Destination path on the local system "DO NOT REPEAT" destination folder
CERT_PATH="/root/id_rsa_root_hostname.priv.crt" # Path to the SSH certificate
REMOTE_SERVER="host.domain.com" # Hostname or IP address of the remote server
CHECK_MODE="--dry-run" # Use "--dry-run" for a dry run, leave empty for normal operation
# File permission options
@filipnet
filipnet / fix_deprecated_mysql_tools.sh
Last active February 16, 2025 10:25
This script updates the deprecated MySQL commands used in the automysqlbackup tool to their MariaDB equivalents. It replaces mysqldump with mariadb-dump, mysqlshow with mariadb-show, and mysql with mariadb, ensuring compatibility with newer MariaDB installations. A timestamped backup of the original file is created before applying the changes, p…
#!/bin/bash
# Script to update deprecated MySQL commands in the automysqlbackup file.
# The automysqlbackup project can be found at: https://sourceforge.net/projects/automysqlbackup/
#
# The following warnings have been observed when using automysqlbackup:
#
# mysqldump: Deprecated program name. It will be removed in a future release, use '/usr/bin/mariadb-dump' instead
# mysqlshow: Deprecated program name. It will be removed in a future release, use '/usr/bin/mariadb-show' instead
# mysql: Deprecated program name. It will be removed in a future release, use '/usr/bin/mariadb' instead