Register
It is currently Sun Apr 20, 2014 2:58 pm

Menu and user suspend/unsuspend


All times are UTC - 6 hours


Post new topic Reply to topic  [ 17 posts ] 
Author Message
 PostPosted: Fri May 16, 2008 5:06 am   

Joined: Fri May 16, 2008 4:58 am
Posts: 94
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


Top
 Profile  
 PostPosted: Fri May 16, 2008 3:18 pm   
User avatar

Joined: Sun Apr 13, 2008 4:05 am
Posts: 37
Location: /dev/random
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


Top
 Profile  
 PostPosted: Sat May 17, 2008 3:45 am   

Joined: Fri May 16, 2008 4:58 am
Posts: 94
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


Top
 Profile  
 PostPosted: Mon May 19, 2008 11:18 pm   

Joined: Wed May 30, 2007 9:22 pm
Posts: 39
Location: California
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!


Top
 Profile  
 PostPosted: Tue Dec 01, 2009 2:40 am   

Joined: Fri May 16, 2008 4:58 am
Posts: 94
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


Top
 Profile  
 PostPosted: Tue Dec 01, 2009 3:05 am   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 512
You could play with tput (man tput; man 5 terminfo)
Code:
submenufunc() {
#...
"mainmenu") tput cuu 6
            tput ed
            break
;;
esac
done
}


Top
 Profile  
 PostPosted: Tue Dec 01, 2009 4:55 am   

Joined: Fri May 16, 2008 4:58 am
Posts: 94
Hm can't seem to get that working properly for some reason, do have an example?


Top
 Profile  
 PostPosted: Tue Dec 01, 2009 5:31 am   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 512
well, I gave you an example.

How doesn't it work ?


Top
 Profile  
 PostPosted: Wed Dec 02, 2009 1:58 pm   

Joined: Fri May 16, 2008 4:58 am
Posts: 94
Sorry, I included the code however it didn't make any difference


Top
 Profile  
 PostPosted: Thu Apr 01, 2010 2:08 pm   

Joined: Fri May 16, 2008 4:58 am
Posts: 94
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'


Top
 Profile  
 PostPosted: Fri Apr 02, 2010 2:36 am   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 512
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


Top
 Profile  
 PostPosted: Fri Apr 02, 2010 8:44 am   

Joined: Fri May 16, 2008 4:58 am
Posts: 94
Thanks but that still only gives 1 submenu?


Top
 Profile  
 PostPosted: Fri Apr 02, 2010 9:59 am   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 512
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?


Top
 Profile  
 PostPosted: Fri Apr 02, 2010 1:39 pm   

Joined: Fri May 16, 2008 4:58 am
Posts: 94
That does the same only 1 sub menu not main/sub/sub


Top
 Profile  
 PostPosted: Fri Apr 02, 2010 2:34 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 512
what's the third menu ?


Top
 Profile  
 PostPosted: Fri Apr 02, 2010 2:56 pm   

Joined: Fri May 16, 2008 4:58 am
Posts: 94
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


Top
 Profile  
 PostPosted: Fri Apr 02, 2010 4:43 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 512
hmm...
and what does fail when you do it?


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 17 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP