Skip to content

Latest commit

 

History

33 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bin_bradz

A collection of scripts for automating various jobs.

Scope of this repo

This repo contains mainly Bash scripts I use to automate my work.
They are developed in a quick and dirty way, so they are not intended to be high-quality code.
There are better and more usable, but longer, ways to do these tasks.

Any contribution to improve these scripts is welcome.


Collections

travel_utils

Scripts for managing data on a USB stick while traveling.

  • datasync.sh
    Run this script from your destination USB stick path. It syncs the directories listed in the file tosync.txt (absolute paths required - do not use '/' at the end if you want separate directories in the destination).

  • listModified.sh
    After returning from travel, run this script from the USB stick path.
    Provide your leave date as input in the format YYYY-MM-DD.
    The script will show which files were modified on the USB stick during your travel, so you can update the corresponding files on your desktop PC.


web_scripts

Web-oriented scripts.

  • check_url.sh
    Useful for monitoring overloaded websites to know when they become accessible.
    This script repeatedly tries to contact a specified URL (default: google.it) using curl until it succeeds.
    Each attempt is logged to a file named after the script (e.g., check_url.sh.log).
    If curl succeeds (exit code 0), it prints a success message and stops retrying.
    If it fails, it prints the exit code and a link to curl exit code documentation.
    After a successful connection, it runs an audible alert in a loop, printing "Alert running. Press CTRL+c to stop!" and beeping every second until you manually stop the script.

fs_utils

Scripts for file system management.

  • searchBigFiles.sh
    Useful for freeing up disk space by detecting the largest files.
    The script searches for files larger than 1024 MB (1 GB) in the home directory and its subdirectories (size can be changed).
    It writes the paths and sizes of these large files to /tmp/bigfiles.txt.
    For each file found, if its size exceeds 1024 MB, it logs the file and adds its size to a running total.
    It prints a dot periodically to show progress.
    At the end, it prints the total size of all large files found.
    The script prints the date at the start and end for timing reference.

Backup-sync

A set of scripts to be placed in your external backup device to sync important directories and configuration of your PC, such as:

  • A configurable directory (typically your home directory)
  • The /etc configuration directory (requires sudo privileges for rsync)
  • The list of installed packages (works for Debian-based Linux distributions)

Scripts:

  • runbackup.sh
    Performs a backup operation with pre-cleanup steps, using the variables at the top as input parameters:

    • DIRTOBKP: main directory to back up
    • TEMPDIRS: temporary directories inside DIRTOBKP to check and optionally clean
    • SCRIPTBKP: backup script to run (backupDataNinfo.sh)

    Steps:

    1. For each directory in TEMPDIRS, counts the files.
    2. If files are present, prompts the user to delete them.
    3. If the user agrees, deletes all files in that directory.
    4. After checking all temporary directories, starts the backup script (SCRIPTBKP) in the background using nohup, so it continues running even if the terminal closes. Output goes to nohup.out.
  • backupDataNinfo.sh
    Performs backup and system info collection, using the variables at the top as input parameters:

    • DIRTOBKP: directory to back up
    • AUDIOALERT: audio file to play when the backup finishes

    Steps:

    1. Backs up DIRTOBKP to the current directory using rsync, excluding the .cache folder.
    2. Backs up /etc to the current directory using rsync.
    3. If a file named nohup.out exists, renames it with a timestamp.
    4. Lists all installed packages and saves the list to a timestamped file.
    5. Plays the audio alert file (AUDIOALERT) to signal completion.
    6. Prints #END when finished.
  • rotatenohup.sh
    Rotates the nohup.out file after execution to archive the last run.


wav2mp3

Scripts for converting WAV files to MP3 and managing the process.

Requirements:

  • ffmpeg: For audio conversion from WAV to MP3.
  • zip: For compressing MP3 files.
  • tar: For creating backup archives.
  • Standard Unix tools: find, mv, ls, date, etc.

Configuration:

  • Edit config.sh to set the following variables according to your system:
    • PROJ: Project name (e.g., "TOFKAP").
    • SRCDIR: Source directory containing WAV files (e.g., "/Volumes/H2N_SD/").
    • TMPF: Temporary file for file lists (e.g., "./tempfile.txt").
    • RIFF: Audio file to play on completion (e.g., "/path/to/sound.mp3").
    • ENCSCRIPT: Path to the encoding script (e.g., "./wav2mp3.sh").
    • BZBACKUP: Backup directory for WAV files (e.g., "/media/user/USB/Drive/$PROJ").
    • CLEANUPS: Path to cleanup script (e.g., "./cleanup.sh").
    • ZIPOK: File to store zip operation status (e.g., "./zipok.txt").

Scripts:

  • config.sh
    Configuration file containing all shared variables. Source this file in other scripts.

  • wav2mp3.sh
    Converts all WAV files in the specified directory to MP3 using ffmpeg.
    Usage: ./wav2mp3.sh <directory>
    It processes both .wav and .WAV files, outputting MP3 files in the same directory.

  • process.sh
    Main script to process WAV files: searches for WAV files in SRCDIR, moves them to a dated directory, encodes them to MP3, zips the MP3s, and optionally backs up the original WAVs.
    Usage: ./process.sh [dirname]
    If no dirname is provided, it uses yesterday's date (adapts to Linux/Mac using uname).

  • cleanup.sh
    Cleans up temporary files and removes WAV files if the zip operation succeeded.
    Usage: ./cleanup.sh [dirname]
    Called automatically by process.sh.

  • main.sh
    Alternative main script with the same functionality as process.sh.
    Usage: ./main.sh [dirname]


picture_mngt

Scripts for organizing and managing photo and video files.

  • organize_foto.sh
    Organizes photos and videos from a source directory into a structured output based on date and location metadata.
    Creates hard links to avoid duplicating files, skipping identical files based on MD5 checksum.

    Requirements:

    • exiftool: For extracting EXIF metadata (date, GPS coordinates)
    • curl and jq: For reverse geocoding GPS coordinates to city/country using Nominatim API
    • md5sum: For duplicate detection (md5 on macOS, md5sum on Linux)

    Configuration:

    Usage:

    ./organize_foto.sh [-v] <SOURCE>
    
    • <SOURCE>: Path to the directory containing photos/videos to organize
    • -v: Verbose mode for detailed processing information

    Output Structure:

    <SOURCE>_Organized/
    ├── YYYY/
    │   └── MM/
    │       └── YYYYMMDD_HHMM_city_country.ext
    

    Features:

    • Extracts creation date from EXIF DateTimeOriginal (when the photo was taken), falls back to file modification time if not available
    • Retrieves GPS coordinates and reverse geocodes to city/country using OpenStreetMap Nominatim
    • Skips duplicate files based on MD5 checksum to avoid redundant organization
    • Handles filename conflicts by appending counters (_1, _2, etc.) for different files with same metadata
    • Cross-platform support for Linux and macOS
    • Progress bar with percentage in non-verbose mode
    • Respects API rate limits (1 second delay between geocoding requests)

    Example:

    ./organize_foto.sh Pictures/Vacation
    

    This creates Pictures/Vacation_Organized/ with files organized by date and location.

  • resize_jpg.sh
    Resizes JPG/JPEG images to a specified percentage of their original dimensions.
    Cross-platform support for macOS and Linux.

    Requirements:

    • ImageMagick: For image resizing (provides convert or magick command)
      • macOS: brew install imagemagick
      • Linux: sudo apt install imagemagick

    Usage:

    ./resize_jpg.sh <input.jpg> <percentage>
    
    • <input.jpg>: Path to the JPG/JPEG image file to resize
    • <percentage>: Resize percentage (positive integer, e.g., 50 for 50% of original size)

    Output: Creates a new file named <input>_resized.jpg with the resized image.

    Example:

    ./resize_jpg.sh photo.jpg 50
    

    This creates photo_resized.jpg at 50% of the original size.


About

The collection of my scripts

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages