Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 14
Hi guys im russell im new to these forum and new to linux. I would like to create a bash menu script for my home server For instance if i ...
  1. #1
    Just Joined!
    Join Date
    Jan 2011
    Posts
    10

    Bash Menu Script

    Hi guys im russell im new to these forum and new to linux.
    I would like to create a bash menu script for my home server
    For instance if i were to type ./script
    It would then bring up 3 options
    a. Create a backup
    b. Restore files from a backup
    c. Quit
    If you were to select a or b it should then ask you were you want to backup or restore from.
    And if i were to type in an incorrect letter i should get an error and take me back to menu.
    I have attepmted this a view time now and have magaged to get the menu up using parameters but am a real newbie at this
    Any help would be very much appreciated.

  2. #2
    oz
    oz is online now
    forum.guy
    Join Date
    May 2004
    Location
    arch linux
    Posts
    18,096
    Hello and welcome to the forums!

    It will be easier for someone to help you find any errors in your code if you'll post it.
    oz

    new members/users: read this first | new member faq
    no private messages requesting computer support - post them on the forums!
    please use the "report post" button to alert our forum admins to problematic posts rather than responding to them yourself.

  3. #3
    Just Joined!
    Join Date
    Jan 2011
    Posts
    10
    As you can see im extremely new to linux and really not sure what im doing if any one can help it would be awesome

    #!/bin/bash

    # Menu for Server

    clear # Clear the screen.

    echo " Select one"
    echo " ------- ----"
    echo "Choose one of the following options:"
    echo
    echo "[A]Create Backup"
    echo "[B]Restore files from backup"
    echo "[C]Quit"
    echo
    read option
    case "$option" in
    # Note variable is quoted.
    "A" | "a" )
    # Accept upper or lowercase input.
    echo
    echo "tar c <any>"
    ;;

  4. #4
    Just Joined!
    Join Date
    Jan 2011
    Posts
    10
    When i try run the first option it gives me this error
    ./menu: line 22: syntax error: unexpected end of file

  5. #5
    Just Joined!
    Join Date
    Jan 2011
    Posts
    10
    Dont think the echo "tar c <any>" is correct
    Im trying to say if you choose A then you will get an option of what file you want to backup
    But dont know how to do that

  6. #6
    Linux Newbie
    Join Date
    Mar 2009
    Posts
    228
    I think your problem is that you're using double quotes on that line. That causes bash to interpret what's within the double quotes which in this case is the < and > which are redirections. Try using single quotes instead.

    Code:
    echo 'tar c <any>'

  7. #7
    Just Joined!
    Join Date
    Jan 2011
    Posts
    10
    I tried that still giving me the same error

  8. #8
    Just Joined!
    Join Date
    Jan 2011
    Posts
    10
    I think what i have to do is something like this
    if you select a
    then tar -cf <any>
    which im hoping will then ask me what i would like to backup
    But i really dont know how to do that.

  9. #9
    Linux Newbie
    Join Date
    Mar 2009
    Posts
    228
    Doh! I now see the problem. You're missing an esac at the end. Also you'll have to prompt for the name of the tarball plus the directory you want to back up. Here's the end of the code:

    Code:
    read -p "Name of tar ball: " tarball
    read -p "Directory to back up: " bckdir
    echo
    tar -cf $tarball $bckdir
    ;;
    esac

  10. #10
    Just Joined!
    Join Date
    Jan 2011
    Posts
    10
    Ok so im almost done now im stuck on the last 1 here i need to have it so if you choose "c" or "C" the it quits the menu.Here is my code so far

    Code:
    #!/bin/bash
    
    # Menu for Server
    
    clear # Clear the screen.
    
    echo " Select one"
    echo " ------- ----"
    echo "Choose one of the following options:"
    echo
    echo "[A]Create Backup"
    echo "[B]Restore files from backup"
    echo "[C]Quit"
    echo
    read option
    case "$option" in
    # Note variable is quoted.
    "A" | "a" )
    read -p "Name Your Backup : " tarball
    read -p "Directory to back up: " bckdir
    echo
    tar -cf $tarball $bckdir
    ;;
    
    "B" | "b" )
    read -p "Name of File you want to Restore : " tarball
    echo
    tar -xf $tarball
    ;;
    
    "C" | "c" )
    read -p "Are you sure you want to exit? : " exit
    ehco
    ./menu
    ;;esac
    anyone give me a hand plz
    Last edited by MikeTbob; 01-26-2011 at 03:38 AM. Reason: Added Code Tags

Page 1 of 2 1 2 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...