Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Show Off Your Open Source Projects (http://www.programmingforums.org/forum52.html)
-   -   Shell Menu Script (http://www.programmingforums.org/showthread.php?t=1256)

big_k105 Nov 23rd, 2004 11:57 AM

here is my menu script i wrote awhile back. i know its pretty boring but im bored and thought i should post something in here finally :)

menu
:

#bin/sh
cd
clear
menu.awk
while :
do
    read INPUT_STRING
    case $INPUT_STRING in
    1)
        echo "Enter the name or ip of computer you want to connect to."
        read ssh_string
        echo "Enter your user name for this machine."
        read user_string
        ssh -l $user_string $ssh_string
        clear
        menu.awk
        ;;
    2)
        clear
        mc
        clear
        menu.awk
        ;;

    3)
        clear
        echo "Option 3 is Unused"; echo
        menu.awk
        ;;
    4)
        echo "Enter File to change permissions of."
        read file_perm
        echo "Enter permissions you want to use, using the number system."
        read perm
        chmod $perm $file_perm
        clear
        echo "File permissions have been changed."; echo
        menu.awk
        ;;
    5)
        echo "Enter Directory to change permisions of."
        read dir_perm
        echo "Enter permissions you want to use, using the number system."
        read perm2
        chmod -R $perm2 $dir_perm
        clear
        echo "Directory permissions have been changed."; echo
        menu.awk
        ;;
    6)
        clear
        ls -la | less
        echo
        menu.awk
        ;;
    7)
        echo "Enter the Directory you want to move to."
        read dir
        cd $dir
        clear
        menu.awk
        ;;
    8)
        clear
        echo "Enter File you want to edit"
        read file
        vim $file
        clear
        menu.awk
        ;;
    9)
        clear
        echo "Option 9 is Unused"; echo
        menu.awk
        ;;
    10)
        clear
        echo "Option 10 is Unused"; echo
        menu.awk
        ;;
    clear)
        clear
        menu.awk
        ;;
    //)
        echo "Exiting!"
        break
        ;;
    *)
        echo "Sorry, I don't understand"
        ;;
esac
done


menu.awk
:

awk 'BEGIN { menu="************** MENU ****************\n"
    menu=menu "* 1) SSH To Remote Computer    *\n"
    menu=menu "* 2) Midnight Commander      *\n"
    menu=menu "*  (Command line file manager) *\n"
    menu=menu "* 3)                *\n"
    menu=menu "* 4) Change File Permissions  *\n"
    menu=menu "* 5) Change Dir Permissions    *\n"
    menu=menu "* 6) List Files in Directory  *\n"
    menu=menu "* 7) Change Directory      *\n"
    menu=menu "* 8) Edit File in Direcotry    *\n"
    menu=menu "* 9)                *\n"
    menu=menu "* 10)              *\n"
    menu=menu "*                *\n"
    menu=menu "* clear) Clear Screen      *\n"
    menu=menu "* //) Quit to Prompt        *\n"
    menu=menu "************************************\n"
    menu=menu "\n"
    menu=menu "Enter Your Selection: "
    print menu }'


if you put both of these files in your /usr/bin/ dir you can just run the thing by typing menu anywhere you are :)

Ooble Nov 23rd, 2004 12:05 PM

Now there's an idea... if anyone wants my JavaScript/PHP/XML menu generator, let me know. Nice code, K.

big_k105 Nov 23rd, 2004 12:05 PM

create a thread and post it ;)

This menu system could be used when you dont want to give a user full access to the computer and only want to give them a few commands. you could set it up for when ever they ssh into the machine the menu automaticly runs and then with they exit the menu it could log out of the computer for them and then the only access they get is what you give them on the menu :)

Ooble Nov 23rd, 2004 5:44 PM

Sounds like a really good idea to me.

Infinite Recursion Nov 24th, 2004 12:19 PM

Looks pretty good man, I'm going to put it on my Fedora Core 3, Gentoo, Ubuntu, and Solaris 10 boxes to test it out for ya... maybe add a bit to it too.

Feelings are hurt cuz you don't have a "Compile C program" option... lol

big_k105 Nov 24th, 2004 12:39 PM

i couldnt think of anymore options to put into it but thats a good one. if you modify it let me know i would like to see what other options would be good to add to it :)

just figured this out if you add this to the users .profile file then it will run automaticly when they login via ssh :)

