LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-08-2014, 12:41 PM   #1
johndoe777
LQ Newbie
 
Registered: Aug 2014
Location: New York City
Distribution: debian wheezy, but I add Kali to my repositories list
Posts: 16

Rep: Reputation: Disabled
Unhappy shell script with dialog box


I don't know if this is the right place to ask my question because it might be a software issue.
Anyway I have debian wheezy installed on my computer but I am using the kernel 3.14 amd64 and wheezy backports software repository. I am trying to run what I thought was a simple script involving KVM and the dialog program for input type boxes. For some reason I can't get the script to run on my computer. Here is the script:
#!/bin/bash

#this will launch your virtual machines with a graphical menu
#in your terminal
cd /home/lilbit/Qemu # my directory with virtual disk drives


dialogue --backtitle "KVM Virtualization Launcher" --title "Main\
Menu" --menu "Move using [UP] [DOWN], [ENTER] to Select" 15 50 10\
deb1_HDA.img "Launches deb1"\
deb2_HDA.img "Launches deb2"\
deb3_HDA.img "Launches deb3" 2>/tmp/menuitem.$$

menuitem=`cat /tmp/menuitem.$$`


case $menuitem in
deb1_HDA.img) kvm -hda deb1_HDA.img -m 256 -smp 2 -net nic -net tap,ifname=tap0,script=no,downscript=no;;
deb2_HDA.img) kvm -hda deb2_HDA.img -m 256 -smp 2 -net nic -net tap,ifname=tap0,script=no,downscript=no;;
deb3_HDA.img) kvm -hda deb3_HDA.img -m 256 -smp 2 -net nic -net tap,ifname=tap0,script=no,downscript=no;;
esac

I get absolutely no error messages or anything back to tell me anything is wrong here but I can't see anything executing is my script OK?

PLease help, I am trying to make something easy for a friend to use and simply launch their virtualizations.
 
Old 09-08-2014, 12:54 PM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,869
Blog Entries: 1

Rep: Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870
Please use [code] and [/code] tags.

Are you running this script from a terminal window? If not, then do so. You might even do this:
Code:
bash -xv name-of-yourscript.sh
 
Old 09-08-2014, 01:16 PM   #3
johndoe777
LQ Newbie
 
Registered: Aug 2014
Location: New York City
Distribution: debian wheezy, but I add Kali to my repositories list
Posts: 16

Original Poster
Rep: Reputation: Disabled
I did what you said and got some output:

#!/bin/bash

#this will launch your virtual machines with a graphical menu
#in your terminal
cd /home/lilbit/Qemu # my directory with virtual disk drives
+ cd /home/lilbit/Qemu


dialogue --backtitle "KVM Virtualization Launcher" --title "Main\
Menu" --menu "Move using [UP] [DOWN], [ENTER] to Select" 15 50 10\
deb1_HDA.img "Launches deb1"\
deb2_HDA.img "Launches deb2"\
deb3_HDA.img "Launches deb3" 2>/tmp/menuitem.$$
+ dialogue --backtitle 'KVM Virtualization Launcher' --title MainMenu --menu 'Move using [UP] [DOWN], [ENTER] to Select' 15 50 10deb1_HDA.img 'Launches deb1deb2_HDA.img' 'Launches deb2deb3_HDA.img' 'Launches deb3'

menuitem=`cat /tmp/menuitem.$$`
cat /tmp/menuitem.$$
++ cat /tmp/menuitem.1772
+ menuitem='virt-launcher.sh: line 8: dialogue: command not found'


case $menuitem in
deb1_HDA.img) kvm -hda deb1_HDA.img -m 256 -smp 2 -net nic -net tap,ifname=tap0,script=no,downscript=no;;
deb2_HDA.img) kvm -hda deb2_HDA.img -m 256 -smp 2 -net nic -net tap,ifname=tap0,script=no,downscript=no;;
deb3_HDA.img) kvm -hda deb3_HDA.img -m 256 -smp 2 -net nic -net tap,ifname=tap0,script=no,downscript=no;;
esac
+ case $menuitem in

