I want to make system menu after login in my Ubuntu server like this image:
To change my Ethernet IP address, the local time and some other stuff important to me, I don't know how I can reach this settings?
I don't know where each option from the example refers to. Here's a working tutorial - How to create a script with similar menu.
First you need to install dialog
. This application provides a method of displaying several different types of dialog boxes from shell scripts:
sudo apt install dialog
Then create executable file, let's call it smenu
, and place it into the directory /usr/local/bin/
, thus it will be accessible as shell command system wide:
sudo touch /usr/local/bin/smenu
sudo chmod +x /usr/local/bin/smenu
sudo nano /usr/local/bin/smenu
The script content should look like this:
#!/bin/bash
HEIGHT=18
CHOICE_HEIGHT=10
WIDTH=78
BACKTITLE="SYSTEM MENU"
TITLE="[ M A I N - M E N U ]"
MENU="Tasks:"
OPTIONS=(
Network/IP "IP Settings [sudo nano /etc/hosts ]"
Network/DNS "DNS Settings [sudo nano /etc/resolv.conf ]"
Network/IFCS "Network Interfaces [sudo nano /etc/network/interfaces ]"
Timezone "Set Time Zone [sudo dpkg-reconfigure tzdata ]"
Reboot "Reboot the System [sudo systemctl reboot ]"
Shutdown "Shutdown the System [sudo shutdown ]"
Logout/Exit "Logout the Session [logout ]"
Update "Update & Upgrade & autoRemove & autoClean [sudo apt ...]"
Edit "Edit this script [sudo nano /usr/local/bin/system-menu]"
Shell "Exit to Shell"
)
CHOICE=$(dialog --clear \
--backtitle "$BACKTITLE" \
--title "$TITLE" \
--menu "$MENU" \
$HEIGHT $WIDTH $CHOICE_HEIGHT \
"${OPTIONS[@]}" \
2>&1 >/dev/tty)
clear
case $CHOICE in
Network/IP)
sudo nano /etc/hosts
;;
Network/DNS)
sudo nano /etc/resolv.conf
;;
Network/IFCS)
sudo nano /etc/network/interfaces
;;
Timezone)
sudo dpkg-reconfigure tzdata
;;
Reboot)
sudo systemctl reboot
;;
Shutdown)
sudo shutdown
;;
Exit)
logout
;;
Update)
sudo apt update && sudo apt upgrade && sudo apt autoremove && sudo apt autoclean
echo "**"
sudo uname -a
echo "**"
sudo lsb_release -a
echo "**"
[ -e /var/run/reboot-required* ] && echo "Reboot is required!" || echo "Reboot is not required."
;;
Edit)
sudo nano /usr/local/bin/smenu
;;
Shell)
exit
;;
esac
nano
: Shift+Insert for paste; Ctrl+O and Enter for save; Ctrl+X for exit.[...]
is just a reminder of what will be executed.Now you will be able to access the script via the command smenu
. The result should be:
If you want to open this script after login into a terminal, append next line to the bottom of the file ~/.bashrc
:
/usr/local/bin/smenu
Instead of dialog
can be used the tool whiptail
, that offers much of the same functionality (and options) as dialog
, and is installed by default in most Ubuntu distributions. For this purpose use the above script and change line 22
in this way:
CHOICE=$(whiptail --clear \
Now the output of our script/command smenu
should look like this:
whiptail
offers much of the same functionality (and options) as dialog
, and is installed by default. (I ran a quick test and you can just replace dialog
with whiptail
in this script, no unsupported options are used.)
whiptail
actually was installed by default, but on my VPS with Ubuntu Server 16.04 (that is hosted on SolusVM/OpenVZ) it was not, so I ran sudo apt install whiptail
.
whiptail
is a dependency of ubuntu-minimal
, but not of ubuntu-standard
or ubuntu-server
. Strange indeed.