Script error with when input is empty


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script error with when input is empty
# 1  
Old 03-31-2009
Data Script error with when input is empty

Hi,

I created the following shell script to lookup multiple name servers for a domain.

Code:
#!/bin/bash

echo -n "Enter the domain name and press [ENTER]: "
read domain


result1=`dig +short $domain @4.2.2.1`
revresult1=`host $result1 | cut -f5 -d " "`

echo "test1"

result2=`dig +short $domain @dns1.vistapages.com`
revresult2=`host $result2 | cut -f5 -d " "`

echo "test2"

result3=`dig +short $domain @dns2.vistapages.com`
revresult3=`host $result3 | cut -f5 -d " "`



echo "test3"
result4=`dig +short $domain @ns1.hostmds.com`
revresult4=`host $result4 | cut -f5 -d " "`

echo "test4"
result5=`dig +short $domain @ns1.hostmds.com`
revresult5=`host $result5 | cut -f5 -d " "`

echo "test5"
result6=`dig +short $domain @dns1.hostingplex.com`
revresult6=`host $result6`

echo "test6"
result7=`dig +short $domain @dns2.hostingplex.com`
revresult7=`host $result7`

echo "test7"
echo "================================="

echo " Result at Verizon DNS : $result1"
echo " Reverse at Verizon DNS : $revresult1"

echo "================================="
echo " Result at dns1.vistapages.com  : $result2"
echo " Reverse at dns1.vistapages.com : $revresult2"
echo "================================="

echo " Result at dns2.vistapages.com : $result3"
echo " Reverse at dns2.vistapages.com : $revresult3"

echo "================================="

echo " Result at ns1.hostmds.com : $result4"
echo " Reverse at ns1.hostmds.com : $revresult4"

echo "================================="
echo " Result at ns2.hostmds.com : $result5"
echo " Reverse at ns2.hostmds.com : $revresult5"

echo "================================="

echo " Result at dns1.hostingplex.com : $result6"
echo " Reverse at dns1.hostingplex.com  : $revresult6"
echo "================================="


echo " Result at dns2.hostingplex.com : $result7"
echo " Reverse at dns2.hostingplex.com : $revresult1"

But when the dns server do not have any result the script generates error.

Code:
Enter the domain name and press [ENTER]: test.com
test1
Usage: host [-aCdlriTwv] [-c class] [-N ndots] [-t type] [-W time]
            [-R number] hostname [server]
       -a is equivalent to -v -t *
       -c specifies query class for non-IN data
       -C compares SOA records on authoritative nameservers
       -d is equivalent to -v
       -l lists all hosts in a domain, using AXFR
       -i IP6.INT reverse lookups
       -N changes the number of dots allowed before root lookup is done
       -r disables recursive processing
       -R specifies number of retries for UDP packets
       -t specifies the query type
       -T enables TCP/IP mode
       -v enables verbose output
       -w specifies to wait forever for a reply
       -W specifies how long to wait for a reply
       -4 use IPv4 query transport only
       -6 use IPv6 query transport only
       -s a SERVFAIL response should stop query
test2
Usage: host [-aCdlriTwv] [-c class] [-N ndots] [-t type] [-W time]
            [-R number] hostname [server]
       -a is equivalent to -v -t *
       -c specifies query class for non-IN data
       -C compares SOA records on authoritative nameservers
       -d is equivalent to -v
       -l lists all hosts in a domain, using AXFR
       -i IP6.INT reverse lookups
       -N changes the number of dots allowed before root lookup is done
       -r disables recursive processing
       -R specifies number of retries for UDP packets
       -t specifies the query type
       -T enables TCP/IP mode
       -v enables verbose output
       -w specifies to wait forever for a reply
       -W specifies how long to wait for a reply
       -4 use IPv4 query transport only
       -6 use IPv6 query transport only
       -s a SERVFAIL response should stop query
test3
Usage: host [-aCdlriTwv] [-c class] [-N ndots] [-t type] [-W time]
            [-R number] hostname [server]
       -a is equivalent to -v -t *
       -c specifies query class for non-IN data
       -C compares SOA records on authoritative nameservers
       -d is equivalent to -v
       -l lists all hosts in a domain, using AXFR
       -i IP6.INT reverse lookups
       -N changes the number of dots allowed before root lookup is done
       -r disables recursive processing
       -R specifies number of retries for UDP packets
       -t specifies the query type
       -T enables TCP/IP mode
       -v enables verbose output
       -w specifies to wait forever for a reply
       -W specifies how long to wait for a reply
       -4 use IPv4 query transport only
       -6 use IPv6 query transport only
       -s a SERVFAIL response should stop query
