-2

I have a web application that generates a shell script with commands running on a server.

Then I also have another Linux server where the script should be executed.

I was wondering if someone could point me in the right direction in terms of how I could send a shell script from one server to another linux server and execute it on the second server?

user1144596
  • 2,068
  • 8
  • 36
  • 56

2 Answers2

0

You can use scp to transfer the file over

scp <source_file> <destination>

if your destination is the host in question:

scp myfile.sh username@x.x.x.x:/path/to/new/script.sh

For executing on the server, you have various options. You can use a cron job to execute it periodically. You can use rc.local to execute at startup. You can use ssh.

Lets take SSH as an example:

ssh username@x.x.x.x 'sh /path/to/script.sh' 

The above ssh command will run myfile.txt on the server.

efel
  • 1,054
  • 3
  • 14
  • 29
0

for linux machines easiest way is

ssh root@MachineB 'bash -s' < local_script.sh 

as explained in Jason R. Coombs's answer

Community
  • 1
  • 1
eyalore
  • 21
  • 1
  • 3