BashScripts.org
http://bashscripts.org/forum/

Menu and user suspend/unsuspend
http://bashscripts.org/forum/viewtopic.php?f=8&t=514
Page 1 of 1

Author:  BrianUK [ Fri May 16, 2008 5:06 am ]
Post subject:  Menu and user suspend/unsuspend

Hi

Although i've started to tinker with scripting i've hit a brick wall when it comes to menus, I would like something like this....

menu 1

1, suspend/unsuspend user
2, blah
3, blah
4, blah

when user selects 1 I want another menu to open saying

0, main menu
1, suspend user
2, unsuspend user

when user selects 0 they're returned to menu 1

when user selects 1 I want Please Enter Username: and after it's entered i'd like the command passwd -l to be run on the user and the output to be displayed. Then returned to suspend/unsuspend user menu.

when user selects 1 I want Please Enter Username: and after it's entered i'd like the command passwd -u to be run on the user and the output to be displayed. Then returned to suspend/unsuspend user menu.

Hope this makes sense and i'm sure it's not as hard as i've made out ha! any help would be appriciated

Author:  myownshadow [ Fri May 16, 2008 3:18 pm ]
Post subject: 

here we go
Code:
#!/bin/bash

submenufunc() {
   select CHOICE  in dang blah blah2 mainmenu
   do
   case "$CHOICE" in
      "dang")
         echo "dang"
         ;;
      "blah")
         echo "blah blah foo"
         ;;
      "blah2")
         echo "blah2 blah foo"
         ;;
      "mainmenu")
              echo -e  "\n1) submenu\n2) blah\n3) blah2\n4) quit"  #to display main menu agin :S there must be a better way
         break
         ;;
   esac
   done
}

select CHOICE  in submenu blah blah2 quit
do
   case "$CHOICE" in
      "submenu")
         submenufunc
         ;;
      "blah")
         echo "blah blah foo"
         ;;
      "blah2")
         echo "blah2 blah foo"
         ;;
      "quit")
         exit
         ;;
   esac
done

Author:  BrianUK [ Sat May 17, 2008 3:45 am ]
Post subject: 

thanks for that very helpful. Can you tell me how to allow for user input after selecting sususer ie selet 1) sususer which returns 'enter username' which is then entered and output is dispalyed, also how do i get space inbetween titles ie Suspend User? this is what i have so far.

Code:
#!/bin/bash

submenufunc() {
   select CHOICE  in sususer blah1 blah2 mainmenu
   do
   case "$CHOICE" in
      "sususer")
         passwd -l
         ;;
      "blah1")
         echo "blah blah foo"
         ;;
      "blah2")
         echo "blah2 blah foo"
         ;;
      "mainmenu")
              echo -e  "\n1) submenu\n2) blah\n3) blah2\n4) quit"  #to display main menu agin :S there must be a better way
         break
         ;;
   esac
   done
}

select CHOICE  in submenu blah blah2 quit
do
   case "$CHOICE" in
      "submenu")
         submenufunc
         ;;
      "blah")
         echo "blah blah foo"
         ;;
      "blah2")
         echo "blah2 blah foo"
         ;;
      "quit")
         exit
         ;;
   esac
done

Author:  DeX [ Mon May 19, 2008 11:18 pm ]
Post subject: 

for user input you will want to use the read command. For example:

Code:
#!/bin/bash

submenufunc() {
   select CHOICE  in sususer blah1 blah2 mainmenu
   do
   case "$CHOICE" in
      "sususer")
         read -p "Enter Your Username: " username
         passwd -l $username
         ;;
      "blah1")
         echo "blah blah foo"
         ;;
      "blah2")
         echo "blah2 blah foo"
         ;;
      "mainmenu")
              echo -e  "\n1) submenu\n2) blah\n3) blah2\n4) quit"  #to display main menu agin :S there must be a better way
         break
         ;;
   esac
   done
}

