<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Marvellous ezemba</title>
    <description>The latest articles on Forem by Marvellous ezemba (@linuxinator).</description>
    <link>https://forem.com/linuxinator</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1409659%2F685f0ca9-1888-4e07-930b-2b99167260a4.png</url>
      <title>Forem: Marvellous ezemba</title>
      <link>https://forem.com/linuxinator</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/linuxinator"/>
    <language>en</language>
    <item>
      <title>Volume Testing With Apache Jmeter On Windows.</title>
      <dc:creator>Marvellous ezemba</dc:creator>
      <pubDate>Tue, 20 Aug 2024 21:01:03 +0000</pubDate>
      <link>https://forem.com/linuxinator/volume-testing-with-apache-jmeter-on-windows-2p06</link>
      <guid>https://forem.com/linuxinator/volume-testing-with-apache-jmeter-on-windows-2p06</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0dh656ikpjyll008i6vw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0dh656ikpjyll008i6vw.png" alt="Image description" width="800" height="534"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this article, I'll be walking you through how we can perform volume testing on different applications. Before I demonstrate how we make volume testing using Jmeter, Here's my own understanding of what volume testing means and why we need to run volume testing on applications before deploying to production.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp94xtq3o0vwkj3lxucz0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp94xtq3o0vwkj3lxucz0.png" alt="Image description" width="800" height="420"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Volume testing: In a very simple term, Volume testing is designed to check how a system handles large amounts of Data. Different companies employ this method of testing to ensure that their service can manage an expected volume of data without significant degradation in performance or data loss.&lt;/p&gt;

&lt;p&gt;Why do we perform volume testing?&lt;br&gt;
Here are some reasons why we take this step:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;To help identify if our system is capable of ingesting, storing, and processing a large dataset effectively.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwdgfsw8rursk1ovv5e9h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwdgfsw8rursk1ovv5e9h.png" alt="Image description" width="703" height="700"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;To gain insights into the performance metrics of our application, system, or service. Metrics such as response time, resource utilization, throughputs, etc.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now that we have a little understanding of what volume testing is, let us proceed to the demonstration. For this demo, we will be using Apache JMeter. The Apache JMeter™ application is open-source software, a 100% pure Java application designed to load test functional behavior and measure performance. It was originally designed for testing Web Applications but has since expanded to other test functions. Here's a list of what we can test with Apache JMeter:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Web - HTTP, HTTPS (Java, NodeJS, PHP, ASP.NET, …)&lt;/li&gt;
&lt;li&gt;SOAP / REST Webservices&lt;/li&gt;
&lt;li&gt;FTP&lt;/li&gt;
&lt;li&gt;Database via JDBC&lt;/li&gt;
&lt;li&gt;LDAP&lt;/li&gt;
&lt;li&gt;Message-oriented middleware (MOM) via JMS&lt;/li&gt;
&lt;li&gt;Mail - SMTP(S), POP3(S) and IMAP(S)&lt;/li&gt;
&lt;li&gt;Native commands or shell scripts&lt;/li&gt;
&lt;li&gt;TCP&lt;/li&gt;
&lt;li&gt;Java Objects&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;to install Apache we will need to install jdk8 or Above:&lt;br&gt;
 Download the Java Development kit &lt;a href="https://www.oracle.com/java/technologies/downloads/" rel="noopener noreferrer"&gt;here.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After downloading the package, unzip it in your program files directory:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F65by3e97vydfd15drh7e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F65by3e97vydfd15drh7e.png" alt="Image description" width="800" height="565"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Set Java as an environment variable on your PC:&lt;/p&gt;

&lt;p&gt;windows home&amp;gt;&amp;gt;&amp;gt;search "edit environment variables"&amp;gt;&amp;gt; path&amp;gt;&amp;gt;&amp;gt;edit&amp;gt;&amp;gt; pass in the path to your java binary directory which should be "C:\Program Files\Java\jdk-22\bin", save and exit.&lt;br&gt;
Up next is to install Apache Jmeter. Follow this link to download the &lt;a href="https://jmeter.apache.org/download_jmeter.cgi" rel="noopener noreferrer"&gt;zip file.&lt;/a&gt;&lt;br&gt;
Extract the file on the program file directory on your C drive "C:\Program Files\apachejmeter".&lt;br&gt;
to navigate to the directory of the JMeter installation and execute the Apachejmeter execution file on your windows powershell to start the service.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fby43rbhtdjftnrksttfp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fby43rbhtdjftnrksttfp.png" alt="Image description" width="800" height="726"&gt;&lt;/a&gt;&lt;br&gt;
Run this command but replace it with the absolute path of your jar execution file location:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; PS C:\Program Filesapache-jmeter-5.6.3\apache-jmeter-5.6.3\bin&amp;gt; .\ApacheJMeter.jar
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Jmeter will automatically start. Here are some terms you should know when working with Jmeter:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Test plan: This is a name you give to a test case. For example, you are trying to test facebook web application, you can name it "facebook-test-app".&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fotiiiz1zys5hdua4wcw9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fotiiiz1zys5hdua4wcw9.png" alt="Image description" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Threads: Threads or thread groups can be defined as virtual users or user groups we can use to test the performance of our application. We can use threads to run up a high amount of requests to a defined path, we can group these threads to send 100s of requests at once. The more threads we configure the higher the load on the application. Initially, there are four types of threads that are configured by default, we can add more by using the Jmeter plugin manager. To install the plugin, check &lt;a href="https://jmeter-plugins.org/wiki/PluginsManager/" rel="noopener noreferrer"&gt;Here.&lt;/a&gt;. When you install  it. You can find it on the "Options" tab at the top of the page.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh28vgsnvh8msmx08mqvb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh28vgsnvh8msmx08mqvb.png" alt="Image description" width="800" height="436"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Search for "Custom Thread Groups" in available plugin, select and scroll down the click "apply changes and restart". After this you will be able to see the multiple thread groups in jmeter like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fexdl4f6gqmx152591fux.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fexdl4f6gqmx152591fux.png" alt="Image description" width="800" height="366"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Samplers: This component sends requests to the specified servers. A sampler can be of type HTTP request, an FTP, or SMTP.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feoirmxllts6p4fxcxmsu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feoirmxllts6p4fxcxmsu.png" alt="Image description" width="800" height="583"&gt;&lt;/a&gt;&lt;br&gt;
The image above displays a whole lot of samplers supported by Jmeter to suit your needs. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6539h42lq8q06k5nrlu6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6539h42lq8q06k5nrlu6.png" alt="Image description" width="800" height="296"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here's an example of how an HTTP request sampler looks with all the necessary details.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Listeners: When we run test cases on the samplers, we will need a report right? That's exactly what the listeners do. They are responsible for collecting and displaying the data in any form such as tables, graphs, charts, etc. Some data collected are response time, throughputs, error rates, response codes, etc.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;DEMO:&lt;br&gt;
To start this demo, ensure you have completed all  the necessary installations. &lt;/p&gt;

&lt;p&gt;Firstly we create a test plan named wordpress-test:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fix1pawzd94u6ak20w2wx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fix1pawzd94u6ak20w2wx.png" alt="Image description" width="800" height="168"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, we create thread group:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4j7uub5sbm7116o23yd6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4j7uub5sbm7116o23yd6.png" alt="Image description" width="800" height="262"&gt;&lt;/a&gt;&lt;br&gt;
An explanation of the settings defined in the thread group.The thread group will have 1000 users, 20 will send a GET request at once after 0 seconds. Then add 10 requests every 15 seconds using a ramp-up time of 5 seconds. After 1000 requests have been sent, users will hold for 60 seconds before they finally stop sending requests. The decreasing rate will be 5 users/second.&lt;/p&gt;

&lt;p&gt;After configuring the thread group, we add an HTTP request sampler to listen for GET requests on the specified path:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3ipwbwp940sskdy4lr8s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3ipwbwp940sskdy4lr8s.png" alt="Image description" width="800" height="175"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhfsq5k3mb7e0v7x6mpyy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhfsq5k3mb7e0v7x6mpyy.png" alt="Image description" width="800" height="307"&gt;&lt;/a&gt;&lt;br&gt;
 save your configuration and add a listener to display result in either a tree or table format. Click on the green "play" button to begin testing.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpvc2egixo28n49aa5o66.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpvc2egixo28n49aa5o66.png" alt="Image description" width="800" height="330"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There you go! This is how we run volume testing using the jp@gc - Stepping Thread Group. &lt;br&gt;
That brings us to the end of this article, if you have any question you can reach out to me on X (FKA twitter) @marviigrey. Thank you for your time, Goodbye.&lt;/p&gt;

</description>
      <category>devops</category>
      <category>sre</category>
      <category>java</category>
    </item>
    <item>
      <title>User creation script using bash shell.</title>
      <dc:creator>Marvellous ezemba</dc:creator>
      <pubDate>Tue, 02 Jul 2024 23:57:05 +0000</pubDate>
      <link>https://forem.com/linuxinator/user-creation-script-using-bash-shell-kem</link>
      <guid>https://forem.com/linuxinator/user-creation-script-using-bash-shell-kem</guid>
      <description>&lt;p&gt;In this article, I will demonstrate how a sysop administrator employs bash shell scripting to create multiple users and assign them unique passwords to different groups. &lt;/p&gt;

&lt;p&gt;Well, who's a sysOps admin?&lt;/p&gt;

&lt;p&gt;A SysOps (System Operations) Administrator, also known as a Systems Administrator or SysAdmin is a professional responsible for managing, maintaining, and ensuring the smooth operation of an organization's IT infrastructure. It involves a wide range of tasks to keep the organization's systems running efficiently, securely, and reliably. Among the list of key responsibilities handled by a SysOp Admin, one of the most important tasks is user management. In an infrastructure where Linux OS is the main choice of all systems, the bash shell scripting language can be used by SysAdmin to manage and maintain user accessibility. Here, I will be explaining how a SysAdmin makes use of shell scripting to manage user, groups, and password creation with ease.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/bash

# Check if the input file is provided
if [ -z "$1" ]; then
  echo "Usage: $0 &amp;lt;input_file&amp;gt;"
  exit 1
fi

INPUT_FILE="$1"

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above code starts with a shebang statement which defines the type of shell to run this script, in this situation, it's a bash shell script. The other lines check if an input file is given while running the script, this explanation will come in later after the whole script is prepared.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;LOG_FILE="/var/log/user_management.log"
PASSWORD_FILE="/var/secure/user_passwords.csv"

# Ensure the log file exists
touch "$LOG_FILE"

# Ensure the secure directory and password file exist with correct permissions
mkdir -p /var/secure
touch "$PASSWORD_FILE"
chmod 600 "$PASSWORD_FILE"

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While creating the users, we will need to log every action and step taken during the creation of users, passwords, and groups for future reference. The above code ensures that the log file is created and assigned appropriate permissions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Function to generate a random password
generate_password() {
  tr -dc A-Za-z0-9 &amp;lt;/dev/urandom | head -c 12 ; echo ''
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The next step is to generate random passwords for our users, it simply generates a 12-character password.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Read the input file line by line
while IFS=";" read -r user groups; do
  # Remove leading/trailing whitespace from user and groups
  user=$(echo "$user" | xargs)
  groups=$(echo "$groups" | xargs)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the input file that contains the users and groups mentioned earlier, this code reads it line by line to create matching usernames and groups specified in the file. The input file can might contain details like this:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Luffy; straw-hats&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The code also trims whitespace if there's any.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  # Create a personal group with the same name as the user
  if ! getent group "$user" &amp;amp;&amp;gt;/dev/null; then
    groupadd "$user"
    echo "$(date +'%Y-%m-%d %H:%M:%S') - Created personal group $user" | tee -a "$LOG_FILE"
  fi

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The next step checks if the group written in the input file exists and adds the user, if it doesn't, the group is created using &lt;code&gt;groupadd&lt;/code&gt; and this action is logged into the log file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  if id "$user" &amp;amp;&amp;gt;/dev/null; then
    echo "$(date +'%Y-%m-%d %H:%M:%S') - User $user already exists. Skipping..." | tee -a "$LOG_FILE"
    continue
  fi

  # Create the user with the personal group
  useradd -m -s /bin/bash -g "$user" "$user"
  echo "$(date +'%Y-%m-%d %H:%M:%S') - Created user $user with personal group $user" | tee -a "$LOG_FILE"

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This step checks for the existence of a user and logs the response, if the user doesn't exist, it creates the user and assigns the user's home directory to /bin/bash and personal group specified in the input file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  # Set the home directory permissions
  chmod 700 "/home/$user"
  chown "$user:$user" "/home/$user"
  echo "$(date +'%Y-%m-%d %H:%M:%S') - Set permissions for /home/$user" | tee -a "$LOG_FILE"

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This action simply sets the permission for the home directory of the user to 700 and logs the action.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  # Generate a random password and set it
  password=$(generate_password)
  echo "$user:$password" | chpasswd
  echo "$(date +'%Y-%m-%d %H:%M:%S') - Set password for $user" | tee -a "$LOG_FILE"

  # Securely store the password
  echo "$user,$password" &amp;gt;&amp;gt; "$PASSWORD_FILE"
  echo "$(date +'%Y-%m-%d %H:%M:%S') - Stored password for $user in $PASSWORD_FILE" | tee -a "$LOG_FILE"

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A password is generated for the user, stores the username and password in the password file, and logs the action in the log file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  # Add user to specified groups
  IFS="," read -r -a group_array &amp;lt;&amp;lt;&amp;lt; "$groups"
  for group in "${group_array[@]}"; do
    group=$(echo "$group" | xargs)  # Remove leading/trailing whitespace
    if ! getent group "$group" &amp;amp;&amp;gt;/dev/null; then
      groupadd "$group"
      echo "$(date +'%Y-%m-%d %H:%M:%S') - Created group $group" | tee -a "$LOG_FILE"
    fi
    usermod -aG "$group" "$user"
    echo "$(date +'%Y-%m-%d %H:%M:%S') - Added user $user to group $group" | tee -a "$LOG_FILE"
  done

done &amp;lt; "$INPUT_FILE"

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, groups are checked for their existence and created if they are not, users are added to their specified groups using other &lt;code&gt;usermod&lt;/code&gt;. Every action here is then logged to the log file.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;echo "$(date +'%Y-%m-%d %H:%M:%S') - User creation process completed." | tee -a "$LOG_FILE"&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
Finally, a message concluding the creation process and logs to the log file.&lt;/p&gt;

&lt;p&gt;To use this script, you will need to create an input file with the &lt;code&gt;.txt&lt;/code&gt; extension. Before you run the file, ensure you change the file permissions of the script using the &lt;code&gt;chmod +x script.sh&lt;/code&gt; command. &lt;br&gt;
Here is an example of what the input file should look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;coby;navy
luffy;straw-hats
edward-newgate;whitebeard
shanks;red-hair
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;coby,luffy,edward-newgate, and shanks are usernames while the navy,straw-hats,whitebeard, and red hair are the personal groups of the users. To run the script:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo ./script.sh input.txt&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Conclusion:&lt;br&gt;
Using the bash script simply makes user management seamless for system admins. This is a task given by the HNG internship. To find out about this internship visit: &lt;a href="https://hng.tech/internship" rel="noopener noreferrer"&gt;https://hng.tech/internship&lt;/a&gt; or &lt;a href="https://hng.tech/hire" rel="noopener noreferrer"&gt;https://hng.tech/hire&lt;/a&gt; to also participate. Thank you for your time. Here is the full script:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/bash

# Check if the input file is provided
if [ -z "$1" ]; then
  echo "Usage: $0 &amp;lt;input_file&amp;gt;"
  exit 1
fi

INPUT_FILE="$1"
LOG_FILE="/var/log/user_management.log"
PASSWORD_FILE="/var/secure/user_passwords.csv"

# Ensure the log file exists
touch "$LOG_FILE"

# Ensure the secure directory and password file exist with correct permissions
mkdir -p /var/secure
touch "$PASSWORD_FILE"
chmod 600 "$PASSWORD_FILE"

# Function to generate a random password
generate_password() {
  tr -dc A-Za-z0-9 &amp;lt;/dev/urandom | head -c 12 ; echo ''
}

# Read the input file line by line
while IFS=";" read -r user groups; do
  # Remove leading/trailing whitespace from user and groups
  user=$(echo "$user" | xargs)
  groups=$(echo "$groups" | xargs)

  # Create a personal group with the same name as the user
  if ! getent group "$user" &amp;amp;&amp;gt;/dev/null; then
    groupadd "$user"
    echo "$(date +'%Y-%m-%d %H:%M:%S') - Created personal group $user" | tee -a "$LOG_FILE"
  fi

  if id "$user" &amp;amp;&amp;gt;/dev/null; then
    echo "$(date +'%Y-%m-%d %H:%M:%S') - User $user already exists. Skipping..." | tee -a "$LOG_FILE"
    continue
  fi

  # Create the user with the personal group
  useradd -m -s /bin/bash -g "$user" "$user"
  echo "$(date +'%Y-%m-%d %H:%M:%S') - Created user $user with personal group $user" | tee -a "$LOG_FILE"

  # Set the home directory permissions
  chmod 700 "/home/$user"
  chown "$user:$user" "/home/$user"
  echo "$(date +'%Y-%m-%d %H:%M:%S') - Set permissions for /home/$user" | tee -a "$LOG_FILE"

  # Generate a random password and set it
  password=$(generate_password)
  echo "$user:$password" | chpasswd
  echo "$(date +'%Y-%m-%d %H:%M:%S') - Set password for $user" | tee -a "$LOG_FILE"

  # Securely store the password
  echo "$user,$password" &amp;gt;&amp;gt; "$PASSWORD_FILE"
  echo "$(date +'%Y-%m-%d %H:%M:%S') - Stored password for $user in $PASSWORD_FILE" | tee -a "$LOG_FILE"

  # Add user to specified groups
  IFS="," read -r -a group_array &amp;lt;&amp;lt;&amp;lt; "$groups"
  for group in "${group_array[@]}"; do
    group=$(echo "$group" | xargs)  # Remove leading/trailing whitespace
    if ! getent group "$group" &amp;amp;&amp;gt;/dev/null; then
      groupadd "$group"
      echo "$(date +'%Y-%m-%d %H:%M:%S') - Created group $group" | tee -a "$LOG_FILE"
    fi
    usermod -aG "$group" "$user"
    echo "$(date +'%Y-%m-%d %H:%M:%S') - Added user $user to group $group" | tee -a "$LOG_FILE"
  done

done &amp;lt; "$INPUT_FILE"

echo "$(date +'%Y-%m-%d %H:%M:%S') - User creation process completed." | tee -a "$LOG_FILE"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
  </channel>
</rss>