test4
Usage: host [-aCdlriTwv] [-c class] [-N ndots] [-t type] [-W time]
            [-R number] hostname [server]
       -a is equivalent to -v -t *
       -c specifies query class for non-IN data
       -C compares SOA records on authoritative nameservers
       -d is equivalent to -v
       -l lists all hosts in a domain, using AXFR
       -i IP6.INT reverse lookups
       -N changes the number of dots allowed before root lookup is done
       -r disables recursive processing
       -R specifies number of retries for UDP packets
       -t specifies the query type
       -T enables TCP/IP mode
       -v enables verbose output
       -w specifies to wait forever for a reply
       -W specifies how long to wait for a reply
       -4 use IPv4 query transport only
       -6 use IPv6 query transport only
       -s a SERVFAIL response should stop query
test5
test6
test7
=================================
 Result at Verizon DNS : 205.178.152.103
 Reverse at Verizon DNS : w2k3-cfm3.prod.netsolhost.com.
=================================
 Result at dns1.vistapages.com  : 
 Reverse at dns1.vistapages.com : 
=================================
 Result at dns2.vistapages.com : 
 Reverse at dns2.vistapages.com : 
=================================
 Result at ns1.hostmds.com : 
 Reverse at ns1.hostmds.com : 
=================================
 Result at ns2.hostmds.com : 
 Reverse at ns2.hostmds.com : 
=================================
 Result at dns1.hostingplex.com : 208.83.209.12
 Reverse at dns1.hostingplex.com  : 12.209.83.208.in-addr.arpa domain name pointer 208-83-209-12.mdswireless.com.
=================================
 Result at dns2.hostingplex.com : 208.83.209.12
 Reverse at dns2.hostingplex.com : w2k3-cfm3.prod.netsolhost.com.

How can I get rid of these errors.
# 2  
Old 03-31-2009
Quote:
Originally Posted by mohitmoudgil
Hi,

I created the following shell script to lookup multiple name servers for a domain.

Code:
#!/bin/bash

echo -n "Enter the domain name and press [ENTER]: "
read domain


result1=`dig +short $domain @4.2.2.1`
revresult1=`host $result1 | cut -f5 -d " "`

How can I get rid of these errors.

Check whether the command was successful:

Code:
if result1=`dig +short $domain @4.2.2.1`
then
   revresult1=`host $result1 | cut -f5 -d " "`
fi

Or check for content in the variable:

Code:
result1=`dig +short $domain @4.2.2.1`
if [ -n "$result1" ]
then
   revresult1=`host $result1 | cut -f5 -d " "`
fi

# 3  
Old 03-31-2009
Hi,

Thank you very much!! You got it working.
Code:
#!/bin/bash

result1="NULL"
result2="NULL"
result3="NULL"
result4="NULL"
result5="NULL"
result6="NULL"
result7="NULL"

revresult1="NULL"
revresult2="NULL"
revresult3="NULL"
revresult4="NULL"
revresult5="NULL"
revresult6="NULL"
revresult7="NULL"


echo -n "Enter the domain name and press [ENTER]: "
read domain


result1=`dig +short $domain @4.2.2.1`

if [ -n "$result1" ]
then

revresult1=`host $result1 | cut -f5 -d " "`

fi


result2=`dig +short $domain @dns1.vistapages.com`

if [ -n "$result2" ]
then

revresult2=`host $result2 | cut -f5 -d " "`
fi



result3=`dig +short $domain @dns2.vistapages.com`

if [ -n "$result3" ]
then

revresult3=`host $result3 | cut -f5 -d " "`

fi


result4=`dig +short $domain @ns1.hostmds.com`


if [ -n "$result4" ]
then
revresult4=`host $result4 | cut -f5 -d " "`
fi


result5=`dig +short $domain @ns1.hostmds.com`
if [ -n "$result5" ]
then

revresult5=`host $result5 | cut -f5 -d " "`
fi


result6=`dig +short $domain @dns1.hostingplex.com`

if [ -n "$result6" ]
then
revresult6=`host $result6`
fi



result7=`dig +short $domain @dns2.hostingplex.com`
if [ -n "$result7" ]
then

revresult7=`host $result7`
fi





echo "================================="

echo " Result at Verizon DNS : $result1"
echo " Reverse at Verizon DNS : $revresult1"

echo "================================="
echo " Result at dns1.vistapages.com  : $result2"
echo " Reverse at dns1.vistapages.com : $revresult2"
echo "================================="

echo " Result at dns2.vistapages.com : $result3"
echo " Reverse at dns2.vistapages.com : $revresult3"

echo "================================="