select CHOICE  in submenu blah blah2 quit
do
   case "$CHOICE" in
      "submenu")
         submenufunc
         ;;
      "blah")
         echo "blah blah foo"
         ;;
      "blah2")
         echo "blah2 blah foo"
         ;;
      "quit")
         exit
         ;;
   esac
done


As far as spacing goes, are you referring to adding a blank line between each menu item or using phrases with spaces as menu items? I think you're trying to use spaced phrases as menu items. Use single quotes like this:

Code:
#!/bin/bash

submenufunc() {
   select CHOICE  in 'Suspend User' blah1 blah2 'Main Menu'
   do
   case "$CHOICE" in
      "sususer")
         read -p "Enter Your Username: " username
         passwd -l $username
         ;;
      "blahblah1")
         echo "blah blah foo"
         ;;
      "blahblah2")
         echo "blah2 blah foo"
         ;;
      "mainmenu")
              echo -e  "\n1) submenu\n2) blah\n3) blah2\n4) quit"  #to display main menu agin :S there must be a better way
         break
         ;;
   esac
   done
}

select CHOICE  in submenu blah blah2 quit
do
   case "$CHOICE" in
      "submenu")
         submenufunc
         ;;
      "blah")
         echo "blah blah foo"
         ;;
      "blah2")
         echo "blah2 blah foo"
         ;;
      "quit")
         exit
         ;;
   esac
done


Hope this helps!

Author:  BrianUK [ Tue Dec 01, 2009 2:40 am ]
Post subject:  Re:

Code:
#!/bin/bash

submenufunc() {
   select CHOICE  in sususer blah1 blah2 mainmenu
   do
   case "$CHOICE" in
      "sususer")
         passwd -l
         ;;
      "blah1")
         echo "blah blah foo"
         ;;
      "blah2")
         echo "blah2 blah foo"
         ;;
      "mainmenu")
              echo -e  "\n1) submenu\n2) blah\n3) blah2\n4) quit"  #to display main menu agin :S there must be a better way
         break
         ;;
   esac
   done
}

select CHOICE  in submenu blah blah2 quit
do
   case "$CHOICE" in
      "submenu")
         submenufunc
         ;;
      "blah")
         echo "blah blah foo"
         ;;
      "blah2")
         echo "blah2 blah foo"
         ;;
      "quit")
         exit
         ;;
   esac
done


Can anyone tell me how to add another submenu ie user selects option 1 gets the submenu as per the above makes another selection and get a second sub menu.

thanks

Author:  Watael [ Tue Dec 01, 2009 3:05 am ]
Post subject:  Re: Menu and user suspend/unsuspend

You could play with tput (man tput; man 5 terminfo)
Code:
submenufunc() {
#...
"mainmenu") tput cuu 6
            tput ed
            break
;;
esac
done
}

Author:  BrianUK [ Tue Dec 01, 2009 4:55 am ]
Post subject:  Re: Menu and user suspend/unsuspend

Hm can't seem to get that working properly for some reason, do have an example?

Author:  Watael [ Tue Dec 01, 2009 5:31 am ]
Post subject:  Re: Menu and user suspend/unsuspend

well, I gave you an example.

How doesn't it work ?

Author:  BrianUK [ Wed Dec 02, 2009 1:58 pm ]
Post subject:  Re: Menu and user suspend/unsuspend

Sorry, I included the code however it didn't make any difference

Author:  BrianUK [ Thu Apr 01, 2010 2:08 pm ]
Post subject:  Re: Menu and user suspend/unsuspend

I've tired this

Code:
!/bin/bash

submenufunc() {
"mainmenu") tput cuu 6
            tput ed
            break
   select CHOICE  in sususer blah1 blah2 mainmenu
   do
   case "$CHOICE" in
      "sususer")
         passwd -l
         ;;
      "blah1")
         echo "blah blah foo"
         ;;
      "blah2")
         echo "blah2 blah foo"
         ;;
      "mainmenu")
              echo -e  "\n1) submenu\n2) blah\n3) blah2\n4) quit"  #to display main menu agin :S there must be a better way
         break
         ;;
   esac
   done
}

