#!/bin/bash

# Define variables
username="ENTER_USER_NAME"
hostname="ENTER_USER_HOSTNAME"

# Check if hostname is present
if grep -q "$hostname" /etc/passwd; then
    # Check if user is present
    if id "$username" &>/dev/null; then
        # Lock user account
        sudo passwd -l "$username"
        echo "User $username has been locked."
        
        
 # Note: Unsaved data may be lost or may result in data corruption
 # Log out the user if in an active session
        sudo pkill -KILL -u "$username"
        echo "User $username has been logged out."
    else
        echo "User $username does not exist."
    fi
else
    echo "Hostname $hostname not found. Exiting..."
    exit 1
fi