We help IT Professionals succeed at work.

restart mysql server on linux from windows box via batch file?

musickmann asked
Okay, I'm not a hardcore linux user, just know enough to manage a box or two. I've got a database server running a database for a Moodle installation, and every so often the web server running the moodle program can't connect to the database server (2 separate boxes), this happened for the first time since I've taken over the management of the server today, but I know it's happened to them before and they just did a hard restart on the box since no one there can work linux. Anyway, I'm trying to figure out the issue with the database,but log files are no help bla bla bla..

So, what I need is the ability to allow someone at the company to run the serve mysql restart command from their windows machine. As it stands now, I have to VPN into the network then SSH into the linux box to restart the service, and if I'm not at my computer then it's a PITA to do it remotely. So.... I'm looking for a way to essentially create a batch file that will connect to the database server and run that restart command.

I don't even know where to begin, or what to search for, as the searches I've run all come up with running a windows batch from a linux machine, and I need the opposite direction.

Watch Question

I think the easiest way to accomplish this would be:

1) Create a user account for whoever will restart the service

2) Allow that user to restart the service without becoming root via sudoers file

3) Create a script on the linux machine to restart the service (so the user does not have to remember the command)

There is no way to run a command on linux from the windows server unless you use some sort of ssh client (putty).  Also only root or someone with root privileges can restart a service.
musickmannData Analyst


Okay. I'm trying to setup a line in the sudoers file, and I'm getting a suyntax error, any chance you can help, I thought I followed everything in the manuals and such, but not sure what I'm missing...

Here is the line I added:
user ALL=NOPASSWD: /sbin/service mysql restart

I Get an error that service: command not found?
musickmannData Analyst


NEvermind, I got it to work. It had to do with the way I Was calling the service from the user. I wasn't specifying the path.

Also, I found reference to plink with Putty, so I think it actually is possible to run a command on a linux box from a windows batch file...trying that now...
Yes its possible but it will still be through the ssh connection via putty.

Good luck!

I might suggest using Cygwin (cygwin.com), then you can even do other complex kinds of things, all with bash scripting.
For example, to execute a bash script in Windows with a shortcut, you just have it point to something like this:
C:\cygwin\bin\bash.exe "/path/to/my/script.sh"
musickmannData Analyst
cygwin would take some looking into, it's a solution I hadn't considered.

I was able to get the plink thing to work, but I had to deactivate the requiretty for that user. Not a big deal since the user can only access the restart mysql as sudo, but not ideal I'm sure.

musickmannData Analyst


savone got me on the right track, the plink program allows me to run the command from a windows batch file, so it's easiest for the client to click an icon.