select CHOICE  in submenu blah blah2 quit
do
   case "$CHOICE" in
      "submenu")
         submenufunc
         ;;
      "blah")
         echo "blah blah foo"
         ;;
      "blah2")
         echo "blah2 blah foo"
         ;;
      "quit")
         exit
         ;;
   esac
done


However get

line 4: syntax error near unexpected token `)'
line 4: `"mainmenu") tput cuu 6'

Author:  Watael [ Fri Apr 02, 2010 2:36 am ]
Post subject:  Re: Menu and user suspend/unsuspend

Code:
#!/bin/bash

clean() {
   printf '%s\n' 'cuu 5' ed | tput -S
}
submenufunc() {
   select CHOICE in sususer blah1 blah2 mainmenu; do
      case $CHOICE in
         sususer) passwd -l
         ;;
         blah1) echo "blah blah foo"
         ;;
         blah2) echo "blah2 blah foo"
         ;;
         mainmenu) clean
                mainMenu #to display main menu agin :S there must be a better way
                break
         ;;
      esac
   done
}
mainMenu() {
select CHOICE in submenu blah blah2 quit; do
   case $CHOICE in
      submenu) clean
               submenufunc
               break
      ;;
      blah) echo "blah blah foo"
      ;;
      blah2) echo "blah2 blah foo"
      ;;
      quit) exit
      ;;
   esac
done
}

mainMenu

Author:  BrianUK [ Fri Apr 02, 2010 8:44 am ]
Post subject:  Re: Menu and user suspend/unsuspend

Thanks but that still only gives 1 submenu?

Author:  Watael [ Fri Apr 02, 2010 9:59 am ]
Post subject:  Re: Menu and user suspend/unsuspend

Code:
#!/bin/bash

clean() {
   printf '%s\n' rc ed | tput -S
}
pend() {
   read -p" Enter the name of the user you want to be $2 : " User
   passwd -$1 $User
   read -p' Press any key'
}
unSusPend() {
   select CHOICE in suspend unsuspend back; do
      case $CHOICE in
         suspend) msg=suspended
                  opt=l
         ;;
         unsuspend) msg=restored
                    opt=u
         ;;
         back) clean
               mainMenu
         ;;
      esac
pend $opt $msg
clean
unSusPend
   done
}
mainMenu() {
select CHOICE in sus/unsuspend blah blah2 quit; do
   case $CHOICE in
      sus/unsuspend) clean
                     unSusPend
      ;;
      blah) echo "blah blah foo"
      ;;
      blah2) echo "blah2 blah foo"
      ;;
      quit) clean
            exit
      ;;
   esac
done
}

printf '%s\n' clear sc | tput -S
mainMenu
anything else?

Author:  BrianUK [ Fri Apr 02, 2010 1:39 pm ]
Post subject:  Re: Menu and user suspend/unsuspend

That does the same only 1 sub menu not main/sub/sub

Author:  Watael [ Fri Apr 02, 2010 2:34 pm ]
Post subject:  Re: Menu and user suspend/unsuspend

what's the third menu ?

Author:  BrianUK [ Fri Apr 02, 2010 2:56 pm ]
Post subject:  Re: Menu and user suspend/unsuspend

Something like

Main Menu

1, Users
2, System

when user selects 1 I want another menu to open saying

1, Access
2. Quota

when user selects 1

1, Suspend User
2, Unsuspend User

Author:  Watael [ Fri Apr 02, 2010 4:43 pm ]
Post subject:  Re: Menu and user suspend/unsuspend

hmm...
and what does fail when you do it?

Page 1 of 1 All times are UTC - 6 hours
© 2000, 2002, 2005, 2007 phpBB Group • http://www.phpbb.com