I have a bash script on a ubuntu 10.4 machine. It is shared and I can access it from my win7 machine with \\LINUX-SERVER\bash_repo\make-live

However when I do, windows tries to open it. This is not what I want. I want to tell ubuntu to execute it.

I am actually hoping to be able to build a GUI app on windows where the user clicks a button and it tells the bash script on the ubuntu machine to execute.

Is any of this possible?

  • How about installing a web server on ubuntu? You can invoke your script within a PHP/perl page. – Khaled Dec 29 '10 at 15:23
  • @Khaled I do have Apache on my ubuntu machine. Why don't you elaborate a little more on how I would execute it from PHP. Thanks!! – JD Isaacks Dec 29 '10 at 15:26
  • Check the answer below. – Khaled Dec 29 '10 at 16:00
  • If this is resolved please mark the answer below – JamesBarnett May 23 '11 at 9:18

Have you tried plink from the makers of PuTTY? http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

You should be able to run the script on the ubuntu machine like:

plink.exe -ssh -pw pass -noagent user@linux-server /path/to/your/script/make-live
  • Wow this is wierd. The script I am trying to execute has 2 parts. part one requires sudo, part 2 echos a message. The message gets echoed but part one does not run instead I get this: sudo: no tty present and no askpass program specified But I think that is a different problem. So I'll still mark you correct if no other better solutions come. thanks! – JD Isaacks Dec 29 '10 at 15:40
  • 2
    @John: Try plink -t ... to allocate a pty. – Dennis Williamson Dec 29 '10 at 16:15

As others have suggested you could use ssh to get a CLI session or wrap it in an accessible program, however that you can access it as a network share implies that Samba is configured and running - and there are numerous ways of getting Samba to execute files (e.g. magic script, winpopups, svcctl) rtfm for more details.


As suggested by my comment above, you can execute your script from PHP if you have a web server running on your ubuntu machine.

A small PHP script like the following will be enough:

$output = shell_exec('bash /path/to/your/script');
echo "$output";

Save the PHP code in a file such as /var/www/exec.php and point your browser from any machine to the URL http://your_ubuntu_machine_ip/exec.php.

Please, note that the script will be executed as www-data user (the default apache web server user). If you want to run a privileged command using sudo, you need to add www-data user to sudoers file using visudo.

You need an entry like:

www-data   ALL=NOPASSWD: /path/to/command
  • Thank you I am getting very close to what I want to do. I am having trouble with add www-data user to sudoers part. Can you please elaborate. visudo using vi which I have never used so I used export EDITOR=gedit && sudo -E visudo but that just opened an empty sudoers.tmp file. Do I add something to this file? if so what? Thank you! – JD Isaacks Dec 29 '10 at 16:20
  • 2
    -1 a php script is overly complex IMHO. plink of another commandline tool is preferable. Not to mention I'm not sure if it's even a good idea from a security point of view. – JamesBarnett Dec 31 '10 at 8:18
  • @JamesBarnett: It is not complicated! The OP already has apache installed and running. A simple PHP script will be enough to do it. It provides an easy way to execute your scripts remotely and it will not impose a security risk if it was secured in a good way. For example, you can use https instead of http if it will be invoked across an insecure network. – Khaled Dec 31 '10 at 16:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.