2017-04-11 7 views
1
#!/bin/bash 
echo -n "Enter the domain name > " 
read name 
dig -t ns "$name" | cut -d ";" -f3 | cut -d ":" -f2| grep ns | cut -f6 > registerfile.txt; 
cat registerfile.txt | while read line; do dig axfr "@$line" "$name"; done | cut -d"." -f-4 > nmap.txt 

このセクションまで実行されます。以下では、行と名前のパラメータと一致しない可能性があります。どのように変更する必要がありますか?bashの論理的アプローチ

cat nmap.txt | while read line; do if [ "$line" == "$name" ]; then host "$line"; fi; done > ping.txt 
cat ping.txt | cut -d " " -f4 | while read line; do if [[ "$line" =~ ^[0-9]+$ ]]; then nmap -sS "$line";fi ;done 
+1

'if [" $ line == "$ name"]; '' $行に '' 'がありません – iamauser

+0

ありがとう、もう1つの質問:cat nmap.txt |一方、読取りライン。 if "$ line" == "$ name"]; "$ line"をホストします。 fi; done> ping.txtは動作しません。つまり、論理的なエラーは発生しませんが、論理的なアプローチを修正する方法はありますか? – user1532437

+1

[cat'sの無用な使い方について]何かしたいかもしれません(http://www.iki.fi/era/unix/award.html)。 – tripleee

答えて

1

それは物事がうまく行っている場所を正確に明確ではないのですが、ここでうまくいけば、少なくとも正しい方向にあなたを微調整するかもしれませんリファクタリングです。 if [ "$line" = "$name" ]; then host "$line"; fiが動作していないことをコメント欄に

#!/bin/bash 
read -p "Enter the domain name > " name 
dig +short -t ns "$name" | 
tee registerfile.txt | 
while read line; do 
    dig axfr "@$line" "$name" 
done | 
cut -d"." -f-4 | 
tee nmap.txt | 
while read line; do 
    if [ "$line" = "$name" ]; then 
     host "$line" 
    fi 
done > ping.txt 
cut -d " " -f4 ping.txt | 
grep -E '^[0-9]+$' | 
xargs -r -n 1 nmap -sS 

あなたの発言はロジックが何らかの形で間違っていることを示唆しています。現在、各行が元のドメイン名と同一であるかどうかをチェックし、そのような場合に何度も何度も検索します。これは好奇心が強いようです。コードだけと「うまくいきません」とすれば、本当に達成すべきことを言うのは難しいです。実際に何か他のものが必要な場合は、必要なものをより具体的にする必要があります。おそらく、あなたは実際には複数の静的に指定されたファイルの使用は、アンチパターンである

... tee nmap.txt | 
# Extract the lines which contain $name at the end 
grep "\.$name\$" | 
xargs -n 1 dig +short | 
tee ping.txt | 
grep -E '^[0-9]+$' ... 

のようなものを探しています。明らかに、これらのファイルが外的な目的を果たさない場合は、teeコマンドを取り出し、中間の出力ファイルなしでパイプライン全体を実行してください。これらのファイルが必要な場合は、それぞれの実行時に上書きするのが問題になります。ファイル名に一意の日付スタンプの接尾辞を追加することは可能でしょうか?

関連する問題