Monday, May 18, 2026

 Python script to add users and assign group

#!/usr/bin/python3

import os


userlist = ["alpha", "beta", "gamma"]


print("Adding users to system")

print("###############################")


#Loop to add user from userlist

for user in userlist:

    exitcode = os.system("id {}".format(user))

    if exitcode != 0:

        print("User {} does not exist. Adding it.".format(user))

        print("#########################################")

        print()

        os.system("useradd {}".format(user))

    else:

        print("User already exist, skipping it.")

        print("#################################")

        print()


# Condition to check if group exists or not, add if not exist.

exitcode = os.system("grep science /etc/group")

if exitcode != 0:

    print("Group science does not exist. Adding it")

    print("#####################################")

    print()

    os.system("groupadd science")

else:

    print("Group already exist, skipping it.")

    print("#############################")

    print()


for user in userlist:

    print("Adding user {} in the science group".format(user))

    print("################################")

    print()

    os.system("usermod -G science {}".format(user))

------------
Output

Adding users to system
###############################
uid=1002(alpha) gid=1002(alpha) groups=1002(alpha),1005(science)
User already exist, skipping it.
#################################

uid=1003(beta) gid=1003(beta) groups=1003(beta),1005(science)
User already exist, skipping it.
#################################

uid=1004(gamma) gid=1004(gamma) groups=1004(gamma),1005(science)
User already exist, skipping it.
#################################

science:x:1005:alpha,beta,gamma
Group already exist, skipping it.
#############################

Adding user alpha in the science group
################################

Adding user beta in the science group
################################

Adding user gamma in the science group
################################

Sunday, May 17, 2026

 Python script to check a file or directory exists or not in linux

vim check-file.py

#!/usr/bin/python3

import os

path = '/tmp/testfile.txt'

if os.path.isdir(path):

    print("It is a directory")

elif os.path.isfile(path):

    print("It is a file.")

else:

    print("file or dir does not exist")

--------------
Grant execute permission to the file

chmod +x check-file.py

Execute the file

./check-file.py

Output

It is a file.

Since I have created this file already, it gave the above output.


Saturday, May 16, 2026

Windows laptop mic volume dropped

My laptop volume suddenly dropped low. Below fix worked for me.

start menu -> settings -> Advanced -> Volume mixer

Select Volume mixer


Click Reset. 


Try to record a video and listen or test your mic.

Inter VLAN configuration