A simple menu for common tasks

I named this file menu and put it in a directory that's in my path. Don't forget to chmod 755 menu so that you can execute it.

Usage: menu

or

Usage: menu <one of the options Example: menu 3

#!/bin/bash

option="${1}"

if [[ $option == "" ]]; then
        clear

        echo "
        SSH
        ---
        1: ssh account 1 (foo-server-1)
        2: ssh account 2 (foo-server-2)

        Open Files
        ----------
        3: some_file.txt
        4: another.xml
        5: nice_latex.tex

"

        read option
fi

if [[ $option == "1" ]] || [[ $option == "2" ]] || [[ $option == "3" ]] || [[ $option == "4" ]] || [[ $option == "5" ]]; then
  if [[ $option == "1" ]]; then
                ssh joefoo@foo-server-1
        elif [[ $option == "2" ]]; then
                ssh manbar@foo-server-2
        elif [[ $option == "3" ]]; then
                vi /path/to/some_file.txt
        elif [[ $option == "4" ]]; then
                vi /path/to/another.xml
        elif [[ $option == "5" ]]; then
                vi /path/to/nice_latex.tex
        fi
else
        echo "
        I don't know what to do!!!

"
fi

Detect when a disk drive is about full

#!/bin/bash

# This script does a very simple test for checking disk space.

space=`df -h | awk '{print $5}' | grep % | grep -v Use | sort -n | tail -1 | cut -d "%" -f1 -`
alertvalue="80"

if [ "$space" -ge "$alertvalue" ]; then
  echo "At least one of my disks is nearly full!" | mail -s "daily diskcheck" root
else
  echo "Disk space normal" | mail -s "daily diskcheck" root
fi

If statment that uses grep like eregi() in PHP

#!/bin/bash

#> error and success are two files
# error="No pages of output"
# success="Output written on"

if grep "No pages of output" error > /dev/null; then
  echo "We found 'No pages of output' in error"
fi
#> out puts the echo above

if grep "written on" success > /dev/null; then
  echo "We found 'Output written on' in success"
fi

Math

x=1
y=3
z=$[$x + $y]
echo $z
#> outputs 4 duh!
echo $[1 + 2]
#> outputs 3

Print last file by modification date

# ls -ltr some_directory | tail -n1 | sed 's/^.*\ //g' | sed 's/\/$//g'

or

# ls -tr | tail -n1 | sed 's/\/$//g'

References

Page Comments (Click to edit)






[Click to add or edit comments])

Please prepend comments below including a date

Design by N.Design Studio, adapted by solidGone.org (version 1.0.0)
Have a nice day.