Below are some of the Linux Automation Scripts I wrote in the Bash Coding Language
#!/usr/bin/env bash
########################################################################
# Script Name: BackUp.sh
#
# Description: Script to automatically backup the files and directories
# located in the users home directory
# Usage: To back up the linux system in the case the system crashes that
# way there is a backup
#
# Author: John Wilson
# Date: 08 Feb 2023
########################################################################
#this line grabs the current user information to assist in naming the file
user=$(whoami)
#this line names the backup file
fileName=$user-backUp
#this line grabs the current date (year, month, day) and time (hour, minutes, seconds) of th computer
dateInfo=$(date +%Y.%m.%d-%H.%M.%S)
#this line maps where the system backup information is located
dirLocation=/var/backups/
#this line maps what to backup.
homeDirLoc=/home/kali/
#this line creates a backup file in the /var/backups location and uses the variables myMIDAS and dateInfo.
tarFile=$dirLocation$fileName-$dateInfo'.tar'
#this line grabs the file information from the current user home location
input=/home/$user
echo "#######################################################################################################"
echo "#######################################################################################################"
#this line lets the user know what the program is doing and shows the name of the backup file and location
echo "Backup file is being created and named: $tarFile and located at the directory: $dirLocation"
echo "#######################################################################################################"
echo "#######################################################################################################"
#this line is the command that begins the backup process
sudo tar -cpvzf $tarFile $homeDirLoc -P
#this line compressess the file
sudo gzip $tarFile
#this function provides information of the total number of files for a given directory.
function total_files () {
find "$1" -type f | wc -l
}
#this function provides the total number of directories for a given directory
function total_directories () {
find "$1" -type d | wc -l
}
echo "#######################################################################################################"
echo "#######################################################################################################"
#this line lets the user know the file was created sucessfully.
echo "Backup file has been sucessfully created in: $dirLocation"
echo "The Backup file that was backedup during this session is name $tarFile"
echo -n 'Total files included in the backup are:'
total_files "$input"
echo -n 'Total directories included in the backup are:'
total_directories "$input"
echo "This is the end of the backup program."
echo "END OF LINE"
echo "#######################################################################################################"
echo "#######################################################################################################"
#!/bin/bash
##############################################################
# Script Name: AutoUpdate.sh
#
# Description: Script to automatically update the system
#
# Usage: Script to automatically update the system
#
# Author: John Wilson
# Date: 11 Nov 2022
##############################################################
exit_status() {
if [ $? -eq 0 ]
then
echo
echo "-----------------------------------------"
echo "* Command Execution Was Successful. *"
echo "-----------------------------------------"
echo
else
echo
echo "-------------------------------------------------------"
echo " [Error] Process Command Execution Has Failed! "
echo "-------------------------------------------------------"
echo
read -p "The last command has exited with an error. Exit script? (yes/no)" answer
if [ "$answer" == "yes" ]
then
exit 1
fi
fi
}
#command to begin updating system
start () {
echo -e "=============================\n"
echo -e " ====> Updating System <====\n"
echo -e " ====> Please Wait <====\n"
echo -e " =====================\n"
echo -e " ===================\n"
echo -e " =================\n"
}
#command to update the system
upgrade() {
sudo apt update;
exit_status
#command to upgrade the system
sudo apt upgrade -y;
exit_status
}
#command to cleanup (remove old files)
cleanUp() {
sudo apt autoremove -y;
sxit-status
}
exitUpdate() {
echo -e "\n=========================================\n"
echo -e " ====> Completed Updating System <====\n"
echo -e " ====> Now get back to work <====\n"
echo -e " ====> END OF LINE <====\n"
echo -e " =====================\n"
echo -e " ===================\n"
echo -e " =================\n"
echo -e " ===============\n"
echo -e " =============\n"
echo -e " ===========\n"
exit
}
#calls the functions
start
upgrade
cleanUp
exitUpdate
#!/usr/bin/env bash
##############################################################
# Script Name: add_local_User.sh
#
# Description: Script to automatically create a user in Linux/
# Unix Machines
#
# Usage: Script to automatically update the system
#
# Author: John Wilson
# Date: 11 Nov 2022
##############################################################
if [[ "${UID}" -ne 0 ]]
then
echo "The script is not run as root"
exit 1
fi
# Get the username (login)
read -p "Enter the username: " USER_NAME
# Get the real name and contents for the description
read -p "Enter the real name: " COMMENT
# Get the password
read -p "Enter the password: " PASSWORD
# Create the user with password
useradd -c "${COMMENT}" -m ${USER_NAME}
# Check to see if the useradd command succeeded
if [[ "${?}" -ne 0 ]]
then
echo "User add command failed"
exit 1
fi
# Set the password
echo ${PASSWORD} | passwd --stdin ${USER_NAME}
# Check to see if password command succeeded
if [[ "${?}" -ne 0 ]]
then
echo "Password command failed"
exit 1
fi
# Force password to change on its first login
passwd -e ${USER_NAME}
# Display username, password and host where the user was created
echo
echo 'Username:'
echo "${USER_NAME}"
echo
echo 'Password:'
echo "${PASSWORD}"
echo
echo 'Hostname'
echo "${HOSTNAME}"
exit 0
#!/bin/bash/env bash
##############################################################
# Script Name: armitage.sh
#
# Description: Script to automatically run Armitage program
#
# Usage: run the Armitage program
#
# Author: John Wilson
# Date: 04 Feb 2023
##############################################################
echo "welcome to the Armitage program starter thingy"
echo "Please wait while the system starts the programs and all those related"
#starting PostgreSQL program
echo "==================================================="
echo " Starting the PostgreSQL service"
echo "==================================================="
#command to start the PostgreSQL service
sudo service postgresql start;
echo "To check if the status of the PostgreSQL service go to a terminal and type in "service PostgreSQL status" or "/sbin/service PostgreSQL status""
#command that starts the Metasploit database
msfdb init;
sudo systemctl enable postgresql;
sudo systemctl stop postgresql;
sudo systemctl start postgresql;
#command that starts the Armitage program
sudo armitage;
echo "Armitage is running; hopefully"