LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-13-2021, 06:44 AM   #1
airline33
LQ Newbie
 
Registered: Nov 2021
Posts: 1

Rep: Reputation: Disabled
Some practice question - working with servers


Hello everyone,
I would like to have some help with some questions I encountered lately:

1. Write a command that shows how many hops you have between your machine and google.com.

2. Using this API: http://api.open-notify.org/
a - Write a command that shows how many people are in space in any moment.
b - Write a command that prints the current longitude of the international space station.



3. Using this: https://raw.githubusercontent.com/Bi...r/pokedex.json
a - write a command that prints the number of Pokemons available in Pokedex.

b - Write a command that prints all the height of the Pokemons from the lowest to the tallest.

c - Who is the tallest Pokemon?



4. Using this: https://ipapi.co/<ip>/json
a - write a command that prints the country where the server of which one of the following addresses is located: amazon.com, amazon.co.uk, amazon.de, amazon.co.jp

b - Are those servers are located in their country?





Thanks
 
Old 11-13-2021, 12:43 PM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_12{.0|.1}
Posts: 5,777
Blog Entries: 23

Rep: Reputation: 3785Reputation: 3785Reputation: 3785Reputation: 3785Reputation: 3785Reputation: 3785Reputation: 3785Reputation: 3785Reputation: 3785Reputation: 3785Reputation: 3785
Welcome to LQ!

Per the LQ Rules, please do not post homework assignments verbatim. We're happy to assist if you have specific questions or have hit a stumbling point, however. Let us know what you've already tried and what references you have used (including class notes, books, and Google searches) and we'll do our best to help. Also, keep in mind that your instructor might also be an LQ member.

Please review the Site FAQ for guidance in asking well formed questions. Especially visit the link from that page, How to Ask Questions the Smart Way for discussion of things to consider when asking others for help.
 
Old 11-13-2021, 03:03 PM   #3
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,037

Rep: Reputation: Disabled
Cross-posts @linux.org and @SO (closed).

Nice APIs they have out there. I didn't count the lines of traceroute output as this would be too easy, but did all the other exercises with curl and jq. See below (I printed only the three shortest and the tallest Pokemon):
Code:
#!/bin/sh
echo = 2 =
api=http://api.open-notify.org
echo == 2a ==
echo 'Q: How many people are in space now?'
echo  "A: $(curl -s $api/astros.json|jq .number)"
echo == 2b ==
echo 'Q: Current longitude of the ISS?'
echo "A: $(curl -s $api/iss-now.json|jq -r .iss_position.longitude)"

echo = 3 =
api=https://raw.githubusercontent.com/Biuni/PokemonGO-Pokedex/master/pokedex.json
echo == 3a ==
echo 'Q: Number of Pokemons available in Pokedex?'
echo "A: $(curl -s $api|jq '.pokemon|length')"

echo == 3b ==
echo 'Q: Heights of all Pokemons from the lowest to the tallest'
curl -s $api|
  jq -r '.pokemon|sort_by(.height)[]|"\(.name) is \(.height) tall"'|
  sed -n '1,3p;$p;3a...'

echo == 3c ==
echo 'Q: Who is the tallest Pokemon?'
curl -s $api|
  jq -r '.pokemon|max_by(.height)|"A: \(.name) is the tallest"'

echo = 4 =
api=https://ipapi.co
echo == 4a ==
echo 'Q: What country the following addresses are located in?'
for cc in com co.uk de co.jp
do
  for ip in $(host -tA amazon.$cc|awk '$0=$NF')
  do
     printf '%-13s %17s is in %s\n' \
       "amazon.$cc" "($ip)" "$(curl -s $api/$ip/json|jq -r .country_name)"
   done
done

echo == 4b ==
echo 'Q: Are those servers located in their country?'
for c in US:com GB:co.uk DE:de JP:co.jp
do
  cc=${c#*:}
  for ip in $(host -tA amazon.$cc|awk '$0=$NF')
  do
     printf '%-13s %17s is %s\n' \
       "amazon.$cc" "($ip)" \
       "$(curl -s $api/$ip/json|
            jq -r 'if .country=="'"${c%:*}"'" then "at home" else "abroad" end')"
   done
done

Last edited by shruggy; 11-23-2021 at 03:07 AM.
 
Old 11-13-2021, 03:10 PM   #4
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 10,188

Rep: Reputation: 4752Reputation: 4752Reputation: 4752Reputation: 4752Reputation: 4752Reputation: 4752Reputation: 4752Reputation: 4752Reputation: 4752Reputation: 4752Reputation: 4752
Quote:
Originally Posted by airline33 View Post
1. Write a command that shows how many hops you have between your machine and google.com.
Code:
traceroute www.google.com | wc -l

Last edited by dugan; 11-13-2021 at 03:12 PM.
 
Old 11-13-2021, 03:14 PM   #5
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,037

Rep: Reputation: Disabled
@dugan. Off by one. The first line is the header, at least in my version of traceroute.

Last edited by shruggy; 11-13-2021 at 04:17 PM.
 
  


Reply

Tags
json


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting up tune2fs on production servers with long uptimes - is there a best practice? JockVSJock Linux - Newbie 7 03-08-2017 03:23 PM
Best Practice for multiple DNS Servers fruitwerks Linux - Server 3 04-22-2013 03:13 AM
combining servers (gridengine) best practice advice Reignfire Linux - Server 0 10-19-2012 09:44 AM
LXer: How To Manage Your Servers With Rex - Best Practice LXer Syndicated Linux News 0 05-18-2012 12:50 PM
Need some tar files to practice on AMDPwred Linux - General 7 01-16-2002 01:10 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:47 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration