S ection A
1. I want a manual page of command so that I can see the full documentation of the
command.
Man page for the command
man internctl
2. Each linux command has an option --help which helps the end user to understand
the use cases via examples. Similarly if I execute internsctl --help it should
provide me the necessary help.
3. I want to see version of my command by executing
internsctl –version
File internsctl --version
code
echo "v0.1.0"
Out put:
S ection B
Part1 :
1. I want to get cpu information of my server through the following command:
Internsctl cpu getinfo:
2. I want to get memory information of my server through the following command:
$Internsctl memory getinfo:
File internsctl memory getinfo:
Code:
free
Part2
1. I want to create a new user on my server through the following command:
$ internsctl user create <username>
File internsctl user create
Code
#! /bin/bash
if id "$1" &>/dev/null;
then
echo "User $1 already exists."
echo "please chose another username."
exit
else
read -p "password " pswd
useradd -p "$pswd" -d /home/"$1" -m -g users -s /bin/bash "$1"
echo "$1 added"
fi
2. I want to list all the regular users present on my server through the following
command:
$ internsctl user list
#! /bin/bash
cat /etc/passwd
3. If want to list all the users with sudo permissions on my server through the following
command:
$ internsctl user list --sudo-only
File internsctl user list --sudo-only
Code
#!/bin/sh
getent group sudo
Part3
By executing below command I want to get some information about a file
$ internsctl file getinfo <file-name>
Expected Output
xenonstack@xsd-034:~$ internsctl file getinfo hello.txt
File: hellot.txt
Access: -rw-r--r--
Size(B): 5448
Owner: xenonstack
Modify: 2020-10-07 20:34:44.616123431 +0530.
Code:
#! /bin/bash
if [[ "$#" -eq 1 ]];
then
ls -l $1
elif [[ "$#" -eq 2 ]];
then
if [ "$1" == "-s" ] || [ "$1" == "--size" ]
then
wc -c $2
elif [ "$1" == "-p" ] || [ "$1" == "--permissions" ]
then
ls -ld $2 |awk '{ print $1; }'
elif [ "$1" == "o" ] || [ "$1" == "--owner" ]
then
stat -c '%U' $2
elif [ "$1" == "m" ] || [ "$1" == "--last-modified" ]
then
stat -c ‘%y’ $2
fi
fi