Obtain the hostname served by a Kubernetes Ingress [closed] - bash

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 11 months ago.
This post was edited and submitted for review 6 months ago and failed to reopen the post:
Original close reason(s) were not resolved
Improve this question
How to resolve the domain/hostname of a K8s Service, that a specific K8s Ingress is serving?
In the namespace foobar, I want to know where to connect for the service provided by the ingress.
kubectl --namespace foobar get ingress
returns the available ones, and
kubectl --namespace foobar describe ingress/bazbar
returns the details; I can match by name (e.g. barbaz) the one I'm targeting.
But how can I extrapolate the host (and, possibly, also the path) to then launch it in the browser with xdg-open?

The below should solve your query on getting domain per namespace.
The query below "get ingress" retrieves the domain details from all namespaces and using awk, it prints the 1st column which is the namespace and the 4th column which is the domain in the ingress, you can grep it further to filter down on particular namespace.
#To get all namespace and domain
kubectl get ingress --all-namespaces|awk '{print $1 " | " $4 }'
foobar | foobar.example.com
barfoo | barfoo.example.com
#To filter on namespace from all namespace
kubectl get ingress --all-namespaces|awk '{print $1 " | " $4 }'|grep -i foobar
foobar | foobar.example.com
#To get one namespace
kubectl get ingress -n <namespace-name>|awk '{print $1 " | " $4 }'
foobar | foobar.example.com

Related

Get currency exchange rate using bash [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed last year.
Improve this question
I would like to display the current exchange rate from the currency euro to us dollar in the command line using bash shell script. I'm using the website market insider.
I saw on someone's blog to use wget command
wget -qO- https://markets.businessinsider.com/currencies/eur-usd
But how can I display only the rate? Desired output (example for current rate 1.1347) --> 1.1347 $
PS: I would prefer not to use API
Any help would be appreciated
Do this cleanly using their API:
#!/usr/bin/env bash
API='https://markets.businessinsider.com/ajax/'
ExchangeRate_GetConversionForCurrenciesNumbers() {
isoCodeForeign=$1
isoCodeLocal=$2
amount=$3
date=$4
cacheFile="/tmp/$date-$amount-$isoCodeForeign-$isoCodeLocal.json"
# Check if we have cached the result to avoid front-running the API
if ! [ -e "$cacheFile" ]; then
post_vars=(
isoCodeForeign="$isoCodeForeign"
isoCodeLocal="$isoCodeLocal"
amount="$amount"
date="$date"
)
method='ExchangeRate_GetConversionForCurrenciesNumbers'
IFS='&' url="$API$method?${post_vars[*]}"
curl -s -X POST "$url" > "$cacheFile"
fi
jq -r '.ConvertedAmountFourDigits' "$cacheFile"
}
getRateEURO_USToday() {
ExchangeRate_GetConversionForCurrenciesNumbers EUR USD 1 "$(date '+%Y-%m-%d')"
}
# Set LC_NUMERIC=C because the float format returned is using . as decimal
LC_NUMERIC=C printf 'The exchange rate for EUR to USD today is: %.4f\n' \
"$(getRateEURO_USToday)"

Dig command repated SERVER value [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
Improve this question
I'm exploring the various options of dig command. I have disabled all output except the stats section:
$ options="+noanswer +nocmd +nocomments +stats"
$ dig example.com $options
;example.com. IN A
;; Query time: 41 msec
;; SERVER: 75.75.75.75#53(75.75.75.75)
;; WHEN: Wed Apr 01 11:59:25 MDT 2020
;; MSG SIZE rcvd: 56
$ dig stackoverflow.com $options
;stackoverflow.com. IN A
;; Query time: 49 msec
;; SERVER: 75.75.75.75#53(75.75.75.75)
;; WHEN: Wed Apr 01 11:59:43 MDT 2020
;; MSG SIZE rcvd: 110
Why these two different domains return the same SERVER? Every domain that I have tried return the same SERVER value.
;; SERVER: 75.75.75.75#53(75.75.75.75)
Is the DNS Name-server used during the dig command.
You can confirm this by checking which name-server your computer uses;
$ dig +noanswer +nocmd +nocomments +stats example.com
...
;; SERVER: 172.18.0.254#53(172.18.0.254)
...
$ cat /etc/resolv.conf | tail -n 1
nameserver 172.18.0.254
I'm using a local custom DNS server, therefore the local ip ;)

sort or unique command bash [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
Improve this question
This is a file . I want to remove the repetition in the name of patch
[ppande#server-1 —]$egrep 'Patch[0-9].*.*:' content1
Patch1001 : snmp fixl.org
Patch1002 : dhcp tmp fix
Patch1003 : qemu-img-9.0.58
Patch001 : snmp fixl.org
Patch002 : dhcp installation
Patch003 : qemu
Patch004 : snmp fixl.org
I used 'sort -u' but here the order of the patch is changed . All I need is the output with out repetitions and order remains same , or in other words if there is a repetition the second/last occurrence must not be displayed .
[ppande#server-1 —]$egrep 'Patch[0-9].*.*:' content1 | sort -u -k3
Patch002 : dhcp installation
Patch1002 : dhcp tmp fix
Patch003 : qemu
Patch1003 : qemu-img-0.0.58
Patch1001 : snmp fixl.org
Patch001 : snmp fixl.org
Desired output:
Patch1001 : snmp fixl.org
Patch1002 : dhcp tmp fix
Patch1003 : qemu-img-9.0.58
Patch002 : dhcp installation
Patch003 : qemu
EDIT: Since oguzismail added same solution few secs before me so adding perl solution now if you are ok with it.
perl -aF': ' -lne 'print if ! $seen{$F[1]}++' Input_file
Could you please try following. You need not to use multiple commands along with awk here.
awk -F': ' '/Patch[0-9].*.*/ && !a[$2]++' Input_file
You can do that in a single awk command.
awk -F ':\\s*' '/^Patch[0-9]+\s*:/ && !a[$2]++' content1

database login using shell scripting [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
This is the Database entry of my application in server.properties file.
umpdb.driverClassName=org.mariadb.jdbc.Driver
umpdb.url=jdbc:mysql://10.66.11.44:3306/MT_SMS_CHN?useUnicode=true&characterEncoding=UTF-8
umpdb.username=stackuser
umpdb.password=stackpass
I want to print mysql -uuser -ppasswrod -hhostname dbname using linux command.
It means, I need output as below
mysql -ustackuser -pstackpass -h10.66.11.44 MT_SMS_CHN
Please help me for this.
Using awk
awk -F'[:=/?]' '/url/{
h=$6" "$8 # get host and database
}
/username/{
u=$2 # get username
}
/password/{
# print username, password, host and database
printf("mysql -u%s -p%s -h%s\n",u,$2,h);
# we got what we want, exit
# if your file contains more than 1 db config
# just comment below exit keyword
exit
}
' server.conf
Test Results:
$ cat server.conf
umpdb.driverClassName=org.mariadb.jdbc.Driver
umpdb.url=jdbc:mysql://10.66.11.44:3306/MT_SMS_CHN?useUnicode=true&characterEncoding=UTF-8
umpdb.username=stackuser
umpdb.password=stackpass
$ awk -F'[:=/?]' '/url/{h=$6" "$8}/username/{u=$2}/password/{printf("mysql -u%s -p%s -h%s\n",u,$2,h); exit}' server.conf
mysql -ustackuser -pstackpass -h10.66.11.44 MT_SMS_CHN

How to enumerate running ec2 instances and load them into a database using ruby? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I'm using aws-sdk gem, I can't figure how to list all the running ec2 instances and load them to a database.
I need an approach on how to do it.
require 'aws-sdk-v1'
ec2 = AWS::EC2.new(
access_key_id: 'YOUR_ACCESS_KEY_ID',
secret_access_key: 'YOUR_SECRET_ACCESS_KEY',
region: 'YOUR_EC2_REGION'
)
ec2.instances
http://docs.amazonwebservices.com/AWSRubySDK/latest/frames.html
The answer above will return all instances, not just running instances. You can use a filter to get only running instances:
ec2 = AWS::EC2.new
ec2.instances.filter('instance-state-name', 'running')
Install the AWS ClI and run the following to get a list of running instance ids:
aws ec2 describe-instances --filter "Name=instance-state-name,Values=running" \
| grep InstanceId | awk '{print $2}' | sed 's/^\"//g' | sed 's/\",$//g'

Resources