Open thomsssv1 opened 1 year ago
Exercise 2: SCP
1 touch test_to_remote_instance.txt 2 ssh username@remote_host touch test_from_remote_instance.txt exit 3
scp test_to_remote_instance.txt username@remote_host:~ scp username@remote_host:~/test_from_remote_instance.txt . 4
local_file_path="$1" scp "$local_file_path" username@remote_host:~
remote_file_path="$1" scp username@remote_host:"$remote_file_path" .
chmod +x scp_to_remote_instance.sh scp_from_remote_instance.sh
5
./scp_to_remote_instance.sh /path/to/local/file.txt ./scp_from_remote_instance.sh /path/to/remote/file.txt
Exercise 1.1: Here are some other interesting URLs that can be found on the OpenDomesday API:
https://opendomesday.org/api/1.0/book/ - to get information about the Domesday Book itself https://opendomesday.org/api/1.0/person/ - to get information about people mentioned in the Domesday Book https://opendomesday.org/api/1.0/search/?query= - to search for specific information in the Domesday Book
curl -s https://opendomesday.org/api/1.0/place/?county=derbyshire | grep -o '"id":[0-9]' | grep -o '[0-9]'
Exercise 1.2: Get ids for all places in Derbyshire
derbyshire_places=$(curl https://opendomesday.org/api/1.0/county/Derbyshire/places/ | grep -o '"id":[0-9]*' | sed 's/"id"://')
Exercise 1.3: Load details for each place and their manors
for place_id in $derbyshire_places do curl https://opendomesday.org/api/1.0/place/$place_id/ > place_${place_id}data.json manors=$(cat place${place_id}_data.json | grep -o '"manor":[0-9]*' | sed 's/"manor"://') for manor_id in $manors do curl https://opendomesday.org/api/1.0/manor/$manor_id/ > manor_${manor_id}_data.json done done
Exercise 1.4: Extract geld and ploughs data for each manor in Derbyshire
echo "Manor ID, Geld Paid, Number of Ploughs" > derbyshire_manors.csv for place_id in $derbyshireplaces do manors=$(cat place${place_id}_data.json | grep -o '"manor":[0-9]' | sed 's/"manor"://') for manorid in $manors do geld=$(cat manor${manor_id}_data.json | grep -o '"geld":[0-9]' | sed 's/"geld"://') ploughs=$(cat manor_${manor_id}_data.json | grep -o '"ploughs":[0-9]*' | sed 's/"ploughs"://') echo "${manor_id}, ${geld}, ${ploughs}" >> derbyshire_manors.csv done done
Exercise 1.5: Sum values in the Geld Paid column of the CSV file
geld_sum=$(awk -F', ' '{s+=$2} END {print s}' derbyshire_manors.csv) echo "Total Geld Paid in Derbyshire: $geld_sum"