Bash Projects
I've developed a simple Bash script to display the current time in a continuous loop, with the flexibility to customize the color of the clock.
Features:
-
Color Customization: The script allows for the clock to be displayed in different colors by using ANSI escape codes for red, green, and blue.
-
Real-Time Update: The script continuously updates the current time every second, providing a real-time clock display.
I've created a Bash script that performs basic arithmetic operations (+, -, *, /) based on user input and handles various edge cases to ensure robustness and accuracy.
Features:
-
User Input: The script prompts the user to enter two numbers and an arithmetic operator separated by spaces.
-
Edge Cases: The script includes checks for: Missing inputs. Division by zero. Invalid arithmetic operators.
-
Arithmetic Operations: The case statement handles the four basic arithmetic operations: Addition: Directly adds the two numbers. Subtraction: Subtracts the smaller number from the larger one to avoid negative results. Multiplication: Multiplies the two numbers. Division: Checks for zero to avoid division by zero and divides the larger number by the smaller one.
This script is designed to monitor the memory usage of a system and send an email alert to a user when the memory usage exceeds a specified threshold.
Features:
-
When this script is run it retrieves the current memory usage in gigabytes, providing up-to-date information on system resource consumption.
-
The script prompts the user to enter their email address, ensuring that alerts are sent to the correct recipient.
-
If the memory usage exceeds the threshold (7 GB), the script sends an automated email to the user with a warning message and the current memory usage details.
This Bash script is designed to identify, compress, and move files larger than 20KB from a specified directory to an archive folder within the same directory.
Features:
-
Ensures the specified filepath exsist before proceeding with further operations.
-
Counts the number of files exceeding the 20KB size limit.
-
Checks for the existence of an archive directory within the specified path and creates it if it does not exist.
-
I used a Print function to encapsulate and display the list of files that need to be compressed, enhancing code readability and organization.
-
Compresses files larger than 20KB using gzip and moves the compressed files to the archive directory.
-
Provides informative messages to the user about the operations being performed, such as the creation of the archive directory, the list of large files, and the status of file compression and movement.
This Bash script is intended to automate the creation of a new user account on Linux OS-based system.
Features:
-
The script checks if it is being run by the root user. If not, it exits with an appropriate message. This ensures that the script has the necessary permissions to create new user accounts and modify system settings.
-
The script requires at least one argument (the username). If no arguments are provided, it displays a usage message and exits, guiding the user on how to correctly run the script.
-
Captures the username from the first argument and shifts the positional parameters to process any additional comments. It then prints the username and any additional comments.
-
Generates a unique password using the current date and time in nanoseconds, ensuring a high degree of uniqueness and security.
-
Creates a new user with the specified username and sets the default shell to /bin/bash. The script checks if the user creation was successful and provides appropriate response.
-
Sets the generated password for the new user account. The script verifies if the password was set correctly and provides feedback.
-
The script prompts the user to enter a new personal password to replace the default generated one. The script uses read -sp to prompt for the new password securely, without echoing the input on the terminal. Furthermore, it ensures that this new password is set correctly and provides feedback.
-
The script provides clear and informative outputs at each step of the process, including success and error messages. This helps the user understand what is happening and any issues that may occur.
-
Displays the final set of information, including the username and the newly set password. This ensures the user has all the necessary details to log in.