and after reading the part that says: + menuitem='virt-launcher.sh: line 8: dialogue: command not found' I went back and changed dialogue to dialog because I think that is the correct name and ran it again with bash -xv and received the reply:
menuitem=`cat /tmp/menuitem.$$`
cat /tmp/menuitem.$$
++ cat /tmp/menuitem.1765
+ menuitem='
Error: Expected 2 arguments, found only 1.
Use --help to list options.'


case $menuitem in
deb1_HDA.img) kvm -hda deb1_HDA.img -m 256 -smp 2 -net nic -net tap,ifname=tap0,script=no,downscript=no;;
deb2_HDA.img) kvm -hda deb2_HDA.img -m 256 -smp 2 -net nic -net tap,ifname=tap0,script=no,downscript=no;;
deb3_HDA.img) kvm -hda deb3_HDA.img -m 256 -smp 2 -net nic -net tap,ifname=tap0,script=no,downscript=no;;
esac
+ case $menuitem in

I don't understand what it means when it is expecting 2 args but found only 1

Thanks for the reply though.
 
Old 09-08-2014, 01:37 PM   #4
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,869
Blog Entries: 1

Rep: Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870
What is difficult with using [code] and [/code] tags?
 
Old 09-08-2014, 01:50 PM   #5
johndoe777
LQ Newbie
 
Registered: Aug 2014
Location: New York City
Distribution: debian wheezy, but I add Kali to my repositories list
Posts: 16

Original Poster
Rep: Reputation: Disabled
I don't know how and am not too sure what you mean so does that mean I'm screwed on the help here?
 
Old 09-08-2014, 02:03 PM   #6
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,869
Blog Entries: 1

Rep: Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870
Please read this topic first: http://www.linuxquestions.org/questi...gs-4175464257/

Edit:
Here is an example:

[code]
Code:
bash -xve virt-launcher.sh
[/code]

Last edited by NevemTeve; 09-08-2014 at 02:13 PM.
 
Old 09-08-2014, 02:16 PM   #7
johndoe777
LQ Newbie
 
Registered: Aug 2014
Location: New York City
Distribution: debian wheezy, but I add Kali to my repositories list
Posts: 16

Original Poster
Rep: Reputation: Disabled
Ok let's try again I am using Bash to write a shell script.
here is the script
Code:
#!/bin/bash                                                                                                                                                             

#this will launch your virtual machines with a graphical menu                                                                                                           
#in your terminal                                                                                                                                                       
cd /home/<username>/Qemu # my directory with virtual disk drives                                                                                                            


dialog --backtitle "KVM Virtualization Launcher" --title "Main\                                                                                                         
Menu" --menu "Move using [UP] [DOWN], [ENTER] to Select" 15 50 10\
deb1_HDA.img "Launches deb1"\
deb2_HDA.img "Launches deb2"\
deb3_HDA.img "Launches deb3" 2>/tmp/menuitem.$$

menuitem=`cat /tmp/menuitem.$$`
opt=$?

case $menuitem in
    deb1_HDA.img) kvm -hda deb1_HDA.img -m 256 -smp 2 -net nic -net tap,ifname=tap0,script=no,downscript=no;;
    deb2_HDA.img) kvm -hda deb2_HDA.img -m 256 -smp 2 -net nic -net tap,ifname=tap0,script=no,downscript=no;;
    deb3_HDA.img) kvm -hda deb3_HDA.img -m 256 -smp 2 -net nic -net tap,ifname=tap0,script=no,downscript=no;;
esac
I then tried your suggestion of
Code:
bash -xv virt-launcher.sh
and I received the output of
Code:
menuitem=`cat /tmp/menuitem.$`
cat /tmp/menuitem.$
++ cat '/tmp/menuitem.$'
+ menuitem='
Error: Expected 2 arguments, found only 1.
Use --help to list options.'
opt=$?
+ opt=0

