LinuxQuestions.org
Help answer threads with 0 replies.
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 12-18-2007, 07:08 PM   #1
Mysticle31
Member
 
Registered: Nov 2007
Location: California
Distribution: Xubuntu 7.10 Gutsy
Posts: 77

Rep: Reputation: 15
Can someone help me to create a script that works like this batch file?


I'm trying to create a script that I can run that will launch my XP installation in VirtualBox, pause while waiting for the XP to boot, login, and logout. Then when I hear the logout noise I designated, I can start rdesktop by pressing any key.

I've created somewhat of a windows equivalent of what I want to do. Can someone help me make this work in Linux?

Here's how I would do it if I was in windows.

Quote:
VBoxManage startvm "Windows XP" -type vrdp
@echo off
Starting Windows XP. Wait until you hear the noise and press any key to continue.
If you see "FAILED" and "A session for the machine 'Windows XP' is currently open" then press any key
pause
cls
@echo on
rdesktop -rsound -A -s "c:\seamlessrdp\seamlessrdpshell.exe C:\Windows\explorer.exe" 192.168.1.5:3389 -u "seamless" -p XXXXXXX
My XP installation is already configured to log in and log out by itself and play a special noise on logout so I know when it's ready to log in on my seamless account.

Then members of my family and I can run windows apps that I can't emulate in Wine fairly easily.
 
Old 12-18-2007, 07:17 PM   #2
GaijinPunch
Member
 
Registered: Aug 2003
Location: Tokyo, Japan
Distribution: Gentoo
Posts: 130

Rep: Reputation: 22
I think you're going to run into a problem where you need the script to automatically log in and log out. Generally VirtualBox will need to support some type of credentials file to read to get the login information, or something to this effect, (and I have no clue if it does or not).
 
Old 12-18-2007, 07:53 PM   #3
reddazz
LQ Guru
 
Registered: Nov 2003
Location: N. E. England
Distribution: Fedora, CentOS, Debian
Posts: 16,298

Rep: Reputation: 77
Moved: This thread is more suitable in the Programming forum and has been moved accordingly to help your thread/question get the exposure it deserves.
 
Old 12-18-2007, 07:54 PM   #4
Mysticle31
Member
 
Registered: Nov 2007
Location: California
Distribution: Xubuntu 7.10 Gutsy
Posts: 77

Original Poster
Rep: Reputation: 15
I don't need a script to log in an out.

I've already set up windows to do that upon boot up (starting of the VM)

I just need the script to start the VM, wait for XP to boot and log out, then when I hear the logout sound (all other sounds are disabled) I can can press a button and the script will continue.

This works if I do it manually. IE if I run the VM start command, wait for the noise, and run the rdesktop command.

I just want a script to do it all.
 
Old 12-18-2007, 07:55 PM   #5
Mysticle31
Member
 
Registered: Nov 2007
Location: California
Distribution: Xubuntu 7.10 Gutsy
Posts: 77

Original Poster
Rep: Reputation: 15
Thanks red, I didn't see a programing form, then again I didn't look very hard. Sorry about that, thanks!
 
Old 12-19-2007, 01:30 PM   #6
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,617

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
I think this bash script does the same as the batch file

Code:
#!/bin/bash
set -v
VBoxManage startvm "Windows XP" -type vrdp
set +v
echo Starting Windows XP. Wait until you hear the noise and press any key to continue.
read -n1 -p "If you see \"FAILED\" and \"A session for the machine 'Windows XP' is currently open\" then press any key"
clear
set -v
rdesktop -rsound -A -s "c:\seamlessrdp\seamlessrdpshell.exe C:\Windows\explorer.exe" 192.168.1.5:3389 -u "seamless" -p XXXXXXX
 
Old 12-20-2007, 01:31 AM   #7
Mysticle31
Member
 
Registered: Nov 2007
Location: California
Distribution: Xubuntu 7.10 Gutsy
Posts: 77

Original Poster
Rep: Reputation: 15
Awesome,

Thank you.

Although I find that the prompt doesn't work. However, I think I like it better this way because I can start windows, and then start windows apps by replacing explorer.exe with others by using two scripts. A start windows script and a start start menu script, or a start OneNote 2007 script.

It would be cool to have a gui that says press OK to continue after you hear the noise, or to start X application click one from the check box. However, this is WAY beyond my capabilities.

Thanks alot.

Now what does set-v and set+v do? What are the \ for?

Does anyone know how I can stop a headless Virtualbox?

I can run killall rdesktop to kill rdesktop, but I find that killall VBoxVRDP doesn't shutdown the OS (send the ATPI shutdown signal).

Last edited by Mysticle31; 12-20-2007 at 01:34 AM.
 
