Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Net::SSH - starting mysql but need to press enter

Status
Not open for further replies.

jollyroger

Technical User
Mar 22, 2001
77
0
0
GB
Hi
Strange or not this is the problem I am having (it is not a problem but is to my method of wanting to do something!!!).
I want to start MySQL without having to press enter after having run the "bin/mysqld_safe --user=mysql &" command.
This may seem silly but I am running the command to start the database remotely using ssh, thus "ssh <machinename> /usr/local/bin/sudo /sbin/init.d/mysqld start" (prior to a backup stopping it is fine naturally because I am doing a kill -15 on the pid). However my SSH Shell created here wants me to press enter (thus this does not return to the prompt and therefore it just hangs).
Even if I enter the command to start and stop the Database locally I still have to press "Enter" after running the script to drop me back to the prompt.
Any suggestions would be welcome and tried.
 
Is this on a Windows machine?

If so, I could suggest Win32::GuiTest. It's a module to simulate mouse clicks and keystrokes (among many other things) and might help with your problem.

Code:
use Win32::GuiTest qw(:all);

# Find the Perl console window
# (edit this to match the window title)
my @dos = FindWindowLike (undef,'C:\\usr\\bin\\perl.exe',undef);

foreach my $console (@dos) {
   # send "Enter" to this console
   SendKeys ('{ENTER}');
}

If your process is being held up by the mysql asking you to press enter, you can spawn a new thread prior to it asking.

Code:
use threads;

#... your code...

# spawn a new thread
my $t = threads->create (sub {
   use Win32::GuiTest;

   # that code I posted above
});
$t->detach; # main process doesn't care about this thread

# now you make your SQL requests

When using threads though, the original code with Win32::GuiTest might want to do a while loop, since the threads will be asynchronous. If the new thread ran through its code and finished before SQL needed you to hit enter, it wouldn't do any good.
 
Nice suggestion but alas I am running HP-UX.
Best regards
Ben
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top