echo " Result at ns1.hostmds.com : $result4"
echo " Reverse at ns1.hostmds.com : $revresult4"

echo "================================="
echo " Result at ns2.hostmds.com : $result5"
echo " Reverse at ns2.hostmds.com : $revresult5"

echo "================================="

echo " Result at dns1.hostingplex.com : $result6"
echo " Reverse at dns1.hostingplex.com  : $revresult6"
echo "================================="


echo " Result at dns2.hostingplex.com : $result7"
echo " Reverse at dns2.hostingplex.com : $revresult1"

Now I want the domain input should be taken from a webpage like a text field, not the command line.

Can you please help me in that.
# 4  
Old 03-31-2009
Hi,

I could execute the script on webpage by hardcoding the domain name

http://mohitmoudgil.com/cgi-bin/test2.sh

but how can I take the value on the web page itself.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to reformat output if input file is empty, but not if file has data in it

The below awk improved bu @MadeInGermany, works great as long as the input file has data in it in the below format: input chrX 25031028 25031925 chrX:25031028-25031925 ARX 631 18 chrX 25031028 25031925 chrX:25031028-25031925 ARX 632 14... (3 Replies)
Discussion started by: cmccabe
3 Replies

2. Shell Programming and Scripting

Script regarding non numerical or empty value

Hello Team, I need bash script to check if my output is non numerical or empty. if its then my output should display default value as 0 basically, I am reading value from txt file. most of numerical value, in case there is no numerical value or its empty, then my output should be 0. ... (5 Replies)
Discussion started by: ghpradeep
5 Replies

3. Shell Programming and Scripting

Script to delete files with an input for directories and an input for path/file

Hello, I'm trying to figure out how best to approach this script, and I have very little experience, so I could use all the help I can get. :wall: I regularly need to delete files from many directories. A file with the same name may exist any number of times in different subdirectories.... (3 Replies)
Discussion started by: *ShadowCat*
3 Replies

4. Shell Programming and Scripting

Need to avoid empty line error

Hi, Below shell script executes based on liasted data files parameters.But small problem need to avoid ,If any empty line occures in dat files it's throwing oracle error .Need to ignore empty lines (means does not ready by script).Please advice. #/bin/sh adsts=`cat... (2 Replies)
Discussion started by: krajasekhar.v
2 Replies

5. Shell Programming and Scripting

perl script to check if empty files are created and delete them and run a shell script

I have a local linux machine in which the files are dumped by a remote ubuntu server. If the process in remote server has any problem then empty files are created in local machine. Is there any way using perl script to check if the empty files are being created and delete them and then run a shell... (2 Replies)
Discussion started by: hussa1n
2 Replies

6. Shell Programming and Scripting

Bash Script verify user input is not empty and is equal to a value

I need to create a script that has a user enter a value. I want to verify that the value is either 1,2, or 3. If it is not then I want them to try entering it again. I am using a while loop to force them to retry. I am able to test the input against 1,2, and 3, but when I test agains an... (4 Replies)
Discussion started by: spartiati
4 Replies

7. Shell Programming and Scripting

empty option output error

I have a script (multirun.sh) which launches the program bsim_em.x or bsim_es.x depending on the value entered from the screen: > multirun.sh 1 (executes bsim_em.x) > multirun.sh 2 (executes bsim_es.x) which, simplifying, I do with the following lines in the multirun.sh script: if ... (3 Replies)
Discussion started by: josegr
3 Replies

8. UNIX for Dummies Questions & Answers

if a file is empty throw an error

I want to count the number of lines in a file and store it in a variable if this count is zero i hv to throw an error ...is this syntax correct , but i am not getting the desired result I am not using -s option here as i am concerned about record count not the size #!/bin/ksh set $count1... (4 Replies)
Discussion started by: mavesum
4 Replies

9. UNIX for Dummies Questions & Answers

Getting same exit status for empty and non empty file

Hi All, I am checking for a empty input file to do some further action , but I am getting exit status 0 in both the cases , for empty and non empty file both. The value of $? is coming 0 in if part also and else part too. #!/bin/ksh if ]; then echo "data" # exit 0 echo "$?" else... (4 Replies)
Discussion started by: mavesum
4 Replies

10. Shell Programming and Scripting

nawk empty regular expression error

Hello, All. please help me with this problem. i need to use variable as regular expression. some thing like this: BEGIN { RS="\n"; ORS="\n"; reg_exp = ".+Dec.+"; # i mean that regular expression is any symbol before "Dec" and any symbol after it. For example <Worksheet... (6 Replies)
Discussion started by: Rjkz
6 Replies
Login or Register to Ask a Question