Old 12-20-2007, 12:39 PM   #8
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,617

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Quote:
Originally Posted by Mysticle31 View Post
Awesome,

Thank you.

Although I find that the prompt doesn't work. However, I think I like it better this way because I can start windows, and then start windows apps by replacing explorer.exe with others by using two scripts. A start windows script and a start start menu script, or a start OneNote 2007 script.
What exactly do you mean by "doesn't work"? Any error messages, etc.

Quote:
It would be cool to have a gui that says press OK to continue after you hear the noise, or to start X application click one from the check box. However, this is WAY beyond my capabilities.
Actually, it's not that hard:
Code:
xmessage -buttons 'okay:0,application X:2,application Y:3' 'press ok to continue after you hear the noise'
case $? in
   2) appx;;
   3) appy;;
esac
Quote:
Now what does set-v and set+v do? What are the \ for?
By default bash doesn't echo commands, set -v is like echo on, set +v is like echo off (note that the space is significant). The \'s are needed to escape the double quotes("). That is make them part of the string instead of ending the string.

Quote:
Does anyone know how I can stop a headless Virtualbox?

I can run killall rdesktop to kill rdesktop, but I find that killall VBoxVRDP doesn't shutdown the OS (send the ATPI shutdown signal).
From the docs of VirtualBox: VBoxManage controlvm <vm> savestate

Last edited by ntubski; 12-20-2007 at 12:41 PM.
 
Old 12-20-2007, 01:51 PM   #9
Mysticle31
Member
 
Registered: Nov 2007
Location: California
Distribution: Xubuntu 7.10 Gutsy
Posts: 77

Original Poster
Rep: Reputation: 15
Wow thank you. I'm going to have to play around with this a little bit.

By doesn't work, I mean that it doesn't prompt me to pause. The script just continues. I does what it's supposed to. It's just it launches the VM, does not pause, and tries to launch rdesktop (which fails because windows is not up)

Then when windows is up and makes it's logout noise I run the script again. It tries to start the VM (which fails because it's already running) and starts rdesktop (which succeeds because windows is booted up and at the login screen).
 
Old 12-20-2007, 02:02 PM   #10
Mysticle31
Member
 
Registered: Nov 2007
Location: California
Distribution: Xubuntu 7.10 Gutsy
Posts: 77

Original Poster
Rep: Reputation: 15
Wow the gui with buttons actually works really well.

Here is another one for you that probably really demonstrates I don't know what I'm doing :P

How do I make the buttons (appx lets say) plug in whatever executable I want (C:\Windows\NOTEPAD.EXE lets say) in the final rdesktop -rsound -A -s "c:\seamlessrdp\seamlessrdpshell.exe C:\Windows\explorer.exe" 192.168.1.5:3389 -u "seamless" -p XXXXXXX command instead of C:\Windows\explorer.exe?
 
Old 12-20-2007, 09:02 PM   #11
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,617

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Quote:
Originally Posted by Mysticle31 View Post
By doesn't work, I mean that it doesn't prompt me to pause. The script just continues. I does what it's supposed to. It's just it launches the VM, does not pause, and tries to launch rdesktop (which fails because windows is not up)

Then when windows is up and makes it's logout noise I run the script again. It tries to start the VM (which fails because it's already running) and starts rdesktop (which succeeds because windows is booted up and at the login screen).
That's weird, does the following exit immediately or wait for you to press a key?
Code:
#!/bin/bash
read -n1 -p "press any key"
Quote:
How do I make the buttons (appx lets say) plug in whatever executable I want (C:\Windows\NOTEPAD.EXE lets say) in the final rdesktop -rsound -A -s "c:\seamlessrdp\seamlessrdpshell.exe C:\Windows\explorer.exe" 192.168.1.5:3389 -u "seamless" -p XXXXXXX command instead of C:\Windows\explorer.exe?
Code:
#start with 2 because xmessage uses 1 to indicate errors.
#technically the [3]= and [4]= aren't needed, but it helps keep the name
#associated to the right path
APPS=([2]="C:\Windows\explorer.exe" [3]="C:\Windows\NOTEPAD.EXE" [4]="C:\bin\foo")
APPNAMES=([2]="Explorer(default)" [3]="Notepad" [4]="Foo")

BUTTONS="okay:2"
for appi in ${!APPSNAMES[@]}; do
  BUTTONS+=",${APPNAMES[$appi]}:$appi"
done


xmessage -default okay -buttons "$BUTTONS" 'press ok to continue after you hear the noise'
APP="${APPS[$?]}"

rdesktop -rsound -A -s "c:\seamlessrdp\seamlessrdpshell.exe $APP" 192.168.1.5:3389 -u "seamless" -p XXXXXXX
 
