• Skip to main content

Uly.me

cloud engineer

  • Home
  • About
  • Archives

menu

Bash Menu and Functions

September 22, 2022

How to integrate menus and functions in your Bash script.

#!/bin/bash
function show_logs {
ls -l /var/log/
}
function show_users {
cat /etc/passwd
}
echo '--------'
echo 'My Menu'
echo '--------'
PS3='Choose an option: '
commands=("Show logs" "Show users" "Quit")
COLUMNS=0
select cmd in "${commands[@]}"; do
    case $cmd in
        "Show logs")
            echo "Showing logs ... "
            show_logs
            ;;
        "Show users")
            echo "Showing users ... "
            show_users
            ;;
	"Quit")
	    echo "Exiting ... "
	    exit
	    ;;
        *) echo "invalid option $REPLY";;
    esac
done

#!/bin/bash function show_logs { ls -l /var/log/ } function show_users { cat /etc/passwd } echo '--------' echo 'My Menu' echo '--------' PS3='Choose an option: ' commands=("Show logs" "Show users" "Quit") COLUMNS=0 select cmd in "${commands[@]}"; do case $cmd in "Show logs") echo "Showing logs ... " show_logs ;; "Show users") echo "Showing users ... " show_users ;; "Quit") echo "Exiting ... " exit ;; *) echo "invalid option $REPLY";; esac done

Result

--------
My Menu
--------
1) Show logs
2) Show users
3) Quit

-------- My Menu -------- 1) Show logs 2) Show users 3) Quit

Filed Under: Linux Tagged With: bash, functions, menu

GRUB Fixes

February 15, 2020

This are grub fixes to servers that are not booting up due to improper entries in the grub menu.

grub --batch <<END
root (hd0,0)
setup (hd0,0)
quit
END
#
sed -i 's/dev\/sda/dev\/hda/' /boot/grub/device.map
sed -i 's/(hd0)/(hd0,0)/' /boot/grub/menu.lst

grub --batch <<END root (hd0,0) setup (hd0,0) quit END # sed -i 's/dev\/sda/dev\/hda/' /boot/grub/device.map sed -i 's/(hd0)/(hd0,0)/' /boot/grub/menu.lst

The fix includes replacing (hd0) with (hd0,0) and /dev/sda with /dev/hda.

Filed Under: Linux Tagged With: boot, fix, grub, issues, menu

  • Home
  • About
  • Archives

Copyright © 2023