Welcome to my Bash Script Repository! Each script in this repository has been crafted to address specific needs and can be customized to suit your requirements. Whether you need to monitor system resources, manage user accounts, or perform routine maintenance tasks, this repository offers a wide range of practical examples that demonstrate the flexibility and capabilities of Bash scripting in Linux environments.
Feel free to explore, modify, and utilize these scripts to improve your productivity, optimize your workflows, and expand your understanding of what can be accomplished with Bash scripts. Happy scripting!
backup.sh
: This script creates a compressed backup of a specified source directory and
saves it in a backup directory with a timestamp in the filename.
To run:
chmod +x script_name.sh
Execute:
./script_name.sh
sys_info
: This script displays a summary of system information, including the hostname,
uptime, free memory, disk usage percentage, and CPU usage percentage. It
utilizes various Linux commands such as hostname, uptime, free, df, and top,
along with text processing utilities like grep and awk, to extract and display
the relevant information.
To run:
chmod +x script_name.sh
Execute:
./script_name.sh
new_user
: This script creates a new user account on a Linux system with the provided
username and password. It checks if the correct number of arguments (2) is
provided, and if not, it displays the proper usage and exits. If the correct
number of arguments is supplied, the script proceeds to create the user with the
useradd command and sets the account password using chpasswd. Finally, it
confirms the user creation with a success message.
To run:
chmod +x script_name.sh
Execute:
./script_name.sh
web_monitor.sh
: This script monitors the availability of a list of websites and sends an email
notification if any of them are down. It uses curl to check the HTTP status code
for each website and writes the status to a temporary file if the code is not
200 (OK). If any websites are found to be down, the script sends an email with
the details using the mail command. Finally, it cleans up the temporary file
after processing.
To run:
- Make sure to replace the WEBSITES_LIST variable with the list of websites you want to monitor.
- Update the EMAIL_TO variable with your email address where you want to receive notifications.
- Make the script executable:
chmod +x website_monitor.sh
- Execute the script:
./web_monitor.sh
For continuous monitoring, you can schedule this script to run periodically using cron. For example, to run the script every 5 minutes, you can add the following line to your crontab:
*/5 * * * * /path/to/website_monitor.sh
To edit your crontab, run:
crontab -e
If you would like to add any extra features to the optimisation simulation, feel free to fork and create a pull request. Thank you!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Erol Gelbul - Website
Project Link: Bash Scripts