Troubleshooting whiptail


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Troubleshooting whiptail
# 1  
Old 08-12-2018
Troubleshooting whiptail

Here is a code snippet using whiptail , it fails to complete giving me long list of options available for whiptail .

That is great, but how do I determine which of the current opinions is wrong?
I did tried inserting comment (#) into options and it just did not work.
Deleting the option created another errors.


So in case of "checklist" - can I start with minimum code which would compile and then add "options" to it ?



Cheers



PS

My main problem using bash is having or not having spaces in right places.

That is hard on old eyes. Maybe that is the issue here.



Code:
    case $ADVSEL in
 108         1)
 109             echo "Option 1"
 110 pause 
 111             whiptail \
 112                 --title "checklist test Option 1" \
 113                 --checklist \
 114                 --separate-output "Choose: " 20 78 15 \ 
 115 
 116 "John" "" on \
 117 "Glen" "" off \
 118 "Adam" "" off 2>results
 119
 120  echo "HERE Option 1"
 121
 122 pause
 123
 124 while read choice
 pause
 123
 124 while read choice
 125 do
 126         case $choice in
 127                 John) firstroutine
 128                 ;;
 129                 Glen) secondroutine
 130                 ;;
 131                 Adam) thirdroutine
 132                 ;;
 133                 *)
 134                 ;;
 135         esac
 136 done < results
 137
 138 exitstatus=$?
 139 if [ $exitstatus = 0 ]; then
 140     echo "Test Status OK " $OPTION
 141 else
 142     echo "Test Status failed"
 143 fi

# 2  
Old 08-12-2018
I think it's you blank line at 115 and --separate-output placed in the middle of your --checklist options

This seems to work fine for me:

Code:
whiptail \
    --title "checklist test Option 1"  \
    --separate-output \
    --checklist "Choose: " 20 78 3 \
    "John" "" on  \
    "Glen" "" off  \
    "Adam" "" off 2> results


Last edited by Chubler_XL; 08-12-2018 at 05:51 PM..
# 3  
Old 08-12-2018
Yes,

blank line causes problem , but I get a specific error now


Code:
 #pause 
  55  whiptail \
  56  --title "$1"  \
  57
  58  --checklist  "Choose: " 20 78 15 \
  59  "$2" "" on  \
  60  "Glen" "" off \
  61  "Adam" "" off
  62




Code:
/usr/bin/raspi-config-DEBUG.sh: 58: /usr/bin/raspi-config-DEBUG.sh: --checklist: not found
Test Status OK 
Press [Enter] key to continue..


Funny
all sample codes have same issue with mixing
these
--separate-output \ --checklist "Choose: " 20 78 3 \

I am not using --separate_output for now

Thanks for reply I'll mark it solved as soon as I solve the multiple
redirections issues. See below.

Code:
 2>results
  64  # redirected whiltail output "choice"  to results
  65  # where is choise  defined ? 
  66  # echo "HERE Option 1"
  67  #pause
  68  # TODO functions do not execute 
  69 while read choice
  70  do
  71          case $choice in
  72                  John) firstroutine
  73                  ;;
  74                  Glen) secondroutine
  75                  ;;
  76                  Adam) thirdroutine
  77                  ;;
  78                  *)
  79                  ;;
  80          esac
  81  done < results
  82  exitstatus=$?

------ Post updated at 09:03 PM ------

OK, I a





Code:
 "$4" "" off  2>choice
  83  echo "cat< choise get contents of choice file  print it" Y
  84  cat<choice     #TOK  here 
  85 echo "cat choise " 
  86 pause 
  87 echo "while read  file  choice "
  88 pause 
  89 while read choice
  90  do
  91          case $choice in
  92                  "$2") 
  93                         echo " first selection " 
  94                         firstroutine
  95                  ;;

------ Post updated at 09:20 PM ------

OK, here is an update.
I understand whiptail puts the selection result in file - in my case "choices".
I can check the contents with cat.



Now how do I check line 89?

It is not doing anything and I do not know how to verify its function.



Code:
 "$4" "" off  2>choices
  83  echo "cat< choise get contents of choice file  print it" Y
  84  cat<choices     #TOK  here 
  85 echo "cat choises " 
  86 pause 
  87 echo "while read  file  choices "
  88 pause 
  89 while read choices
  90  do
  91          case $choice in
  92                  "$2") 
  93                         echo " first selection " 
  94                         firstroutine
  95                  ;;
  96                  $3) secondroutine
  97                  ;;
  98                  $4) thirdroutine
  99                  ;;
 100                  *) 
 101                         echo " default selection " Y
 102                  ;;
 103          esac
 104  done < results
 105  exitstatus=$?
 106  if [ $exitstatus = 0 ]; then
 107      echo "Exit file read Test Status OK " $choice
 108  else
 109      echo "Exit Test Status failed"
 110  fi

# 4  
Old 08-13-2018
on line 104 you are reading the contents of file results and whiptail output is being re-directed to file choices.

Note that this file name will cause issues if you have 2 processes running the script at the same time. Can I suggest you use /tmp to store the output file and give it a unique name eg using $$ for the process ID eg:


Code:
whiptail \
    --title "checklist test Option 1"  \
    --separate-output \
    --checklist "Choose: " 20 78 3 \
    "John" "" on  \
    "Glen" "" off  \
    "Adam" "" off 2> /tmp/wtout_$$

while read choice
do
    case $choice in
        John)
...
   esac
done < /tmp/wtout_$$

# clean up temp file
rm /tmp_wtout_$$

# 5  
Old 08-13-2018
Moderator's Comments:
Mod Comment Thread title changed from "Troubleshoting whiptail" to "Troubleshooting whiptail".
This User Gave Thanks to Don Cragun For This Post:
# 6  
Old 08-13-2018
Quote:
Originally Posted by Chubler_XL
on line 104 you are reading the contents of file results and whiptail output is being re-directed to file choices.

Note that this file name will cause issues if you have 2 processes running the script at the same time. Can I suggest you use /tmp to store the output file and give it a unique name eg using $$ for the process ID eg:


Code:
whiptail \
    --title "checklist test Option 1"  \
    --separate-output \
    --checklist "Choose: " 20 78 3 \
    "John" "" on  \
    "Glen" "" off  \
    "Adam" "" off 2> /tmp/wtout_$$


I this is my problem 

where does "choice" file come in ?

I am missing / do not understand 

the relations between whiptail and choice file.  
 


 Perhaps renaming the file as "selections" after I know more about the interactions
of the code. 



 while read choice
do
    case $choice in
        John)
...
   esac
done < /tmp/wtout_$$

# clean up temp file
rm /tmp_wtout_$$


Last edited by annacreek; 08-13-2018 at 02:12 PM..
# 7  
Old 08-13-2018
Whiptail produces output on stderr that indicates the interactions taken by the user. Your script works by redirecting this output to a file as hi-lighted below:

Code:
whiptail \
    --title "checklist test Option 1"  \
    --separate-output \
    --checklist "Choose: " 20 78 3 \
    "John" "" on  \
    "Glen" "" off  \
    "Adam" "" off 2> whiptail.out

Run the above code and make various choices in the dialog and then check the contents of the whiptail.out file.

So after the user has selected their preferences these need to be read in from the file and acted upon.

Code:
while read choice
do
    echo "Line read: $choice"
done < whiptail.out

The above code fragment loops for each line of the file whiptail.out setting the variable choice to the contents of the line.

You can take particular actions based on the file contents using something like a case statement within the while loop eg:

Code:
case $choice in
    John)
          echo "User selected John"
   ;;
   Glen)
         echo "User selected Glen"
   ;;
   *)
         echo "User selected $choice - which in neither John or Glen"
   ;;
esac

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing positioning array as whiptail -- menu option

I may have asked this before, so forgive OF. Problem: I can pass positioning array as -- menu option to whiptail, but it does not show in the whiptail form as an array - only single (first member "lsusb" ) entry / line shows up. Code: DynamicEntry=$(whiptail \ --title "DEBUG... (1 Reply)
Discussion started by: annacreek
1 Replies

2. Shell Programming and Scripting

Use positional parameters in loop / while syntax in whiptail

I like to “optimize” / make more like a real program my bash script by replacing repetitious code which utilizes positional parameters. I am having two issues I cannot solve and would appreciate some assistance with resolving them. a) how to modify the whiptail checklist... (3 Replies)
Discussion started by: annacreek
3 Replies

3. Shell Programming and Scripting

Redirecting stdout output to whiptail menu box

As a result of whiptail menu option I am getting a data from a file. Naturally it is output to terminal as stdour. I like to redirect the output back to the menu. It can be done with single input of line of text , see attached. I just cannot see where or how the sample... (0 Replies)
Discussion started by: annacreek
0 Replies

4. Shell Programming and Scripting

Whiptail "Command not found"

Evening, I'd like to point out I am very much new to anything regarding scripting, so I apologize If I am / will ask stupid questions. I am currently trying to design a script that will completely setup a server for a group that needs one, so that they can have a easy way of getting up and... (8 Replies)
Discussion started by: KeyXMakerX
8 Replies

5. Shell Programming and Scripting

Bash Script - Whiptail Menu Help!

Hello, Been trying to build a menu with whiptail lately. However, my code doesn't seems to be working even though when i compared to other similar code they looks the same. #!/bin/bash clear whiptail --msgbox "Entering networking sub-menu" 20 78 whiptail --title Networking --menu... (8 Replies)
Discussion started by: malfolozy
8 Replies

6. Shell Programming and Scripting

Whiptail menu, getting back the variable

Hi all Only learning so if any mistakes, let me know I am trying to create a menu box with Whiptail, taking in the variables from a txt.file called Name.txt which has just 4 names listed for now, one below each other..ie Dave John Mike Mary Bash script is below and calls the txt... (8 Replies)
Discussion started by: olearydc
8 Replies

7. IP Networking

TCP/IP troubleshooting

Hello all, Can somebody please tell what is the best book out there that can help me learn TCP troubleshooting and understaning the TCP options like window scaling, large receive offload? I would like to understand how all the TCP tuning parameters function. Is there a book out there that can... (4 Replies)
Discussion started by: Pouchie1
4 Replies

8. Shell Programming and Scripting

Questions: whiptail --passwordbox

I have a question regarding "whiptail utility" in Linux. I have the following whiptail command within a script: #!/bin/sh whiptail --passwordbox " Password " 10 40 I would like to know Where does it store the password when the script is run? Does it go to any particular file? How... (1 Reply)
Discussion started by: Vabiosis
1 Replies

9. Red Hat

whiptail --password : How does it work?

I have a question regarding "whiptail utility" in Linux. I have the following whiptail command within a script: #!/bin/sh whiptail --passwordbox " Password " 10 40 I would like to know Where does it store the password when the script is run? Does it go to any particular file? How... (1 Reply)
Discussion started by: Vabiosis
1 Replies

10. Solaris

help troubleshooting

Hi. I have a Solaris 10 server that's taking about 20secs to respond to telnet or ftp commands. Has anyone ever seen something like that? Can you tell me where to start troubleshooting please? I logged in and did a prtstat, but nothing is jumping out as an issue. (8 Replies)
Discussion started by: bbbngowc
8 Replies
Login or Register to Ask a Question