These shell commands perform the following actions: create a directory and execute a command if it doesn't exist, copy files using Secure Copy (SCP) from a local directory to a remote EC2 instance, using private key authentication. The commands copy different patterns of files using SCP, including https_www_googleapis, client_secret, and aws-sdk files.
npm run import -- "copy credentials"npm run ssh -t "mkdir ~/.credentials || true" \
&& scp -i ~/.credentials/selenium.pem \
~/.credentials/https_www_googleapis* ubuntu@ec2-54-201-232-148.us-west-2.compute.amazonaws.com:~/.credentials/ \
&& scp -i ~/.credentials/selenium.pem \
~/.credentials/client_secret* ubuntu@ec2-54-201-232-148.us-west-2.compute.amazonaws.com:~/.credentials/ \
&& scp -i ~/.credentials/selenium.pem \
~/.credentials/aws-sdk* ubuntu@ec2-54-201-232-148.us-west-2.compute.amazonaws.com:~/.credentials/ \
bash
#!/bin/bash
# Define credentials directory and upload files to remote server
REMOTE_SERVER="ec2-54-201-232-148.us-west-2.compute.amazonaws.com"
REMOTE_USER="ubuntu"
# Create credentials directory on remote server if it doesn't exist
ssh -t "$REMOTE_USER@$REMOTE_SERVER" "mkdir -p ~/.credentials || true"
# Define file patterns to upload
UPLOAD_FILES=(
"~/.credentials/https_www_googleapis*"
"~/.credentials/client_secret*"
"~/.credentials/aws-sdk*"
)
# Define private key file
PRIVATE_KEY="~/.credentials/selenium.pem"
# Upload files to remote server
for file_pattern in "${UPLOAD_FILES[@]}"; do
scp -i "$PRIVATE_KEY" "$file_pattern" "$REMOTE_USER@$REMOTE_SERVER:~/.credentials/"
done
# TODO: Consider using a more secure way to handle private keys and credentials
# Such as using a key management service or encrypting the credentialsCode Breakdown
Command 1: Create directory and execute command if it doesn't exist
npm run ssh -t "mkdir ~/.credentials || true"
npm run ssh: Run an SSH command using npm.-t: Enable pseudo-terminal (PTY) allocation.mkdir ~/.credentials || true: Create a directory named .credentials in the home directory if it doesn't exist.Command 2: Copy files using SCP
scp -i ~/.credentials/selenium.pem \
~/.credentials/https_www_googleapis* ubuntu@ec2-54-201-232-148.us-west-2.compute.amazonaws.com:~/.credentials/
scp: Secure copy command.-i ~/.credentials/selenium.pem: Use the private key file named selenium.pem for authentication.~/.credentials/https_www_googleapis*: Copy files starting with https_www_googleapis from the local .credentials directory.ubuntu@ec2-54-201-232-148.us-west-2.compute.amazonaws.com:~/.credentials/: Copy the files to the remote .credentials directory on the specified EC2 instance.Command 3 and 4: Copy files using SCP (similar to Command 2)
scp -i ~/.credentials/selenium.pem \
~/.credentials/client_secret* ubuntu@ec2-54-201-232-148.us-west-2.compute.amazonaws.com:~/.credentials/
scp -i ~/.credentials/selenium.pem \
~/.credentials/aws-sdk* ubuntu@ec2-54-201-232-148.us-west-2.compute.amazonaws.com:~/.credentials/
These two commands are identical to Command 2, but copy files with different patterns: client_secret* and aws-sdk* respectively.