[Linux] Some Linux Bash Notes (with some NetApp CI)

 Checking/Editing the Bash Profile:

cat ~/.bash_profile
vi ~/.bash_profile

HTTPS Proxy:

echo $https_proxy
export https_proxy='SERVERNAME:80' proxy_auth_scheme=''

Make a Directory and samples.sh file:

mkdir testing
cd testing/
vi samples.sh

Example Content of datasources.sh (unhash the curl you want to use):

#!/bin/bash
export https_proxy='SERVERNAME:80' proxy_auth_scheme=''
key="YOURAPIKEY"

#curl -X GET "https://YOUR_CI_TENANT/rest/v1/collector/datasources" -H "accept: */*" -H "Content-Type: application/json" -H "X-CloudInsights-ApiKey:${key}"
#curl -X GET "https://YOUR_CI_TENANT/rest/v1/dwh-management/odata/dwh_inventory/storage" -H "accept: */*" -H "Content-Type: application/json" -H "X-CloudInsights-ApiKey:${key}"
#curl -i -X POST "https://YOUR_CI_TENANT/rest/v1/dwh-management/upload/csvs" -H "Content-Type:multipart/form-data" -H "X-CloudInsights-ApiKey:${key}" -F "customFile=@/home/user/file.csv"

Note (see curl - How To Use):
-l is for list-only
-k is for insecure.

Running the samples.sh file (2 examples):

sh samples.sh

sh samples.sh > output
cat output
cat output | grep SOMESTRING

But You Don't Have to Create a Bash Script!

You could actually enter your key directly in the bash shell with something like:

key="YOURKEY"; echo $key

Note: You cannot directly enter a variable in the bash shell without putting a ; on the line, as the bash shell would be expecting a value, but the value doesn't exist until you've assigned it.

And then you can run something like (which gets all the tables in dwh_custom in JSON format):

curl -X GET "https://TENANT/rest/v1/dwh-management/odata/dwh_custom/" -H "accept: */*" -H "Content-Type: application/json" -H "X-CloudInsights-ApiKey:$key"

Even better (because raw JSON format is not so easy for humans to read), you can also pipe it to grep to get the name:table value pairs:

curl -X GET "https://TENANT/rest/v1/dwh-management/odata/dwh_custom/" -H "accept: */*" -H "Content-Type: application/json" -H "X-CloudInsights-ApiKey:$key" | grep -Po '"name":.*?[^\\]",'



Comments