Kodumda neyin yanlış olduğunu bilmek isterim. Neyi kaçırıyorum? İfade neden IFdüzgün çalışmıyor? Neden sadece bir çıktı gösteriyor? İfade neden elifçalışmıyor? IPv6 adresi veya posta sunucusu olup olmadıklarını belirlemek için 3 sunucu, www.ee ve www.eu ve www.com adreslerini barındırmaya ve ardından onları tekrar barındırmaya çalışıyorum.
EDIT: Böyle çalışması gerekiyordu:
1) nimed.sh adlı komut dosyası oluşturun
2) Girişte ana bilgisayar .ee'yi çalıştırır; .AB; .com ana bilgisayarları.
3) Ev sahibi yoksa, yazdır"Host not found"
4) Ana bilgisayar adresi ilk önce bulduğu ilgili e-posta sunucusu adresini gösterecektir. (Use commands sort, awk, tail or head). Ana bilgisayar cümlesinin sonundaki noktaları kaldırmanız gerekir. Gibi, bu gibi gösterir:? .Com. (noktayı kaldırmak =? .com)
5) Posta sunucusu bulunamadıysa, yazdırın "mail server not found"
6) Posta sunucusu bulunursa, ana bilgisayar komutuyla posta sunucusu IP adresini sorun.
7) Posta sunucusu IPv6 adresini "found IPv6"aldıysa, yazdırın , değilse yazdırın"IPv6 not found"
Yapmam gereken şey bu ve 7. bölüme kaldım. Egzersiz yaparak bash öğrenmek için bir okul alıştırması. İsteğe bağlı, zorunlu değil.
#!/bin/bash
m1="has address"
m2="has IPv6 address"
m3="mail is handled by 0 ."
m4="found IPv6"
m5="IPv6 not found"
m6="mail server not found"
###########################################################################################################################
host "$(host www.ee | sort | grep "mail is handled" | head -1 | awk '{print $7}')" >> www.all.txt
#first line shows this to www.all.txt
#aspmx.l.google.com has address 108.177.14.26
#aspmx.l.google.com has IPv6 address 2a00:1450:4010:c03::1b
host "$(host www.eu | sort | grep "mail is handled" | head -1 | awk '{print $7}')" >> www.all.txt
#second line shows this to www.all.txt
#mail.www.eu has address 46.105.44.68
host "$(host www.com | sort | grep "mail is handled" | head -1 | awk '{print $7}')" >> www.all.txt
#third line shows this to www.all.txt
#ASPMX.L.GOOGLE.com has address 108.177.14.26
#ASPMX.L.GOOGLE.com has IPv6 address 2a00:1450:4010:c03::1b
file="www.all.txt" #and this file has this in total:
#aspmx.l.google.com has address 108.177.14.26
#aspmx.l.google.com has IPv6 address 2a00:1450:4010:c03::1b
#mail.www.eu has address 46.105.44.68
#ASPMX.L.GOOGLE.com has address 108.177.14.26
#ASPMX.L.GOOGLE.com has IPv6 address 2a00:1450:4010:c03::1b
while read line #now this is where it gets messy. I don't know what to do-
#with line variable
do
if grep -q "$m2" $file #if string 'has IPv6 address' is in www.all.txt
then
awk 'NR==1 {print $1}' #go to line 1 and print the first text
# aspmx.l.google.com
echo "${m4}" #print 'Found IPv6'
elif grep -q "$m1" $file; then #else if string 'has address' is in
# www.all.txt then
awk 'NR==2 {print $1}' #go to line 2 and print the first text
echo "${m5}" #print 'IPv6 not found'
elif grep -q "$m3" $file; then #if string 'mail is handled by 0 .'
#is in www.all.txt then
echo "${m6}" #print 'mail server does not exist'
else #if none of the above was correct then
echo "${m6}" #mail server does not exist and
echo "${m5}" #IPv6 not found
fi #end the if-elif-else statement
done < $file #end the while loop
Yarattığı dosya:
kristen@kristen-virtual-machine:~/Desktop$ ./nimed.sh
aspmx.l.google.com
found IPv6
kristen@kristen-virtual-machine:~/Desktop$ ls
koopia.sh nimed.sh TEST.sh www.all.txt
kristen@kristen-virtual-machine:~/Desktop$ cat www.all.txt
aspmx.l.google.com has address 64.233.161.26
aspmx.l.google.com has IPv6 address 2a00:1450:4010:c0e::1b
mail.www.eu has address 46.105.44.68
ASPMX.L.GOOGLE.com has address 64.233.161.26
ASPMX.L.GOOGLE.com has IPv6 address 2a00:1450:4010:c0e::1b
kristen@kristen-virtual-machine:~/Desktop$
TEST 1: Başarı
Correct program output
--- Input ---
www.ee
--- Program output ---
aspmx.l.google.com
found IPv6
--- Expected output (text)---
aspmx.l.google.com
found IPv6
2. TEST: Başarısız
Incorrect program output
--- Input ---
www.eu
--- Program output ---
aspmx.l.google.com
Found IPv6
--- Expected output (text)---
mail.www.eu
Didn't find IPv6
hostkomutlar her zaman üç alan için de çalışır. İkincisi, while readdöngünün ne yapması gerektiği belli değil - $linedosyadan okuduğu değişkenle hiçbir şey yapmaz ve yine de onunla ne yapacağınızdan emin değilim. Üçüncüsü, grepkomutlar tüm dosyayı awkokur (tek satırı değil) ve komut döngüden yaptığı aynı kaynaktan okur (bu nedenle döngü bir kez çalışır read, ilk satırı awkokur , sonra gerisini okur). Nasıl çalışması gerektiği belli değil.