1

I wrote a bash script for my use and it works. I want that script to be put in some server in my network and call that script in laptops / desktops in my network itself to execute. Any way I have made a way for that also as below.

Steps:

  1. Install Apache web server in local server.
  2. Put the script in web server.
  3. Make the script executable chmod a+x.
  4. Open terminal in the client machine and install the package curl
  5. Now from the client terminal itself execute the command as:

    sudo curl -kL http://serverip/script.sh | bash
    

It works fine but only problem is, in my script I have used User input commands like "read variable", that doesn’t work in this scenario. So how to do that is my problem. Is there any way for me ?

3
  • Why don't you use ssh? Mar 31, 2014 at 8:39
  • yea , i already looked into it but I dont want to disclose the user credentials to ssh to the server , so y hosted in a webserver to access all in my network. But now I am thinking of creating a demo user with no password so that any one in my network can ssh with out password and more over I will give own to that demo user only .
    – SAGAR
    Mar 31, 2014 at 10:03
  • How can we help if you don't show the script? Is it expecting interactive input from the user?
    – terdon
    Mar 31, 2014 at 18:15

3 Answers 3

1

You can use:

bash -c "$(curl -kL http://serverip/script.sh)"

This will run the script on the local machine. See also man bash to understand why I used -c option. Also double quotes are very important in this case.

Also, as @terdon said in his comment, sudo curl is pointless. If If the script needs local sudo permissions, you need to use sudo in front of bash command.

3
  • 1
    Why the sudo? If the script needs local sudo permissions, you want sudo bash, running sudo curl is pointless.
    – terdon
    Mar 31, 2014 at 17:58
  • @terdon I just used the OP's original command. I didn't think too much at this aspect. But yes, is pointless. Mar 31, 2014 at 18:06
  • Yup , this is very great use for me . This is what I am looking for bash -c "$(......" great help bro.
    – SAGAR
    Apr 1, 2014 at 13:21
1

I think what you want is

wget http://server.com/scriptname.sh && bash scriptname.sh

That will simply download the script locally and run it.

1
  • No dude , I dodnt want all to download my script in their local machine . I got the answer . Thanks for the effort
    – SAGAR
    Apr 1, 2014 at 13:22
0

As suggested in Radu's comment, why not using ssh to start your script from your local server?

First install openssh-server on your client system:

sudo apt-get install openssh-server

Then from your local server:

ssh -t client_login@client_ip '/path_to_your_script/script.sh'

The -t option in the ssh -t command force pseudo-tty allocation.

1
  • Yup , thats a fine alternative , and I know it but my point is that , I dont want to disclose the user credentials to ssh to the server , so y hosted in a webserver to access all in my network. But now I am thinking of creating a demo user with no password so that any one in my network can ssh with out password and more over I will give own to that demo user only . Yup
    – SAGAR
    Mar 31, 2014 at 10:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .