Find the answer to your Linux question:
Page 2 of 3 FirstFirst 1 2 3 LastLast
Results 11 to 20 of 21
I had to remove all changes and put right as its on my previous post. The if statement dont work, i replace the exit between the else and fi and ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #11
    Just Joined!
    Join Date
    Sep 2011
    Posts
    19

    I had to remove all changes and put right as its on my previous post.

    The if statement dont work, i replace the exit between the else and fi and it just dont work, only works with the exit

  2. #12
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    It works for me, if I use the line I originally suggested, e.g. (spaces around '=' and double-pipe):
    Code:
    if [ "$text" = "s" ] || [ "$text" = "S" ]; then

  3. #13
    Just Joined!
    Join Date
    Sep 2011
    Posts
    19
    yes
    had to remove it now everything works except the yes/no thing, always go yes...

    Does the yes/no part work with you?

  4. #14
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    Well, I think it does. If I answer 's' (yes), it attempts to perform whatever number I entered for selection. Then when it is done executing that command, the menu is displayed again. So..

    If I select 7 and s, it exits.

    If I select 1-6 and s, it performs that action for 1-6 and then re-displays the menu.

    If I select 1-7 and n, then it exits.

    So is it that you want the menu to display again, in that last case (if the users enters 'n')?

  5. #15
    Just Joined!
    Join Date
    Sep 2011
    Posts
    19
    almost when user press n from 1 to 7 it reloads the menu

  6. #16
    Just Joined!
    Join Date
    Sep 2011
    Posts
    19
    if [ "$text" = "s" ] || [ "$text" = "S" ]; then

    tried that, if i gave any space it wont work.

  7. #17
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    Create a new script and copy-pasted this in there and try it:
    Code:
    #!/bin/bash
    now=$(date +"%d_%b_%Y-%H:%M:%S")
    
    selection=''
    
    until [ "$selection" = "0" ]; do
    
      echo ""
      echo Manutencao de BD
      echo - - - - - - - - - -
      echo Backup
      echo 1. Backup Diario
      echo 2. Backup Semanal
      echo 3. Backup Mensal
      echo - - - - - - - - - -
      echo Restauro
      echo 4. Restauro Diario
      echo 5. Restauro Semanal
      echo 6. Restauro Mensal
      echo - - - - - - - - - -
      echo 7. Sair
      echo ""
      echo -n "Escolha uma opcao: "
      read selection
      echo ""
    
      echo -n "Tem a certeza?(s/n) "
      read text
    
      if [ "$text" = "s" ] || [ "$text" = "S" ]; then
    
        case $selection in
          1 )
    mv /home/oc/Desktop/Backup_OC/Backup_Diario/* /home/oc/Desktop/Backup_OC/Backup_Diario_old/
    /opt/PostgreSQL/8.4/bin/pg_dump --host localhost --port 5432 --username postgres --format tar --blobs --verbose --file "/home/oc/Desktop/Backup_OC/Backup_Diario/Backup_oc_diario_$now" openclinica
    echo
    echo ::::Backup Diario Efectuado com Sucesso::::;;
    
          2 )
    mv /home/oc/Desktop/Backup_OC/Backup_Semanal/* /home/oc/Desktop/Backup_OC/Backup_Semanal_old/
    /opt/PostgreSQL/8.4/bin/pg_dump --host localhost --port 5432 --username postgres --format tar --blobs --verbose --file "/home/oc/Desktop/Backup_OC/Backup_Semanal/Backup_oc_semanal_$now" openclinica
    echo
    echo ::::Backup Semanal Efectuado com Sucesso::::;;
    
          3 )
    mv /home/oc/Desktop/Backup_OC/Backup_Mensal/* /home/oc/Desktop/Backup_OC/Backup_Mensal_old/
    /opt/PostgreSQL/8.4/bin/pg_dump --host localhost --port 5432 --username postgres --format tar --blobs --verbose --file "/home/oc/Desktop/Backup_OC/Backup_Mensal/Backup_oc_mensal_$now" openclinica
    echo
    echo ::::Backup Mensal Efectuado com Sucesso::::;;
    
          4 )
    cd /home/oc/Desktop/Backup_OC/Backup_Diario/
    for i in `ls -a *`
    do
    /opt/PostgreSQL/8.4/bin/pg_restore --host localhost --port 5432 --username postgres --dbname openclinica --list "/home/oc/Desktop/Backup_OC/Backup_Diario/"$i"" openclinica
    done
    echo
    echo ::::Restauro DB Diario Efectuado com Sucesso::::;;
    
          5 )
    cd /home/oc/Desktop/Backup_OC/Backup_Semanal/
    for i in `ls -a *`
    do
    /opt/PostgreSQL/8.4/bin/pg_restore --host localhost --port 5432 --username postgres --dbname openclinica --list "/home/oc/Desktop/Backup_OC/Backup_Semanal/"$i"" openclinica
    done
    echo
    echo ::::Restauro DB Semanal Efectuado com Sucesso::::;;
    
          6 )
    cd /home/oc/Desktop/Backup_OC/Backup_Mensal/
    for i in `ls -a *`
    do
    /opt/PostgreSQL/8.4/bin/pg_restore --host localhost --port 5432 --username postgres --dbname openclinica --list "/home/oc/Desktop/Backup_OC/Backup_Mensal/"$i"" openclinica
    done
    echo
    echo ::::Restauro DB Mensal Efectuado com Sucesso::::;;
    
          7 ) exit ;;
          * ) echo "Escolha uma das opções apresentadas no menu"
        esac
    #  else
    #    exit
      fi
    done

  8. #18
    Just Joined!
    Join Date
    Sep 2011
    Posts
    19
    Working great thanks.

    The problem was the lack of # in the end??

  9. #19
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    Problems what "else exit" in your 'if' clause. It was saying, in pseudo-code:

    if the user enters 's' or 'S', then carry on with selection, otherwise exit the script. You already had a continuous loop (i didn't notice before), so it would regenerate the menu by itself after each command. You just had to remove the bit about exiting if not 's' or 'S'.
    Last edited by atreyu; 11-07-2011 at 03:57 PM. Reason: typo

  10. #20
    Just Joined!
    Join Date
    Sep 2011
    Posts
    19
    the thing is that everytime i tried to remove that exit it would just stop working, dont know why...

    Oh well, its working great now, thanks so much for the help

Page 2 of 3 FirstFirst 1 2 3 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
  •