Projects dedicated to:
- Providing information about the system and its architecture
- Retrieving data about system components (memory, CPU/GPU, disk space, etc.)
List of projects in this directory:
architecture.sh- Return operating system and machine name, check OS compatibilityhardware.sh- Return average CPU load, total and used memory
Script that returns the operating system and machine name, as well as provides OS compatibility check function.
General usage:
- Script:
bash architecture.sh
- Import:
source architecture.sh
Methods:
-
get_os- Return operating system name- Returns:
- Operating system name
- Returns:
-
get_machine- Return machine name- Returns:
- Machine name
- Returns:
-
is_compatible- Check if the current OS is compatible with the provided list of OS names- Arguments:
os_names- List of OS names to check compatibility with
- Returns:
1if the current OS is not compatible- Message that the OS is compatible
- Arguments:
Use cases:
-
Check your OS and machine name:
bash architecture.sh
-
Check if given script can be run on this OS by providing compatible OS names:
#!/bin/bash source architecture.sh is_compatible "darwin" "linux" # Code below will run if the OS is either darwin or linux unix_only_method
Script that returns average CPU load, total and used memory.
General usage:
- Script:
bash hardware.sh
- Import:
source hardware.sh
Methods:
-
get_cpu_load- Get average loads of the CPU (1, 5, and 15 min)- Returns:
- Average CPU loads to stdout
- Returns:
-
get_total_memory- Get total RAM memory size- Arguments:
-b/k/m/g/t/pflags for return format--siflag for using base 1000 instead of 1024-h, --helpfor printing usage and allowed formats
- Returns:
- Total RAM memory value to stdout
- Exit code 1 if incompatible
- Arguments:
-
get_used_ram_percentage- Get percentage of used RAM memory- Returns:
- Memory usage percentage to stdout
- Exit code 1 if incompatible
- Returns:
-
main- Main script method- Returns:
- Current average CPU loads
- Current percentage of memory used
- Current memory used in GB
- Returns:
Use cases:
-
Check current CPU load and memory usage:
bash hardware.sh
-
Get total memory in megabytes using SI units:
#!/bin/bash source hardware.sh get_total_memory --si -m
-
Get used RAM percentage:
#!/bin/bash source hardware.sh get_used_ram_percentage