Bash3lper/Bash3lper.sh
2023-03-29 20:10:53 +02:00

907 lines
23 KiB
Bash
Executable file
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
# Bash3lper.sh - Linux server tools
# Date: 2.2.2020
# Author : Erreur32
# - inspired by grabsysinfo.sh from Vivek Gite
version="2.1.32"
# echo -e "\n Bash3lper Version: $version"
# Define variables
LSB=/usr/bin/lsb_release
readonly PROGNAME=$(basename $0)
readonly PROGDIR=$(readlink -m $(dirname $0))
readonly PROGDIRSCRIPT="$(readlink -m $(dirname $0))/scripts"
readonly ARGS="$@"
## debug
set -e -u -o pipefail
IFS=$'\n\t'
on_error() { echo "Error on or near line $1; exiting with status $2"; exit "$2"; }
#trap 'on_error ${LINENO} $?' ERR
############
Bash3lper="$(cd "$(dirname "$0")" && pwd)"
Bscripts="$Bash3lper/scripts"
Bscript=$(realpath "$0")
On_Red=$(tput setab 124)
On_Green=$(tput setab 28) # ou 40
#CALERT="${CNoir}${On_Red}" # Bold White on red background
#CAlert="${CBlanc}${On_Red}"
#Cokvb="${CBlanc}${On_Green}"
#Cokv="${CNoir}${On_Green}"
#Cokvo="${CBlanc}${On_Green} OK ${NC}"
#Cko="${CRouge}X${NC}"
#Cok="${CVert}✔${NC}"
#### Color definition
GREEN="$(tput setaf 2)"
PINK="$(tput setaf 5)"
BLUE="$(tput setaf 6)"
RED="$(tput setaf 1)"
YELLOW="$(tput setaf 3)"
ORANGE="\e[38;5;202m"
ORANGE1="$(tput setaf 166)"
GRIS="\e[38;5;8m"
#GRIS="$(tput setaf 246)"
NOC="$(tput sgr0)"
NC="$(tput sgr0)"
# tmp dir
#[ -f tmp ] && echo "Dir tmp not found! let me create it." && mkdir tmp
# Make sure only root can run our script
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" 1>&2
exit 1
fi
####################################
# Purpose - Display header message
#write_header(){
# local h="$@"
# echo -e " ${GREEN} ${h} \e[38;5;8m "
# echo -e "${NOC}"
#}
####################################
# Purpose: Display pause prompt # $1-> Message (optional)
# Quit
pause_quit() {
echo -e "$(tput setaf 3)"
local message="$@"
[ -z "$message" ] && message=" Press [Enter] to quit..."
read -r -p "$message" readEnterKey
exit 0
echo -e "$(tput sgr0)"
clear
# exit 0
}
# Return
pause() {
echo -e "$(tput setaf 3)"
local message="$@"
[ -z "$message" ] && message=" Press [Enter] key to continue..."
read -r -p "$message" readEnterKey
echo -e "$(tput sgr0)"
clear
# exit 0
}
check_root() {
if [[ $EUID -ne 0 ]]; then
echo -e "\n ${RED}This script must be run as root${NOC}\n\n"
exit 1
fi
}
###############
## Header ascii
write_header_acsii() {
cat <<-"EOFB"
____ _ ____ _
| _ \ | | |___ \| |
| |_) | __ _ ___| |__ __) | |_ __ ___ _ __
| _ < / _` / __| '_ \ |__ <| | '_ \ / _ \ '__|
| |_) | (_| \__ \ | | |___) | | |_) | __/ |
|____/ \__,_|___/_| |_|____/|_| .__/ \___|_|
| |
|_|
EOFB
}
##### Header
write_header() {
tput clear
local h="$@"
# Move cursor to screen location Y,X (top left is 0,0)
tput cup 0 16
tput setaf 6
write_header_acsii
tput sgr0
tput cup 7 12
# Set a foreground colour using ANSI escape
tput setaf 3
echo " "
tput sgr0
tput cup 7 42
# Set a foreground colour using ANSI escape
tput setaf 3
echo " V0.32"
tput sgr0
# Set reverse video mode
tput cup 11 9
tput rev
echo -e "${h}"
tput sgr0
# rc revenir position initial
#tput rc
#tput cup 13 16
}
# Main menu
main_menu() {
write_header
write_header " M A I N - M E N U "
echo -e "${NOC}\n"
echo -e "${GRIS}|${NOC} 1 ${GRIS}|${NOC} Info - System ${GRIS}(Some info about your system)"
echo -e "${GRIS}|${NOC} 2 ${GRIS}|${NOC} Tools - System ${GRIS}(Tools list system)"
echo -e "${GRIS}|${NOC} 3 ${GRIS}|${NOC} Upgrade - System ${GRIS}(Check missing packages system)${NOC}"
echo -e "${GRIS}|${NOC} 4 ${GRIS}|${NOC} Misc - Tools ${GRIS}(...) "
echo -e "${GRIS}|${NOC} 5 ${GRIS}|${NOC} Scripts - Tools ${GRIS}(Scripts list) "
echo ""
echo -e "${GRIS}|${NOC} b ${GRIS}|${NOC} Browser terminal"
echo -e "\n\n${GRIS} ------------ ${NOC}</>${GRIS} -------------"
echo -e "${GRIS}| ${NOC}d${GRIS} | Bash3lper mode dialog |"
echo -e " ----- ------------------------ "
echo -e "${GRIS}| ${NOC}i${GRIS} | Bash3lper info |"
echo -e " ----- ------------------------ "
echo -e "${GRIS}| (${YELLOW}0${GRIS} or ${YELLOW}Enter${GRIS}) to ${NOC}exit${GRIS} |"
echo -e "${GRIS} ------------ ${NOC}</>${GRIS} -------------${NOC}\n"
}
# Purpose - Get input via the keyboard and make a decision using case..esac
read_input() {
echo -e "\e[38;5;202m "
local c
read -r -p " Enter your choice ${NOC} -> " c
case $c in
1) system_menu ;;
2) tools_menu ;;
3) maj_system ;;
4) misc_menu ;;
5) clear
# $dirnamescript/scripts/bashelper_list-script.sh
$Bash3lper/scripts/bashelper_list-script.sh
;;
b) sensible-browser https://git.echosystem.fr/Erreur32/Bash3lper ;;
i) show_info_bash3lper
pause
;;
d) /bin/sh ./Bash3lper-dial.sh
exit 0
;;
0) echo -e "\n Thanks to using \e[38;5;184mBash3lper ${NOC} "
exit 0
;;
"") echo -e "\n Thanks to using \e[38;5;184mBash3lper ${NOC} "
exit 0
;;
*) echo -e "\e[38;5;202m Please select between 0 to 9. ${NOC}"
pause
;;
esac
}
################# system menu ##########################
system_menu() {
option=0
until [ "$option" = "q" ]; do
write_header
write_header " I N F O - S Y S T E M "
echo -e "${NOC}\n"
echo -e "| 1 | Operating system info"
echo -e "| 2 | Network info"
echo -e "| 3 | Who is online"
echo -e "| 4 | Last logged in users"
echo -e "| 5 | Check big file"
echo -e "| 6 | All USer Crontab (root)"
echo -e "| 7 | All (quick) stat"
echo -e "\n\n --------- </> ----------"
echo -e "| 0 | Return Main Menu ${NOC}"
echo -e "| q |${RED} Exit ${NOC}"
echo -e "\e[38;5;202m "
local option
read -r -p " Enter your choice ${NOC} -> " option
echo -e "\n\n"
case $option in
1) os_info
;;
2) net_info
;;
3) user_info "who"
;;
4) user_info "last"
;;
5) clear
/usr/bin/duf ; echo -e "/n"
show_check_file
;;
6) clear
$Bash3lper/scripts/bashelper_show-crontab.sh
# $Bscripts/bashelper_show-crontab.sh
pause
;;
7) clear
$Bash3lper/scripts/bashelper_Monitor32.sh -a
# $dirnamescript/scripts/bashelper_Monitor32.sh -a
pause
;;
0) clear
break
;;
q) clear
exit 0
;;
"")
clear
break
;;
*)
echo -e "\n \e[38;5;202m Please select valid value. ${NOC}"
pause
;;
esac
done
}
################# TOOLS MENU ##########################
tools_menu() {
option=0
until [ "$option" = "q" ]; do
write_header
write_header " T O O L - S Y S T E M "
echo -e "${NOC}"
echo -e " ${GRIS}MONITORING SYSTEM${NC}"
echo -e "| 1 | Bashtop "
echo -e "| 2 | Glances"
echo -e "| 3 | Htop"
echo -e "| 4 | gtop"
echo -e "| 5 | watch Sensors"
echo -e "| 6 | s-tui"
echo -e "| 7 | Vtop"
echo -e "\n ${GRIS}Network${NOC}"
echo -e "| 14 | nload eth0"
echo -e "| 15 | iftop"
echo -e "| 16 | nethogs eth0"
echo -e "| 17 | bmon"
echo -e "| 18 | speedometer eth0"
echo -e "| 19 | vnstat "
echo -e "| 10 | netwatch eth0"
echo -e "| 666 | More info "
echo -e "\n (press q to return here)"
echo -e "| 11 | ttyload"
echo -e "| 12 | netload eth0"
echo -e "\n --------- </> ----------"
echo -e "| 0 | Return Main Menu ${NOC}"
echo -e "| q | ${RED} Exit ${NOC}"
echo -e "\e[38;5;202m "
local option
read -r -p " Enter your choice ${NOC} -> " option
echo -e "\n"
case $option in
1) clear
scripts/bashelper_bashtop.sh
;;
2) clear
glances
;;
3) clear
htop
Bash3lper.sh
;;
4) clear
show_gtop
;;
5) clear
watch -n 1 -d /usr/bin/sensors
trap ''
;;
6) clear
s-tui
;;
7) clear
show_vtop
;;
# 6) clear ; $Bscripts/nmon.sh ;;
14) clear
nload eth0
;;
15) clear
iftop
;;
16) clear
nethogs -p eth0
;;
17) clear
show_bmon
;;
18) clear
speedometer -r eth0 -t eth0
;;
19) clear
write_header
vnstat -s
vnstat -t
vnstat -m
pause
;;
10) clear
netwatch -e eth0
;;
11) clear
ttyload
trap 'break' EXIT
;;
12) clear
netload eth0
;;
0) break
;;
q) clear
exit 0
;;
*) echo -e "\n \e[38;5;202m Please select valid value. ${NOC}"
unset REPLY
;;
esac
done
}
#########################################
misc_menu() {
option=0
until [ "$option" = "q" ]; do
write_header
write_header " MISC - tool "
echo -e "${NOC}\n"
echo -e "| 1 | ${ORANGE}HACK${NOC}"
echo -e "| 2 | ${YELLOW}MOTDs32${NOC}"
echo -e "| 22 | Find top 10 big file /log"
echo -e "| 3 | Find Big File"
echo -e "| 33 | Clock - time"
echo -e "| cro | All USer Crontab (root)"
echo -e "\n\n --------- </> -----------"
echo -e "| 0 | Return Main Menu ${NOC}"
echo -e "| q |${RED} Exit ${NOC}"
echo -e "\e[38;5;202m "
local option
read -r -p " Enter your choice ${NOC} -> " option
echo -e "\n"
case $option in
1) clear
$Bscripts/bashelper_redhawk.sh
misc_menu
;;
2) check_motds32
;;
22) echo "todo!"
;;
3) clear
show_check_file
;;
33) clear
$Bscripts/bashelper_clock.sh
misc_menu
;;
0) clear
break
;;
q) clear
exit 0
;;
*) clear
echo -e "\e[38;5;202m Please select valid value.${NOC}"
;;
esac
done
}
############################################
maj_system() {
option=0
until [ "$option" = "q" ]; do
write_header
write_header " M A J - S Y S T E M "
echo -e "${NOC} \n "
echo -e "| 1 | APT update only"
echo -e "| 2 | ${ORANGE}APT Installation ${NOC}"
echo -e "| 3 | Install all essential"
echo -e "| 4 | List package installed"
echo -e "| 5 | Updatedb"
echo -e "\n --------- </> -----------\n"
echo -e "| 10 | Add .bashrc path"
echo -e "| 11 | Del .bashrc path"
echo -e "| 20 | FIX file (root right)"
echo -e "\n\n --------- </> -----------\n"
echo -e "| 00 | Check bashrc ${NOC}"
echo -e "| 0 | Return Main Menu ${NOC}"
echo -e "| q |${RED} Exit ${NOC}"
echo -e "\e[38;5;202m "
local option
read -r -p " Enter your choice ${NOC} -> " option
echo -e "\n"
case $option in
1) check_root
$Bscripts/bashelper_apt-update.sh
# show_info_Aide
;;
2) check_root
$Bscripts/bashelper_apt-upgrade.sh
# show_info_Aide
;;
3) check_root
$Bscripts/bashelper_apt-dependencies.sh
# show_info_Aide
;;
4) $Bscripts/bashelper_apt-check-installed.sh
;;
5) updatedb_do
;;
10) add_path
echo " Put manually in your .bashrc (after path line) : export PATH=/usr/local/bin:/usr/bin:/bin:$Bash3lper "
# show_info_Aide
;;
00) check_bashrc
;;
11) $Bscripts/bashelper_del_path.sh
# show_info_Aide
;;
20) $Bscripts/bashelper_fix_owner.sh
# show_info_Aide
;;
0) clear
break
;;
q) clear
exit 0
;;
*) echo -e "\e[38;5;202m Please select valid value. ${NOC}" ;;
esac
done
}
updatedb_do() {
write_header
write_header " updatedb - UPDATE "
echo -e "\n updated is dependant to locate function, eg: locate Bash3lper\n\n"
echo -e "updatdb inprogress ... please wait!" && updatedb
echo -e " ${GREEN} OK"
pause
}
check_bashrc() {
write_header
write_header " P A T H - A L I A S "
if [ $(grep -c "Bash3lper.sh" ~/.bashrc) == 0 ]; then
# echo -e "${RED} Code bash not found"
echo -e "alias bashelper=\"$Bash3lper/Bash3lper.sh\"" >> ~/.bashrc
echo -e "\n\n Check PATH: $PROGDIRSCRIPT"
echo -e "export PATH=\$PATH:$PROGDIRSCRIPT" >> ~/.bashrc
echo -e "\n \e[0m >>\e[50;3m alias=\"$Bash3lper/Bash3lper.sh\" \e[0m\n"
echo -e " ${NOC}[\e[32m✔${NOC}] \e[1;30m Code added in bashrc OK!\n"
source ~/.bashrc && export PATH
pause
else
echo -e "\n\n Check PATH: $PROGDIRSCRIPT\n"
echo -e " PATH bashelper ok! [\e[32m✔${NOC}]"
pause
fi
}
add_path() {
write_header
write_header " P A T H - S Y S T E M "
echo -e "\n \e[48;3m -Script path: ${NOC}$Bash3lper\n"
# if no path - add this
#if [ -z "${PATH-}" ]; then export PATH=/usr/local/bin:/usr/bin:/bin:$Bash3lper; fi
if grep -qinE "Bash3lper" ~/.bashrc ; then
# echo -e "\n \e[0m >>\e[50;3m export PATH=$PATH$Bash3lper \e[0m\n${NOC}"
# if [ -z "${PATH-}" ]; then export PATH=/usr/local/bin:/usr/bin:/bin:$Bash3lper; fi
# echo -e " \e[0m >>\e[50;3m alias=\"$Bash3lper/Bash3lper.sh\" \e[0m\n"
# echo -e " ${NOC}[\e[32m✔${NOC}] \e[1;30m Code added in bashrc OK!\n"
echo -e "✅ Code .bashrc OK"
echo $PROGDIR
else
echo -e "alias bashelper=\"$Bash3lper/Bash3lper.sh\"" >> ~/.bashrc
echo -e "\n \e[0m >>\e[50;3m export PATH=$PATH$Bash3lper \e[0m\n${NOC}"
if [ -z "${PATH-}" ]; then export PATH=/usr/local/bin:/usr/bin:/bin:$Bash3lper; fi
echo -e "export PATH=\$PATH:$Bash3lper" >> ~/.bashrc
echo -e " \e[0m >>\e[50;3m alias=\"$Bash3lper/Bash3lper.sh\" \e[0m\n"
echo -e " ${NOC}[\e[32m✔${NOC}] \e[1;30m Code added in bashrc OK!\n"
# echo -e "export PATH=\$PATH:$Bash3lper" >> ~/.bashrc
# echo -e " \e[0m >>\e[50;3m alias=\"$Bash3lper/Bash3lper.sh\" \e[0m\n"
# echo -e " alias bashelper=\"$Bash3lper/Bash3lper.sh\"" >> ~/.bashrc
# echo -e " ${NOC} [\e[32m✔${NOC}] -->\e[34m Path added in .bashrc: \e[38;5;2mOK\e[0m \n"
# echo -e "\n\e[48;3m Your new path is: ${NOC}"
# echo -e " $PATH"
fi
#source ~/.bashrc
#echo -e "\n add path to your .bashrc $GREEN OK ${NOC}"
pause && source ~/.bashrc && export PATH
}
remove_path (){
write_header
write_header " P A T H - S Y S T E M "
if (whiptail --title " Yes / No" --yesno "Remove path in your .bashrc ?" 10 60) then
# make backup of your .bashrc
cp ~/.bashrc ~/.bashrc_backup
echo -e "\n ${YELLOW} backup of your .bashrc DONE! \n"
echo -e "\n${GRIS} --------- </> ---------- ${NOC}\n"
echo -e "\n - remove path in your .bashrc \n"
echo -e "${GRIS} --------- </> ---------- ${NOC}\n"
if [ `grep -c Bash3lper ~/.bashrc` == 0 ]
then
echo -e "\n ${RED} Code bash not found - or already removed!\n ${GREEN} All GOOD !\n\n"
pause
else
sed -i '/Bash3lper/d' ~/.bashrc
echo -e "\e[92m Code .bashrc removed.\n\e[0m"
echo -e " ${GREEN} all GOOD !"
echo -e "${YELLOW}To reload your bash now type: ${GRIS} source ~/.bashrc${NOC}"
pause
# source ~/.bashrc
echo -e "\e[1;30m Check\n \e[0m>>\e[50;3m export PATH=$PATH \e[0m<<\n\n"
# relaod bashrc
# grep -n 'Bash3lper' ~/.bashrc
fi
# echo -e "\n${RED} Already removed! ${NOC}- ${GREEN} all GOOD !${NOC}2"
else
echo -e "\n ${RED} No change ! quit"
pause
fi
}
################################
# System menu
show_check_file() {
write_header
write_header " DUF + FIND top 10 big file - /var/log "
echo -e "\n\n${GRIS} --------- </> ---------- ${NOC}\n"
# duf
# Vérifier si la commande 'curl' est installée
if ! which duf > /dev/null; then
echo "La dépendance curl n'est pas installée."
read -p "Voulez-vous l'installer maintenant? (y/n) " choice
if [ "$choice" = "y" ]; then
sudo apt-get install duf
else
echo "Installation annulée."
# exit 1
fi
fi
/usr/bin/duf
echo ""
echo -e " Check Big file ... please wait"
echo ""
find /var/log/ -type f -exec du -s {} \; | sort -n | tail -n 10
pause
}
#################################
# TOOLS menu
check_motds32() {
# write_header
# write_header " MOTDs32 "
if [ -f /usr/bin/motds32 ]; then
/usr/bin/motds32 -s
pause
else
echo "MOTDS32 not installed , installation in progress... please wait!"
# cd /tmp
# git clone https://git.echosystem.fr/Erreur32/MOTDs32.git
# cd /tmp/MOTDs32 && ./install.sh
pause
fi
}
show_check_bmon() {
dpkg-query -l bmon | grep bmon
}
show_bmon() {
if [ -n show_check_bmon ]; then
# echo "ok bmon is installed"
/usr/bin/bmon
else
echo "bmon not installed , installation in progress... please wait!"
echo "apt-get install bmon"
apt-get install bmon
fi
}
#######
show_check_glances() {
dpkg-query -l glances | grep glances
}
show_glances() {
if [ -n show_check_glances ]; then
# echo "ok bmon is installed"
/usr/bin/bmon
else
echo "Glances not installed , installation in progress... please wait!"
echo "curl -L https://bit.ly/glances | /bin/bash"
curl -L https://bit.ly/glances | /bin/bash
fi
}
######
show_check_vtop() {
if [ -f /usr/bin/vtop ]; then
/usr/bin/vtop
else
echo "$FILE not installed , installation in progress... please wait!"
npm install -g vtop || echo "npm need to be installed"
fi
}
show_vtop() {
if [ -f /usr/local/bin/vtop ]; then
# echo "wheris vtop is installed"
#whereis vtop
/usr/local/bin/vtop
else
echo "Vtop not installed , installation in progress... please wait!"
echo "npm install -g vtop"
npm install -g vtop || echo "npm need to be installed"
fi
}
#######
show_check_gtop() {
dpkg-query -l bmon | grep gtop
}
show_gtop() {
if [ -n show_check_gtop ]; then
# echo "ok bmon is installed"
/usr/bin/gtop
else
echo "gtop not installed , installation in progress... please wait!"
echo "npm install gtop -g"
npm install gtop -g
fi
}
# Purpose - Get info about your operating system
os_info() {
clear
write_header
write_header " System information "
echo -e "\n\n"
echo -e " Operating system :$GREEN $(uname) ${NOC}"
[ -x $LSB ] && $LSB -a || echo " $LSB command is not insalled (set \$LSB variable)"
echo ""
# pause
# host_info ()
local dnsips=$(sed -e '/^$/d' /etc/resolv.conf | awk '{if (tolower($1)=="nameserver") print $2}')
echo -e "\n Hostname :$GREEN $(hostname -s)${NOC}"
echo -e " DNS domain :$GREEN $(hostname -d)${NOC}"
echo -e " Fully qualified domain name :$GREEN $(hostname -f)${NOC}"
echo -e " Network address (IP) :$GREEN $(hostname -i)${NOC}"
echo -e " DNS name servers (DNS IP) :$GREEN ${dnsips}${NOC}"
# pause
# meminfo ()
echo -e "\n\n $GREEN Free memory ${NOC}"
free -m
echo -e "\n $GREEN Virtual memory statistics ${NOC}"
vmstat
echo -e "\n $GREEN Top 5 memory eating process ${NOC}"
ps auxf | sort -nr -k 4 | head -5 && pause
echo ""
pause
}
# Purpose - Get info about host such as dns, IP, and hostname
host_info() {
write_header
local dnsips=$(sed -e '/^$/d' /etc/resolv.conf | awk '{if (tolower($1)=="nameserver") print $2}')
write_header " Hostname and DNS information ${NOC}"
echo -e "\n\n Hostname :$GREEN $(hostname -s)${NOC}"
echo -e " DNS domain :$GREEN $(hostname -d)${NOC}"
echo -e " Fully qualified domain name :$GREEN $(hostname -f)${NOC}"
echo -e " Network address (IP) :$GREEN $(hostname -i)${NOC}"
echo -e " DNS name servers (DNS IP) :$GREEN ${dnsips}${NOC}"
pause
}
# Purpose - Network inferface and routing info
net_info() {
# {
# for ((i = 0; i <= 100; i += 20)); do
# sleep 0.5s
# echo $i
# done
# } | whiptail --gauge "Veuillez patienter ... Scan en cours" 6 60 0
clear
write_header
devices=$(netstat -i | cut -d" " -f1 | egrep -v "^Kernel|Iface|lo")
write_header " Network information "
echo -e " \n\n"
echo -e " Total network interfaces found :\e[38;5;11m $(wc -w <<<${devices}) ${NOC}"
echo -e ""
echo -e "\e[38;5;8m---------------------------------------------------------------${NOC}"
echo -e "$GREEN IP Addresses ${NOC} Information ${NOC}"
echo -e "\e[38;5;8m---------------------------------------------------------------${NOC}"
ip -4 address show
echo ""
echo -e "\e[38;5;8m---------------------------------------------------------------${NOC}"
echo -e "$GREEN Network routing ${NOC}"
echo -e "\e[38;5;8m---------------------------------------------------------------${NOC}"
netstat -nr
echo ""
echo -e "\e[38;5;8m---------------------------------------------------------------${NOC}"
echo -e "$GREEN Interface traffic information ${NOC}"
echo -e "\e[38;5;8m---------------------------------------------------------------${NOC}"
netstat -i
echo ""
pause
}
# Purpose - Display a list of users currently logged on
# display a list of receltly loggged in users
user_info() {
echo -e " \n\n"
{
for ((i = 0; i <= 100; i += 25)); do
sleep 0.4
echo $i
done
} | whiptail --gauge "Veuillez patienter ... Scan en cours" 6 60 0
local cmd="$1"
case "$cmd" in
who)
write_header " Who is online "
who -H
pause
;;
last)
write_header " List of last logged in users "
last
pause
;;
esac
}
# Purpose - Display used and free memory info
mem_info() {
write_header " Free and used memory "
echo -e " \n\n"
free -m
echo ""
echo -e "*** $GREEN Virtual memory statistics ${NOC}"
vmstat
echo ""
echo -e "*** $GREEN Top 5 memory eating process ${NOC}"
ps auxf | sort -nr -k 4 | head -5
echo ""
pause
}
show_info_bash3lper() {
write_header
write_header " S C R I P T - I N F O "
echo -e "\n${GRIS} --------- </> ---------- ${NOC}\n"
echo -e " \n"
echo -e " Path script : $Bash3lper/ \n Script Name : $0 \n - Version : $version \n - Author : Erreur32 \n"
echo -e "${GRIS} --------- </> ---------- ${NOC}\n"
echo -e " Bash3lper CLI"
# echo -e " cli enable: ./bash3lper -h (help) \n"
echo -e " ${GRIS} Usage:\n ${NOC} bash3lper --help (-h)${GRIS} :Display help message ${NOC}\n"
echo -e "${GRIS} --------- </> ---------- ${NOC}\n"
echo -e " Kernel Info: $(uname -smr)"
echo -e " Shell: $SHELL ${NC}\n"
}
######################## - CLI ###################################
show_cli() {
write_header
write_header " C L I - info "
echo -e "\n Bash3lper CLI"
echo -e "$GRIS Usage:\n \$ bash3lper [arguments] ${NOC}\n"
echo -e "Arguments:"
echo -e "--help (-h): Display this help message"
echo -e "--update (-U): Update Bash3lper script"
echo -e "--stat32 (-s): Stat32 show system stat"
echo -e "--motds32(-m): show MOTD\n"
echo -e "--info (-i): Info script"
echo -e "--version(-v): Show version\n"
}
################################################################
## CLI
read_cli() {
case "$@" in
-h | --help)
show_cli
exit 0
;;
-i | --info)
show_info_bash3lper
exit 0
;;
-U | --update)
write_header
write_header " UPDATE "
echo -e "\n"
exit 0
;;
-v | --version)
show_info_bash3lper
exit 0
;;
-m | --motds32)
echo "Read motds32 file"
cat /etc/motd
exit 0
;;
-s | --stat32)
echo "Read motds32 file"
/etc/motds32/Stats32
exit 0
;;
*)
main_menu
;;
esac
}
################################################################
# ignore CTRL+C, CTRL+Z and quit singles using the trap
# trap '' SIGINT SIGQUIT SIGTSTP
trap "clear; exit" SIGHUP SIGINT SIGTERM
###############################
#function finish {
# Your cleanup code here
#}
#trap finish EXIT
###############################
## main_menu logic
while true; do
read_cli $ARGS
clear
main_menu # display memu
read_input # wait for user input
done
## EOF