0% found this document useful (0 votes)
22 views

Labs and Mini-Project For Linux

Uploaded by

zidane
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Labs and Mini-Project For Linux

Uploaded by

zidane
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Administration of Operating Systems :

Administration of Linux

1. Basic commands

During this practical Test, you will learn how to :


Create files, folders and links
Paste, move and rename files
Use pipes and redirections
Search file on the system
Archive and compress file

1.1. File's and Directory's Operations

You will learn how to create files, folders and links

- Create a file file1 and a folder folder1 in your home directory.

- In folder1, create a symbolic link named kernel which link to /usr/src/ .

- List the content of the current directory , and the content of folder1. backup (copy)
folder1 directory to folder2. Remove folder1 and then rename folder2 to folder1.
- Go to folder1/noyau/ , then used pwd -P to print the current directory. Use cd ? to go
back in the previous directory.

- Print the /var/log/X.0.log file with the cat , more , less , tail and head command. Quickly
explain the difference between each command.

- On a first terminal, use the auto refresh of the tail command to display the file
/var/log/auth. Then log into another terminal and observe file's modifications on the first
terminal.

- Display all lines of the /var/log/messages which contains the word « usb ».

- Create a file name A Great File. Then remove it using the rm command and Bash
completion . Look closely at the syntax used by Bash .

- Remove all files and folder ended by « 1 ».

1.2. Find and Locate

You will learn how to search files in the system


- Find a file named messages in the /var directory.
- Find all files ended by « .log ».
- Find all directories named log which have been access in the last 2 days.
- Find all files ended by « .log » and then use touch to update the last modification date.
Then, check with the ls -l command that the date has been modified correctly.
- Update the slocate database .
- Find all file's which ended by « .conf », redirect the output in the /home/supinfo/result
file and display the file with less only if the locate command was successful.

Page 1 / 31
Administration of Operating Systems :
Administration of Linux

2. Introduction to shell
In this practical test, you will learn to:
7.1.Use the shell, discover autocompletion
7.2.Configure your prompt and login actions
7.3.Find help
7.4.Create aliases
7.5.Play with input/output redirections

2.1. Start using the shell

- Open a terminal window or login in the console


- A prompt apears. Write some commands: uname -sr, free -m, ls
- Discover autocompletion: list the content of the /usr/share/doc directory, using
autocompletion.

2.2. Configure your prompt and login actions

- Modify your prompt to get some colours in it.

- You can find color code in this page http://bash-


hackers.org/wiki/doku.php/scripting/terminalcodes for example

- configure your shell to get a welcome message at login.

2.3. Find help

- Find some help on the find command. You want to know wich option is used to search
by modification time.

- You don't remember the syntax of ln , to create a link. Does the destination must be
the first or the second argument ? Find some quick help !

2.4. Create aliases

- You never remember the command that find files that were created or modified the
previous 3 days in your home directory. Write an alias to make it easier and to
remember well.

2.5. Play with input/output redirection

- Use the alias you've just created in order to write the list of the files created or
modified the previous 3 days in a file called "recent_documents.txt".

Page 2 / 31
Administration of Operating Systems :
Administration of Linux

3. Users and group management


During this practices we will learn to:
Manipulate users on the system

3.1. Users and groups


- Create a user redhat with /home/redhat as home directory (automatically) and with the
password « password » (do not show the password in the shell).

- Create the esi group without any option.

- Define the esi group as primary for the redhat user.

- Set the secondary groups of redhat as : users and audio .

- List redhat 's groups

3.2. Identity management

Note : To quickly logout the user of a shell session , there is a useful shortcut Ctrl + D . This
shortcut is equivalent to type exit command.

- Switch from root to redhat .

- Show who is logged on.

- Logout from redhat to root über-user.

- Lock the redhat account.

- Become supinfo . Why the password of supinfo user is not asked ??

- Try to log as redhat .

- Back in root then log into redhat . Why it's possible ?

- Back in root and unlock the redhat 's user account.

- Modify the /etc/passwd file and set the shell of redhat to /bin/false .

- Log in as redhat . Does it function? Why ?

3.3. User and Group deletion.

- Delete the user redhat and his home directory.

- Delete the group esi .

Note : We can also edit the files /etc/passwd and /etc/group an delete the concerned lines.
Page 3 / 31
Administration of Operating Systems :
Administration of Linux

4. Permission management
During this practice we will
learn to:
Change permissions

4.1. Permissions Management

- Create a file named « toto » and a folder « foo ». What are the permissions by default ?

- List file's and folder's permissions.

- Change umask to 0077

- Create a file named toto2 and a folder named foo2 , what are the permissions?

- Change file's owner and group to root.

- Set read/write/execute access for the owner, read/execute for the group and read for the
others on the file toto . Use letters first, then octal permissions.

- Try to shutdown the system as redhat user by using the shutdown -h now command then
/sbin/shutdown -h now . Why shutdown does not function without using
the full path ?

- Make so that a normal user can shutdown the system by setting SUID on /sbin/shutdown .

Page 4 / 31
Administration of Operating Systems :
Administration of Linux

5. Process Management
During this practice we will learn to:
• Control and kill Processes
• Manage task with atd and crond

5.1. Process Management

- Launch updatedb and kill it with a key combination.

- Launch the eyes > /dev/null command and suspend it with a key combination.

- Use the jobs command to see the running "jobs" and their PID for the current shell.

