1

I want to make system menu after login in my Ubuntu server like this image:

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?

1 Answer 1

2

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
  • Copy the above content and use in nano: Shift+Insert for paste; Ctrl+O and Enter for save; Ctrl+X for exit.
  • All commands used within the script are available in Ubuntu 16.04.
  • The content between the brackets [...] 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:

enter image description here

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:

enter image description here

5
  • 1
    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.)
    – muru
    Sep 12, 2017 at 9:15
  • 1
    @muru, thanks for this. I've updated the answer. I found that on my home Ubuntu Desktop 16.04 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.
    – pa4080
    Sep 12, 2017 at 12:46
  • 1
    Hmm, that is strange. whiptail is a dependency of ubuntu-minimal, but not of ubuntu-standard or ubuntu-server. Strange indeed.
    – muru
    Sep 12, 2017 at 12:53
  • thank you guys so much, i'll try this next week and i'll reply thanks for your support.
    – Devigner3D
    Sep 12, 2017 at 22:07
  • Hi, @Devigner3D, have you succeed with this?
    – pa4080
    Nov 14, 2017 at 19:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .