Your friend saw a Windows administrator using widgets like this, but he uses Linux and asked you to help him out by writing something similar for his terminal.
- Practice writing shell scripts
- Use environment variables in practice
- Use basic control structures
- Learn which files in Linux hide information about the system
-
The behaviour of
widget.sh
should be controlled with theWIDGET_CONTROL
enviromental variable. The contents ofWIDGET_CONTROL
are separated by commas and can be one or more of the following in any order: mem, cpu, proc, user, disk.- If
WIDGET_CONTROL
is not setwidget.sh
displays memory and cpu stats - If
WIDGET_CONTROL
is setwidget.sh
displays stats about the given parameters, e.g. ifWIDGET_CONTROL=mem,user
then memory and user stats are displayed
- If
-
Write a script (
mem.sh
) that displays information about memory usage and free memory.- The script displays the amount of free memory
- The script displays the amount of total memory
-
Write a script (
cpu.sh
) that displays information about the CPU.- The script displays the CPU's model name
- The script displays the number of CPU cores
- The script displays the CPU's clock frequency (in MHz or GHz)
-
Write a script (
proc.sh
) that displays the number of running processes.- The script displays the number of running processes.
-
Write a script (
disk.sh
) that displays the avaible disks and the total amount of free space.- The script displays all available disks (block devices), e.g.
/dev/sda
,/dev/sdb
, etc. - The script displays the amount of total disk space
- The script displays the amount of free space
- The script displays the percentage of used disk space
- The script displays all available disks (block devices), e.g.
-
[OPTIONAL] You've found a way to extract some nifty information from a file hidden deep inside in the Linux file hierarchy. Feel free to add this new functionalty similarly to the other scripts, like
mem.sh
and its friends.- Be creative! :)
None
- Remeber, in Linux everything is a file! :)
- You can pipe the output of commands to
grep
and/orcut
to filter relevant information - You can find various information about memory and cpu in
/proc/meminfo
and/proc/cpuinfo
- You can find the list of users in
/etc/passwd
and groups in/etc/group
- You can find information about disk usgint the
lsblk
command anddf
for disk usage - Most of the command's output can be written without headers using arguments for easier parsing for scripts