Menu driven linux

Ananya Jain
5 min readAug 24, 2021

📄 *Task Description:*

_Create Blog/Video attaching Screenshot of following task:_

*️⃣ Make a user in Rhel8 Machine give permissions.

*️⃣ Create a menu program that runs all the Linux based commands. (lvcreate, vgcreate, cron, fstab etc). Also add webserver configuration in that program.

Let’s first discuss all the command which I have used in my task.

  1. Yum

Yellowdog Updater, Modified, one of the vestiges of Yellow Dog Linux, is the package manager used by Red Hat, Fedora, and CentOS systems and their derivatives.

If we want to search any package in our Linux OS

yum search <queryString>#other than root account
sudo yum search <queryString>

To install:

yum install <packagename>#other than root
sudo yum install <packagename>

2. Date

To give date as a output in terminal.

$date

3. ls

ls is a Linux shell command that lists directory contents of files and directories.

ls -l : To show long listing information about the file/directory

$ls -l

4. grep

The grep filter searches a file for a particular pattern of characters, and displays all lines that contain that pattern. The pattern that is searched in the file is referred to as the regular expression (grep stands for globally search for regular expression and print out).

grep [options]  [files]

options are:

-c : This prints only a count of the lines that match a pattern
-h : Display the matched lines, but do not display the filenames.
-i : Ignores, case for matching
-l : Displays list of a filenames only.
-n : Display the matched lines and their line numbers.
-v : This prints out all the lines that do not matches the pattern
-e exp : Specifies expression with this option. Can use multiple times.
-f file : Takes patterns from file, one per line.
-E : Treats pattern as an extended regular expression (ERE)
-w : Match whole word
-o : Print only the matched parts of a matching line,
with each such part on a separate output line.
-A n : Prints searched line and nlines after the result.
-B n : Prints searched line and n line before the result.
-C n : Prints searched line and n lines after before the result.

5. systemctl

systemctl is used to examine and control the state of “systemd” system and service manager.

systemctl [OPTIONS...] COMMAND [NAME...]

6. useradd:

useradd is a command in Linux that is used to add user accounts to your system. It is just a symbolic link to adduser command in Linux

sudo useradd  <test_user>

one more command is associated with it is:

passwd : to pass password for the user just added using above.

sudo passwd <test_user>

7. fdisk

fdisk also known as format disk is a dialog-driven command in Linux used for creating and manipulating disk partition table. It is used for the view, create, delete, change, resize, copy and move partitions on a hard drive using the dialog-driven interface.

fdisk [options] device

8. crontab

the crontab command opens the cron table for editing. The cron table is the list of tasks scheduled to run at regular time intervals on the system.

crontab [-u user] file

9. mount

mount command is used to mount the filesystem found on a device to big tree structure(Linux filesystem) rooted at ‘/’.

mount -t type device dir

10. fstab

fstab is a configuration table designed to ease the burden of mounting and unmounting file systems to a machine. It is a set of rules used to control how different filesystems are treated each time they are introduced to a system.

vim /etc/fstab

11. pvcreate

Use the pvcreate command to initialize a block device to be used as a physical volume. Initialization is analogous to formatting a file system.

The following command initializes /dev/sdd, /dev/sde, and /dev/sdf as LVM physical volumes for later use as part of LVM logical volumes.

# sudo pvcreate /dev/sdd /dev/sde /dev/sdf

12. vgcreate

To create a volume group from one or more physical volumes, use the vgcreate command. The vgcreate command creates a new volume group by name and adds at least one physical volume to it.

The following command creates a volume group named vg1 that contains physical volumes /dev/sdd1 and /dev/sde1.

# vgcreate vg1 /dev/sdd1 /dev/sde1

13. lvdisplay

The lvdisplay command displays logical volume properties (such as size, layout, and mapping) in a fixed format.

sudo lvdisplay

NOTE: ‘sudo’ keyword is used only when you are working on non-root account.

Now let’s take a small glimpse at the python code for menu driven program.

os.py

I have also used e-speak command to get the audio output also.

Also in option 8 I have provided a whole set of command to python so that if user hit for 8 option the whole webserver will be created.

First is to make a account which have permissions

Now lets run our python program

# python3 os.py

used option 1, yum command successfully working.

date command is working great.

All commands are running great and fine.

Successfully created a Linux Menu using Python. 😎

Thank You!

--

--

Ananya Jain

Google Cloud ACE Certified | Google Cloud Student Mentor | Operation Team @Amazon Alexa Community | Aviatrix Certified Engineer | Machine Learning enthusiast