ok i have added a compile c++ and c options and even a run a.out cause thats what the code compiles to on my computer when i dont get a specific name

menu
:

#bin/sh
cd
clear
/home/big_k/menu/menu.awk
while :
do
    read INPUT_STRING
    case $INPUT_STRING in
    1)
        echo "Enter the name or ip of computer you want to connect to."
        read ssh_string
        echo "Enter your user name for this machine."
        read user_string
        ssh -l $user_string $ssh_string
        clear
        /home/big_k/menu/menu.awk
        ;;
    2)
        clear
        mc
        clear
        /home/big_k/menu/menu.awk
        ;;

    3)
        clear
        echo "Option 3 is Unused"; echo
        /home/big_k/menu/menu.awk
        ;;
    4)
        echo "Enter File to change permissions of."
        read file_perm
        echo "Enter permissions you want to use, using the number system."
        read perm
        chmod $perm $file_perm
        clear
        echo "File permissions have been changed."; echo
        /home/big_k/menu/menu.awk
        ;;
    5)
        echo "Enter Directory to change permisions of."
        read dir_perm
        echo "Enter permissions you want to use, using the number system."
        read perm2
        chmod -R $perm2 $dir_perm
        clear
        echo "Directory permissions have been changed."; echo
        /home/big_k/menu/menu.awk
        ;;
    6)
        clear
        ls -la | less
        echo
        /home/big_k/menu/menu.awk
        ;;
    7)
        echo "Enter the Directory you want to move to."
        read dir
        cd $dir
        clear
        /home/big_k/menu/menu.awk
        ;;
    8)
        clear
        echo "Enter File you want to edit"
        read file
        vim $file
        clear
        /home/big_k/menu/menu.awk
        ;;
    9)
        clear
        echo "Enter C++ Program to compile."
        read file
        g++ $file
        /home/big_k/menu/menu.awk
        ;;
    10)
        clear
        echo "Enter C Program to compile."
        read file
        gcc $file
        /home/big_k/menu/menu.awk
        ;;
    11)
        clear
        a.out
        /home/big_k/menu/menu.awk
        ;;
    clear)
        clear
        /home/big_k/menu/menu.awk
        ;;
    //)
        echo "Exiting!"
        break
        ;;
    *)
        echo "Sorry, I don't understand"
        ;;
esac
done


menu.awk
:

awk 'BEGIN { menu="************** MENU ****************\n"
    menu=menu "* 1) SSH To Remote Computer    *\n"
    menu=menu "* 2) Midnight Commander      *\n"
    menu=menu "*  (Command line file manager) *\n"
    menu=menu "* 3) Still Not Used        *\n"
    menu=menu "* 4) Change File Permissions  *\n"
    menu=menu "* 5) Change Dir Permissions    *\n"
    menu=menu "* 6) List Files in Directory  *\n"
    menu=menu "* 7) Change Directory      *\n"
    menu=menu "* 8) Edit File in Direcotry    *\n"
    menu=menu "* 9) Compile C++ Program    *\n"
    menu=menu "* 10) Compile C Program      *\n"
    menu=menu "* 11) Run a.out          *\n"
    menu=menu "*                *\n"
    menu=menu "* clear) Clear Screen      *\n"
    menu=menu "* //) Quit to Prompt        *\n"
    menu=menu "************************************\n"
    menu=menu "\n"
    menu=menu "Enter Your Selection: "
    print menu }'


Infinite Recursion Nov 24th, 2004 7:20 PM

Just added a few changes to the compile options to where you can put in a name for the binary that was created.

Changed the run a.out option to Run Program... so you can run any program you want (that you have perms to run).

Also, removed the cd command from the top of menu.sh to make the menu work with the current directory or directory specified instead of defaulting to home directory.

These are minor, trivial changes... that I needed for my "instance" of Big K's menu script.

Good work man!


menu.sh
-----------
:

    9)
        clear
        echo "Enter C++ Program to compile."
        read file
    echo "Enter program name: "
    read pname
        g++ $file -o $pname
        menu.awk
      ;;
    10)
        clear
        echo "Enter C Program to compile."
        read file
    echo "Enter program name: "
    read pname
        gcc $file -o $pname
        menu.awk
      ;;
    11)
        clear
    echo "Enter program to run:"
    read pname
        $pname
        menu.awk
      ;;



menu.awk
-------------

:


 menu=menu "* 11) Run Program        *\n"



All times are GMT -5. The time now is 1:47 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC