Write your script. This is a random example script that just performs some basic input validation, and then runs a jar.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/bin/sh
arg1=$1arg2=$2## Directory where jar file is located dir=/directory-path/to/jar-file/
## Jar file namejar_name=app.jar
## Permform some validation on input arguments, one example belowif[ -z "$1"]||[ -z "$2"];thenecho"Missing arguments, exiting.."echo"Usage : $0 arg1 arg2"exit1fijava -jar $dir/$jar_name arg1 arg2
Copy your Bash script to the /usr/local/bin directory.
1
cp run.sh /usr/local/bin
Give execute permission to the script.
1
chmod u+x /usr/local/bin/test.sh
Now you can type just the word run or run.sh on command line, followed by any arguments necessary to run your script. The shell will auto-complete the script name and allow execution by pressing the enter key.
#!/bin/bash
# Create an application-OVERRIDES.properties file in # environment/src/main/resources, then this script will# load credentials for AWS SDK usage in your environment.## Usage: run `./setAWSProperties.sh` from scripts or root app directory AMAZON_ACCESS_KEY_PROPERTY_NAME="amazon.access.key="AMAZON_SECRET_KEY_PROPERTY_NAME="amazon.access.secretkey="AMAZON_SESSION_TOKEN_PROPERTY_NAME="amazon.access.sessiontoken="write_aws_credentials (){# get vault creds as json JSON=$(aws-vault exec <YOUR_AWS_ROLE_NAME> --json)ACCESS_KEY_ID=$(echo"$JSON"| jq -r .AccessKeyId)SECRET_ACCESS_KEY=$(echo"$JSON"| jq -r .SecretAccessKey)SESSION_TOKEN=$(echo"$JSON"| jq -r .SessionToken)# write a newline so the credentials are not appended onto an existing property echo"" >> "$1"# find and delete existing aws session credentials sed -i -e "/$AMAZON_ACCESS_KEY_PROPERTY_NAME/d""$1" sed -i -e "/$AMAZON_SECRET_KEY_PROPERTY_NAME/d""$1" sed -i -e "/$AMAZON_SESSION_TOKEN_PROPERTY_NAME/d""$1"# set new aws sessions credentials echo"$AMAZON_ACCESS_KEY_PROPERTY_NAME;$ACCESS_KEY_ID" >> "$1"echo"$AMAZON_SECRET_KEY_PROPERTY_NAME$SECRET_ACCESS_KEY" >> "$1"echo"$AMAZON_SESSION_TOKEN_PROPERTY_NAME$SESSION_TOKEN" >> "$1"echo"wrote aws session credentials to application.OVERRIDES.properties"}OVERRIDES_FILE_DIR="environment/src/main/resources/application-OVERRIDES.properties"if[ -e "$OVERRIDES_FILE_DIR"];then write_aws_credentials $OVERRIDES_FILE_DIRelif[ -e "../$OVERRIDES_FILE_DIR"];then write_aws_credentials "../$OVERRIDES_FILE_DIR"elseecho"application-OVERRIDES.properties does not exist. Create it and re-run the script."fi