- Switch the yes > /dev/null command to the foreground.

- Open a new terminal and search for the PID, nice number of the precedent command ,
then decrease its priority to 15.

- Now, send the SIGTERM or SIGKILL signal to the yes > /dev/null process and check if it
has been quit .

- Launch the top command to display all current processes 3 times, with an interval
between the refresh of 5 seconds and redirect the output to a file. (have a look at the man)

Page 5 / 31
Administration of Operating Systems :
Administration of Linux

6. Bash Scripting

In this practical test, you will learn to


Write useful shell scripts
Create little programs with menus
Make boring tasks easier and quicker

6.1. Simple scripts

You are going to write several simple

scripts. Pre-requisites :
- Basic commands
- cut, sed
- Pipes and redirections
- Variables
- Arguments given to script
- Archiving
- Permissions
- Network basics
- FHS organization

- Create a file with text and add "#! /bin/more" at the beginning. Make this file executable
and execute it.
What's happening?

- Create a script that empties the /var/log/messages. (Work on a copy of /var/log/messages).

- Create a script that keeps the 20 last lines of the "/var/log/messages" file.

- Modify the previous script to have a customizable line number (passed as parameter).

- Create a script that copies a floppy using the dd command.

- Create a script that print the number of process that you have launch.

- Create a script that displays the CPU usage, its speed in MHz and the Ram amount you are
using.

- In a script, using the ls command and it's list function, check if a file exists.

- Create a script that deletes all files of a directory (Be care of the hidden files).

- Create a script displaying "Hello your_name" (use the whoami command).


- Create a compressed archive of your home directory in the /var/tmp directory. The
name must depend of the archive creation's date : archive-DD-MM-YYYY.tar.gz.
- Modify the bash configuration to personalize the shell connection (the message that is
print when we connect to the shell).
- Display a welcome message followed by the user name.
- Display the time. For example: It's 14 hours and 53 minutes

Page 6 / 31
Administration of Operating Systems :
Administration of Linux

Note : Use the date command (To display only hours: date +%H, only

minutes: date +%M). Copy this file in /etc/skel after verifying it works.

Create a script that :


- Has a network interface name.
- Displays the IP (only IP) of the previous interface.
- Use ifconfig <interface>
- Use grep to get the line containing the IP.
- Use cut to separate the line and get the column containing the IP. (the ":" separator can be
a good idea).
- Delete the text not used with sed.
- Print the variable.

6.2. Advanced Scripts(mini project)

In this part, you will have to create several advanced scripts.

Pre-requisites:
- Conditionnal structures
- Loops
- Functions (arguments and return value)
- Network
- Zenity
- Gnuplot
- HTML
Monitoring your computer's internet traffic
Goals
Reaffirm your knowledge of what you have learned about programming shell scripts and using the
Gnuplot program.

Description of the mini-project


Knowing the resource usage of computers can be essential in some cases. For example, in the
case of a provider of cloud computing services, a high CPU resource utilization rate, on a
frequent and regular basis, would plead for an increase in their computing capacity (ie more
servers).
To know the level of use of the resources of your computer, the operating systems are able to
interrogate the sensors inserted in the electronic components (eg temperature of the CPU), as
well as to maintain statistics on the software events (eg state of processes, etc.).
In this project, you will create a very basic shell script that will calculate network traffic and
create a figure (using the Gnuplot program) showing the evolution of the amount of data
received and sent by our network card. This figure will be shown through a static HTML page
that will update regularly and automatically.

Mini-guide for the realization of the project


Here is some information that will help you complete your project.
• For a static HTML page to update automatically, you can use the meta tag with
parameter http-equiv="refresh" (see page
https://www.hscripts.com/tutorials/html/autorefresh.php)
• Statistics related to network interface activity are available in the
Page 7 / 31
Administration of Operating Systems :
Administration of Linux
system/sys/class/net/netiface/statistics/ where netiface is the name of the network
interface (eg eth0). Statistics related to incoming traffic can be found in the file
beginning with "rx_», and those of outgoing traffic in the files starting with «tx_".

Services expected from your script


1. At a minimum, your script should take the name of the interface to monitor as an
argument.
2. The static HTML web page must show the name of the interface that was given as an
argument and other information that will be necessary for the good readability of the
results.
3. The HTML page will be saved by default in the folder/tmp/netiface, where
netiface matches in the name of the interface to monitor.The image must show the number of bytes
received and sent per minute and will cover a maximum of 1 hour of monitoring.
4. An additional feature. For example, taking into account multiple arguments to better
adapt to user needs (monitoring interval, modification of the default location, taking into
account one or more network interfaces, etc.), or adding a graphical interface with zenity
(https://medium.com/@krishnakantdigole/how-to-use-zenity-command-and-its-
options-in-redhat-linux-ebec9a167912 ),
export of data to a .csv file that can be downloaded from the web page, etc.

What you need to return


Solution files will be sent in the supmti plateforme in a compressed file in format yourname.rar and containing all
your files:
• Your shell script. The code should be commented and modular;
• Your HTML Template page;
• A README file, which will describe how your program should be used, what your
script does and what it doesn't.

The most correct solution will be gratify by +6 points add to the mark of the exam
The almost correct solution will be gratify by +4 points add to the mark of the exam
The half correct solution will be gratify by +2 points add to the mark of the exam

Deadline 01/30/2023

Page 8 / 31

You might also like