Skip to content

Instantly share code, notes, and snippets.

@halleshubham
Last active September 3, 2018 11:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save halleshubham/4d69cd47a99a11c28fe8c618f4c28436 to your computer and use it in GitHub Desktop.
Save halleshubham/4d69cd47a99a11c28fe8c618f4c28436 to your computer and use it in GitHub Desktop.
BASH: Deploy and execute script on remote Linux node
#!/bin/bash
PASSWORD=<PASSWORD>
node=<IP>
# Copy to remote node
echo y | pscp -pw "${PASSWORD}" /path/to/Script.sh <user>@"$node":/tmp/Script.sh
# Move to required / accessible directory
echo y | plink -ssh -pw "${PASSWORD}" -t <user>@"$node" "sudo cp /tmp/Script.sh /required/path/"
# Convert to Linux BASH (if file edited in Windows)
plink -ssh -pw "${PASSWORD}" -t <user>@"$node" "sed -i 's/\r$//' /required/path/Script.sh"
# Sudo execute
echo y | plink -ssh -pw "${PASSWORD}" -t <user>@"$node" "sudo bash /required/path/Script.sh"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment