Working with bash scripts Dig is an outstanding command line tool that is widely used in the system administration / devops world. It lets us query DNS servers and, by default, it returns the records...

1 answer below »
The task is to modify a bash script that identifies the various DNS record types and DNS names in the argument list, and then extracts for each hostname all of the requested record types.
The instructions and the bash script is attached.


Working with bash scripts Dig is an outstanding command line tool that is widely used in the system administration / devops world. It lets us query DNS servers and, by default, it returns the records in standard BIND format with many useful comments. However, it doesn't allow us to ask for multiple record types in a request, and it likewise doesn't let us ask about more than one DNS name. Our bash script, cop4342-assign5.sh, remedies this by parsing the options, identifying the various DNS record types and DNS names in the argument list, and then extracts for each hostname all of the requested record types. For instance, here is an example of our script in action: bash-4.2$ ./cop-4342-assign5.sh -t -@ 8.8.8.8 -s 5 -q -y harvard.edu fsu.edu Report for harvard.edu dig @8.8.8.8 +timeout=5 +short +tcp harvard.edu TXT "MS=ms35192554" "google-site-verification=DzhZyP8pu0M1-RFghfTcSN-9poidboYRNdfn2Rf2hCQ " "status-page-domain-verification=p83gt91wpxms" "status-page-domain-verification=b4j4g69th3vv" "v=spf1 redirect=_spf.harvard.edu" "adobe-idp-site-verification=66e813947c764d98330002232f383a68df8ad609 065abb9482f3805dd2a1902c" "pardot378242=7001579db574e062735763ba81b54da111abc31facf16bbfa653ab6 b8a770988" "pardot_378242_*=8b485d5cd9114869cff8f307da5fa9287434ebec11621d88c07c e97a7fee06e0" "ciscocidomainverification=41ce9827e3fbbca9ce75d5dbb5a6bc7b089dc4e239 c1b56ba828216d1214480" "Peh2GHoW8uiAzwS9tTZKlGBn9cMq6Y+XUFtrqmLtqFh1WvloPkzGczPsZcSdDfin4hZ7 QiL9J7SM8yr7Yyzi8w==" "atlassian-domain-verification=Z8oUd5brL6/RGUMCkxs4U0P/RyhpiNJEIVx9HX JLr3uqEQ1eDmTnj1eq1ObCgY1i" "pardot679353=3cc5e124c5020a1e160f01981f45be33a467a1c802711e0e5654184 ef56d18c9" "pardot679353=f93ea3588d69483bf48dbf587511f51d43ddadaae52b8bac6856c84 28559a06d" "google-site-verification=lY-T8NneGQX1RGXeaoBJjSmT_lx3dLRKDq1xY44ZI5w " "globalsign-domain-verification=1C94E0FFAAE95796F597427644D90C03" "jAykGnWytyLeBseMa8x2/MBve6/yQqana4yrAc1ROoei7uZHUkM2FU0Xx4qI/rm+kOGd ImZdoq0fdodgLEw1dg==" "google-site-verification=xqg8LPF_v_QMEIST789q8xhRDqUEX4_8lQjAvV6YykY " "xIGeuA0e5B1BOjTE4IBO806ziFX9G1m2dVJ8zO7CMkmKwZ6MEkMXC0P7n5SRCGOdS9jb ceH/7gKYgD4h9FBGKA==" Report for fsu.edu dig @8.8.8.8 +timeout=5 +short +tcp fsu.edu TXT "google-site-verification=rfFZMOyEvlaVCHEXON67HT1IaNY-qWrQltYG3gWLcNQ " "adobe-idp-site-verification=65fe86d8-9cff-4483-9e0a-5f79a62094df" "docusign=accbcb99-46f9-4f6b-a9f9-0f9ab40650aa" "amazonses:A96H79weD68NNoW8K1oFn8nPfVq03+DcMAiGaInWfUs=" "e2ma-verification=vb1cb" "e2ma-verification=vr0cb" "e2ma-verification=55gfb" "google-site-verification=MOc2Nx2DrRnMyIZRyqYXUiCUm5owsjgVLOwtLMKFKgU " "amazonses:t4DBDpenTdNcxCTWZewFU3GxENX9YeFrwVyJApjF+2c=" "Blnm1Yca35pROmJBkTo7IWPvD1MrPpArexE7F/zAweqCnhzHjibxyZdmrhBDUjf6uXNJ 39HfRw7mhfDqTR6qFw==" "v=spf1 ip4:146.201.58.214 ip4:146.201.58.215 ip4:146.201.107.145 ip4:146.201.107.249 " "ip4:192.135.64.7 ip4:199.188.157.80 ip4:107.20.210.250 ip4:52.1.14.157 " "include:spf.protection.outlook.com include:_spf.qualtrics.com " "include:_spf.mlsend.com ~all" "docusign=878a13c7-bff1-489e-85e9-df7fa0ef1bd1" "e2ma-verification=zb1cb" "adobe-sign-verification=49a5a6dbfb17bebff3c5e0f55fd1a08f" "Sendinblue-code:ba3f5b267d9ffe463852be6367b50612" "e2ma-verification=yb1cb" "amazonses:rqJyCdRo8g1YbiHh/V8fM08imbOM2xBzGf/U93N40p4=" In this case, we asked for the TXT records for both FSU and Harvard (that's what the "-t" is short for.) The other options all are used to control how we make the query: the -@ option lets specify a DNS server to query (Google's 8.8.8.8 server in the above example), the -s option lets us specify how many seconds to allow before timing out (5 in the above), the -q means to be quiet (suppress comments and performance numbers), and the -y option is perhaps the most important: we are using it to mean "use TCP" rather the default UDP. This is important because our UDP performance on the servers is dismal, due to heavy-handed DNS censorship. Here's the usage message for our script (induced by specifying an undefined option, which your script should also do): bash-4.2$ ./cop4342-assign5.sh -? ./cop4342-assign5.sh: illegal option -- ? unknown option -? passed in ********** * * cop4342-assign5.sh [-@ DNS_SERVER] [-s TIMEOUT] [-q] [-t] [-y] [-a] [-6] [-m] [-r] [-v] HOST ... * * This assignment augments standard "dig" so that it can handle multiple DNS record type requests * for multiple DNS names (i.e., it does the cartesian production of dig against DNS records versus * DNS names.) * * It accepts these options: * * -@ DNS_SERVER * Query this specific DNS_SERVER (8.8.8.8, 8.8.4.4, and 1.1.1.1 are all reasonable choices.) * * -s TIMEOUT * Wait up to TIMEOUT seconds for a response. * * -q * Use terse mode. * * -y * Use tcp instead of udp; very valuable here at FSU since our udp queries are very slow since * due to the heavy-handed censorship imposed last year. * * -t * Return a TXT record. * * -a * Return an A record. * * -6 * Return an AAAA record. * * -m * Return an MX record. * * -r * Return an SPF record. * * -v * Return an SRV record. * ********** Your assignment is to restore the missing lines from the script (the missing lines only deal with options; you don't need to change anything except for the indicated lines in the script). Step 1: Edit the script starting at line 58 to restore the parsing of the options. Step 2: Verify your code by trying to replicate the above examples, and the following larger example: bash-4.2$ !! ./cop4342-assign5.sh -@ 8.8.8.8 -y -q -s 6 -a -6 -t -m -r -v harvard.edu fsu.edu google.com www.google.com _jabber._tcp.google.com. Report for harvard.edu dig @8.8.8.8 +tcp +short +timeout=6 harvard.edu A 23.185.0.1 dig @8.8.8.8 +tcp +short +timeout=6 harvard.edu AAAA 2620:12a:8000::1 2620:12a:8001::1 dig @8.8.8.8 +tcp +short +timeout=6 harvard.edu TXT "MS=ms35192554" "google-site-verification=DzhZyP8pu0M1-RFghfTcSN-9poidboYRNdfn2Rf2hCQ " "status-page-domain-verification=p83gt91wpxms" "status-page-domain-verification=b4j4g69th3vv" "v=spf1 redirect=_spf.harvard.edu" "adobe-idp-site-verification=66e813947c764d98330002232f383a68df8ad609 065abb9482f3805dd2a1902c" "pardot378242=7001579db574e062735763ba81b54da111abc31facf16bbfa653ab6 b8a770988" "pardot_378242_*=8b485d5cd9114869cff8f307da5fa9287434ebec11621d88c07c e97a7fee06e0" "ciscocidomainverification=41ce9827e3fbbca9ce75d5dbb5a6bc7b089dc4e239 c1b56ba828216d1214480" "Peh2GHoW8uiAzwS9tTZKlGBn9cMq6Y+XUFtrqmLtqFh1WvloPkzGczPsZcSdDfin4hZ7 QiL9J7SM8yr7Yyzi8w==" "atlassian-domain-verification=Z8oUd5brL6/RGUMCkxs4U0P/RyhpiNJEIVx9HX JLr3uqEQ1eDmTnj1eq1ObCgY1i" "pardot679353=3cc5e124c5020a1e160f01981f45be33a467a1c802711e0e5654184 ef56d18c9" "pardot679353=f93ea3588d69483bf48dbf587511f51d43ddadaae52b8bac6856c84 28559a06d" "google-site-verification=lY-T8NneGQX1RGXeaoBJjSmT_lx3dLRKDq1xY44ZI5w " "globalsign-domain-verification=1C94E0FFAAE95796F597427644D90C03" "jAykGnWytyLeBseMa8x2/MBve6/yQqana4yrAc1ROoei7uZHUkM2FU0Xx4qI/rm+kOGd ImZdoq0fdodgLEw1dg==" "google-site-verification=xqg8LPF_v_QMEIST789q8xhRDqUEX4_8lQjAvV6YykY " "xIGeuA0e5B1BOjTE4IBO806ziFX9G1m2dVJ8zO7CMkmKwZ6MEkMXC0P7n5SRCGOdS9jb ceH/7gKYgD4h9FBGKA==" dig @8.8.8.8 +tcp +short +timeout=6 harvard.edu MX 100 mx0a-00171101.pphosted.com. 100 mx0b-00171101.pphosted.com. dig @8.8.8.8 +tcp +short +timeout=6 harvard.edu SPF NO ANSWER to SPF query for harvard.edu dig @8.8.8.8 +tcp +short +timeout=6 harvard.edu SRV NO ANSWER to SRV query for harvard.edu Report for fsu.edu dig @8.8.8.8 +tcp +short +timeout=6 fsu.edu A 146.201.111.62 dig @8.8.8.8 +tcp +short +timeout=6 fsu.edu AAAA NO ANSWER to AAAA query for fsu.edu dig @8.8.8.8 +tcp +short +timeout=6 fsu.edu TXT "amazonses:rqJyCdRo8g1YbiHh/V8fM08imbOM2xBzGf/U93N40p4=" "e2ma-verification=vb1cb" "google-site-verification=MOc2Nx2DrRnMyIZRyqYXUiCUm5owsjgVLOwtLMKFKgU " "e2ma-verification=55gfb" "docusign=878a13c7-bff1-489e-85e9-df7fa0ef1bd1" "amazonses:t4DBDpenTdNcxCTWZewFU3GxENX9YeFrwVyJApjF+2c=" "Blnm1Yca35pROmJBkTo7IWPvD1MrPpArexE7F/zAweqCnhzHjibxyZdmrhBDUjf6uXNJ 39HfRw7mhfDqTR6qFw==" "Sendinblue-code:ba3f5b267d9ffe463852be6367b50612" "google-site-verification=rfFZMOyEvlaVCHEXON67HT1IaNY-qWrQltYG3gWLcNQ " "e2ma-verification=zb1cb" "docusign=accbcb99-46f9-4f6b-a9f9-0f9ab40650aa" "adobe-sign-verification=49a5a6dbfb17bebff3c5e0f55fd1a08f" "amazonses:A96H79weD68NNoW8K1oFn8nPfVq03+DcMAiGaInWfUs=" "e2ma-verification=vr0cb" "adobe-idp-site-verification=65fe86d8-9cff-4483-9e0a-5f79a62094df" "v=spf1 ip4:146.201.58.214 ip4:146.201.58.215 ip4:146.201.107.145 ip4:146.201.107.249 " "ip4:192.135.64.7 ip4:199.188.157.80 ip4:107.20.210.250 ip4:52.1.14.157 " "include:spf.protection.outlook.com include:_spf.qualtrics.com " "include:_spf.mlsend.com ~all" "e2ma-verification=yb1cb" dig @8.8.8.8 +tcp +short +timeout=6 fsu.edu MX 10 mxa-00012503.gslb.pphosted.com. 10 mxb-00012503.gslb.pphosted.com. dig @8.8.8.8 +tcp +short +timeout=6 fsu.edu SPF NO ANSWER to SPF query for fsu.edu dig @8.8.8.8 +tcp +short +timeout=6 fsu.edu SRV NO ANSWER to SRV query for fsu.edu Report for google.com dig @8.8.8.8 +tcp +short +timeout=6 google.com A 64.233.177.100 64.233.177.102 64.233.177.138 64.233.177.101 64.233.177.113 64.233.177.139 dig @8.8.8.8 +tcp +short +timeout=6 google.com AAAA 2607:f8b0:4002:c08::71 2607:f8b0:4002:c08::65 2607:f8b0:4002:c08::8b 2607:f8b0:4002:c08::8a dig @8.8.8.8 +tcp +short +timeout=6 google.com TXT "globalsign-smime-dv=CDYX+XFHUw2wml6/Gb8+59BsH31KzUr6c1l2BPvqKX8=" "docusign=1b0a6754-49b1-4db5-8540-d2c12664b289" "facebook-domain-verification=22rm551cu4k0ab0bxsw536tlds4h95" "apple-domain-verification=30afIBcvSuDV2PLX" "docusign=05958488-4752-4ef2-95eb-aa7ba8a3bd0e" "v=spf1 include:_spf.google.com ~all" dig @8.8.8.8 +tcp +short +timeout=6 google.com MX 20 alt1.aspmx.l.google.com. 40 alt3.aspmx.l.google.com. 10 aspmx.l.google.com. 50 alt4.aspmx.l.google.com. 30 alt2.aspmx.l.google.com. dig @8.8.8.8 +tcp +short +timeout=6 google.com SPF NO ANSWER to SPF query for google.com dig @8.8.8.8 +tcp +short +timeout=6 google.com SRV NO ANSWER to SRV query for google.com Report for www.google.com dig @8.8.8.8 +tcp +short +timeout=6 www.google.com A 172.217.11.132 dig @8.8.8.8 +tcp +short +timeout=6 www.google.com AAAA 2607:f8b0:4002:c02::93 2607:f8b0:4002:c02::6a 2607:f8b0:4002:c02::69 2607:f8b0:4002:c02::68 dig @8.8.8.8 +tcp +short +timeout=6 www.google.com TXT NO ANSWER to TXT query for www.google.com dig @8.8.8.8 +tcp +short +timeout=6 www.google.com MX NO ANSWER to MX query for www.google.com dig @8.8.8.8 +tcp +short +timeout=6 www.google.com SPF NO ANSWER to SPF query for www.google.com dig @8.8.8.8 +tcp +short +timeout=6 www.google.com SRV NO ANSWER to SRV query for www.google.com Report for _jabber._tcp.google.com. dig @8.8.8.8 +tcp +short +timeout=6 _jabber._tcp.google.com. A NO ANSWER to A query for _jabber._tcp.google.com. dig @8.8.8.8 +tcp +short +timeout=6 _jabber._tcp.google.com. AAAA NO ANSWER to AAAA query for _jabber._tcp.google.com. dig @8.8.8.8 +tcp +short +timeout=6 _jabber._tcp.google.com. TXT NO ANSWER to TXT query for _jabber._tcp.google.com. dig @8.8.8.8 +tcp +short +timeout=6 _jabber._tcp.google.com. MX NO ANSWER to MX query for _jabber._tcp.google.com. dig @8.8.8.8 +tcp +short +timeout=6 _jabber._tcp.google.com. SPF NO ANSWER to SPF query for _jabber._tcp.google.com. dig @8.8.8.8 +tcp +short +timeout=6 _jabber._tcp.google.com. SRV 20 0 5269 alt4.xmpp-server.l.google.com. 20 0 5269 alt2.xmpp-server.l.google.com. 20 0 5269 alt3.xmpp-server.l.google.com. 5 0 5269 xmpp-server.l.google.com. 20 0 5269 alt1.xmpp-server.l.google.com. Step 4: Submit your fixed script here #!/bin/bash function usage() { echo ' ' echo ' **********' echo ' * ' echo ' * cop4342-assign5.sh [-@ DNS_SERVER] [-s TIMEOUT] [-q] [-t] [-y] [-a] [-6] [-m] [-r] [-v] HOST ... ' echo ' * ' echo ' * This assignment augments standard "dig" so that it can handle multiple DNS record type requests' echo ' * for multiple DNS names (i.e., it does the cartesian production of dig against DNS records versus' echo ' * DNS names.)' echo ' * ' echo ' * It accepts these options:' echo ' * ' echo ' * -@ DNS_SERVER' echo ' * Query this specific DNS_SERVER (8.8.8.8, 8.8.4.4, and 1.1.1.1 are all reasonable choices.)'
Answered 2 days AfterJun 24, 2021

Answer To: Working with bash scripts Dig is an outstanding command line tool that is widely used in the system...

Ali Asgar answered on Jun 26 2021
158 Votes
#!/bin/bash
function usage()
{
echo ' '
echo ' **********'
echo ' * '
echo '
* cop4342-assign5.sh [-@ DNS_SERVER] [-s TIMEOUT] [-q] [-t] [-y] [-a] [-6] [-m] [-r] [-v] HOST ... '
echo ' * '
echo ' * This assignment augments standard "dig" so that it can handle multiple DNS record type requests'
echo ' * for multiple DNS names (i.e., it does the cartesian production of dig against DNS records versus'
echo ' * DNS names.)'
echo ' * '
echo ' * It accepts these options:'
echo ' * '
echo ' * -@ DNS_SERVER'
echo ' * Query this specific DNS_SERVER (8.8.8.8, 8.8.4.4, and 1.1.1.1 are all reasonable choices.)'
echo ' * '
echo ' * -s TIMEOUT'
echo ' * Wait up to TIMEOUT seconds for a response.'
echo ' * '
echo ' * -q'
echo ' * ...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here