case $menuitem in
    deb1_HDA.img) kvm -hda deb1_HDA.img -m 256 -smp 2 -net nic -net tap,ifname=tap0,script=no,downscript=no;;
    deb2_HDA.img) kvm -hda deb2_HDA.img -m 256 -smp 2 -net nic -net tap,ifname=tap0,script=no,downscript=no;;
    deb3_HDA.img) kvm -hda deb3_HDA.img -m 256 -smp 2 -net nic -net tap,ifname=tap0,script=no,downscript=no;;
esac
+ case $menuitem in
please explain to many what I am missing here I don't understand what is being expressed in the error message of expected 2 args, found 1

Greatly appreciated
 
Old 09-08-2014, 02:21 PM   #8
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,869
Blog Entries: 1

Rep: Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870
You seems to have manually edited the script and/or the output (eg changing between ' and `), please don't do that. Next try option -e too:

Code:
bash -xve virt-launcher.sh
 
Old 09-08-2014, 02:34 PM   #9
johndoe777
LQ Newbie
 
Registered: Aug 2014
Location: New York City
Distribution: debian wheezy, but I add Kali to my repositories list
Posts: 16

Original Poster
Rep: Reputation: Disabled
I ran the command again
Code:
bash -xve virt-launcher.sh
this time got the output
Code:
#!/bin/bash

#this will launch your virtual machines with a graphical menu 
#in your terminal
cd /home/lilbit/Qemu # my directory with virtual disk drives
+ cd /home/lilbit/Qemu


dialog --backtitle "KVM Virtualization Launcher" --title "Main\
Menu" --menu "Move using [UP] [DOWN], [ENTER] to Select" 15 50 10\
deb1_HDA.img "Launches deb1"\
deb2_HDA.img "Launches deb2"\
deb3_HDA.img "Launches deb3" 2>/tmp/menuitem.$$
+ dialog --backtitle 'KVM Virtualization Launcher' --title MainMenu --menu 'Move using [UP] [DOWN], [ENTER] to Select' 15 50 10deb1_HDA.img 'Launches deb1deb2_HDA.img' 'Launches deb2deb3_HDA.img' 'Launches deb3'
 
Old 09-08-2014, 02:53 PM   #10
johndoe777
LQ Newbie
 
Registered: Aug 2014
Location: New York City
Distribution: debian wheezy, but I add Kali to my repositories list
Posts: 16

Original Poster
Rep: Reputation: Disabled
I figured out my problem thanks for the pointers on how to debug though I just had to rewrite my section about the dialog box as a single line instead of all the backslashes. I guess I didn't understand what the purpose of those \'s was. I am just learning this stuff by looking at a website. So, I got no clue about a lot of what I see.
 
Old 09-09-2014, 11:33 AM   #11
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,008

Rep: Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193
Here is a working example of the dialog options with multi-line entries:
Code:
dialog --backtitle "KVM"  \
       --title     "Main" \
       --menu      "Move using [UP] [DOWN], [ENTER] to Select" \
       15 50 10 \
       deb1_HDA.img "Launches deb1" \
       deb2_HDA.img "Launches deb2" \
       deb3_HDA.img "Launches deb3"
Or perhaps a cleaner alternative:
Code:
dialog_items=( --backtitle "KVM"
               --title     "Main"
               --menu      "Move using [UP] [DOWN], [ENTER] to Select"
               15 50 10
               deb1_HDA.img "Launches deb1"
               deb2_HDA.img "Launches deb2"
               deb3_HDA.img "Launches deb3"
             )

dialog "${dialog_items[@]}"
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script dialog box question unclesamcrazy Linux - Newbie 14 10-14-2013 04:58 AM
shell script using dialog box sharma.kashyap Linux - General 2 04-13-2007 08:28 AM
Need help creating/using a password dialog box for an Expect script crazygyhrous Linux - General 1 12-13-2005 11:48 AM
shell script with dialog sqn Programming 3 04-08-2004 02:25 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:23 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration