LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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, 05: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, 11:43 AM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,269
Blog Entries: 24

Rep: Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206
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, 02:03 PM   #3
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,678

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 02:07 AM.
 
Old 11-13-2021, 02:10 PM   #4
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,249

Rep: Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323
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 02:12 PM.
 
Old 11-13-2021, 02:14 PM   #5
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,678

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 03:17 PM.
 
  


Reply

Tags
json



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 02:23 PM
Best Practice for multiple DNS Servers fruitwerks Linux - Server 3 04-22-2013 02:13 AM
combining servers (gridengine) best practice advice Reignfire Linux - Server 0 10-19-2012 08:44 AM
LXer: How To Manage Your Servers With Rex - Best Practice LXer Syndicated Linux News 0 05-18-2012 11:50 AM
Need some tar files to practice on AMDPwred Linux - General 7 01-16-2002 12:10 PM

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

All times are GMT -5. The time now is 06:00 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