Old 12-21-2007, 12:24 PM   #12
Mysticle31
Member
 
Registered: Nov 2007
Location: California
Distribution: Xubuntu 7.10 Gutsy
Posts: 77

Original Poster
Rep: Reputation: 15
I found that this works quite well..

Code:
VBoxManage startvm "Windows XP" -type vrdp
#start with 2 because xmessage uses 1 to indicate errors.
#technically the [3]= and [4]= aren't needed, but it helps keep the name
#associated to the right path
APPS=([2]="C:\Windows\explorer.exe" [3]="C:\Windows\NOTEPAD.EXE" [4]="C:\bin\foo")
APPNAMES=([2]="Explorer" [3]="Notepad" [4]="Foo")

BUTTONS="Explorer:2"
for appi in ${!APPSNAMES[@]}; do
  BUTTONS+=",${APPNAMES[$appi]}:$appi"
done


BUTTONS="Notepad:3"
for appi in ${!APPSNAMES[@]}; do
  BUTTONS+=",${APPNAMES[$appi]}:$appi"
done

xmessage -buttons 'Explorer:2,Notepad:3' 'press ok to continue after you hear the noise'
APP="${APPS[$?]}"

rdesktop -rsound -A -s "c:\seamlessrdp\seamlessrdpshell.exe $APP" 192.168.1.5:3389 -u "seamless" -p seamless
I found that I didn't have but one button using the other "xmessage -default okay -buttons "$BUTTONS" 'press ok to continue after you hear the noise'"

Now what is happening here? what does appi do and APPSNAMES do? What does APP="${APPS[$?]}" do, why is there only one of them and not one for each app? Do I really need APPNAMES=([2]="Explorer"...) Is that what is being referenced?

Would it be easy to make the app buttons a radial list with a "Launch" button?

As to the batch file, it would just end, no prompt. I tried running it in the terminal to see what the output was, nothing. It was as if @echo off the whole time.
 
Old 12-22-2007, 06:10 PM   #13
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,617

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Okay, maybe I got too fancy, it's failing of mine.

First there's a typo in what I posted: should have
Code:
for appi in ${!APPNAMES[@]}; do
Quote:
Now what is happening here?
APPS and APPNAMES are both arrays. So ${APPS[2]} gets expanded to C:\Windows\explorer.exe, ${APPNAMES[2]} expands to Explorer. ${APPNAMES[@]} expands to all the indices that have values, in this case: 2 3 4.

The for sets appi to each value in the list so
Code:
for appi in ${!APPSNAMES[@]}; do
  BUTTONS+=",${APPNAMES[$appi]}:$appi"
done
has the effect of doing
Code:
BUTTONS+=",${APPNAMES[2]}:2"
BUTTONS+=",${APPNAMES[3]}:3"
BUTTONS+=",${APPNAMES[4]}:4"
The idea being, that after the loop BUTTONS should have the value okay:2,Explorer:2,Notepad:3,Foo:4.

Quote:
What does APP="${APPS[$?]}" do, why is there only one of them and not one for each app?
$? is the exit status of the previous command, so if you click the button labeled Explorer, xmessage exits with status 2, ${APPS[$?]} expands to ${APPS[2]}, which expands to C:\Windows\explorer.exe.

Quote:
Do I really need APPNAMES=([2]="Explorer"...) Is that what is being referenced?
Well I was trying to use APPNAMES for the labels on the buttons, but the typo screwed that up, so they weren't getting referenced at all. My idea was that to add a new program you just have to an entry in the APPS array and an entry in the APPNAMES array and it should all work...


Quote:
Would it be easy to make the app buttons a radial list with a "Launch" button?
Maybe with xdialog (you might need to install it first). I'm not sure what a radial list is, but at least one of those options has to be something like what you're looking for

Quote:
As to the batch file, it would just end, no prompt. I tried running it in the terminal to see what the output was, nothing. It was as if @echo off the whole time.
Well, like I said, by default bash doesn't echo commands as it exucutes them, but the command itself should have output something... What about the output of
Code:
#!/bin/bash
echo $BASH_VERSION
help -s read
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
How to create batch file? TigerLinux Linux - Newbie 16 09-26-2011 12:24 PM
Looking to Create User Accounts Using Batch Load Script wlue Linux - Newbie 3 12-17-2007 01:51 PM
How to convert a batch file(.bat) to script file(.sh) manas_sem Programming 4 06-28-2007 12:10 PM
To create a batch file to use with a mem stick al bernier Programming 2 10-30-2006 10:33 AM
How to create a batch file? Franziss Programming 8 05-16-2005 12:36 AM

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

All times are GMT -5. The time now is 09:58 PM.

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