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?
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.
for linux machines easiest way is
ssh root@MachineB 'bash -s' < local_script.sh
as explained in Jason R. Coombs's answer
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.