Sobes.tech
Junior

What scripts have you written in Bash?

sobes.tech AI

Answer from AI

  • Scripts for automating application deployment (installing dependencies, configuration).
  • Scripts for data backup and recovery.
  • Scripts for monitoring server status (CPU usage, memory, disk) and sending notifications.
  • Scripts for managing users and access rights.
  • Scripts for automating the building and deployment of Docker images.
  • Scripts for performing routine system administration tasks (updating packages, cleaning logs).
  • Scripts for interacting with APIs of various services (e.g., cloud providers).
  • Scripts for testing network connectivity and performance.
  • Scripts for synchronizing files and directories between servers.
  • Scripts for parsing log files and extracting useful information.

Example of a simple backup script:

#!/bin/bash

# Directory for backups
BACKUP_DIR="/backups/app_data"
# Directory to back up
SOURCE_DIR="/path/to/your/app_data"
# Backup file name
TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
BACKUP_FILE="$BACKUP_DIR/app_data_$TIMESTAMP.tar.gz"

# Create backup directory if it doesn't exist
mkdir -p "$BACKUP_DIR"

# Create archive
tar -czf "$BACKUP_FILE" "$SOURCE_DIR"

# Check if archive creation was successful
if [ $? -eq 0 ]; then
  echo "Backup created successfully: $BACKUP_FILE"
else
  echo "Error creating backup"
  exit 1
fi

# Delete old backups (e.g., older than 7 days)
find "$BACKUP_DIR" -mtime +7 -delete

exit 0