0

I have a script that I made when I was at home on a Kali virtual machine. It works perfectly there, but now I'm at work on my Xubuntu install and it's not working at all. The exact shell that I'm using via the help command is GNU bash version 4.2.25. I'm not sure what shell I have at home (assume it's the latest version). I'm assuming that the shell I have here at work is older and therefore doesn't support some of the things I'm using in the script? When I run it here it prints out the header and footer but nothing in between. Any help or advice would be appreciated.

#!/bin/bash

echo ""
echo "######## WHOIS: "$1

# Whois using the inputted parameter
whois $1 |\

# Remove EOL characters
tr -d '\015\032' |\

# Remove spaces
sed 's/^ *//' |\

# Remove unnecessary words from output
grep -v -e "@" -e "http://" -e "WHOIS" > temp.txt

# Display all of the date lines
egrep -i "ate: " temp.txt

# Remove the tmp file
rm -rf temp.txt

echo "------- DONE!"
echo ""
5
  • run it like "bash -x script_name.sh" and you should get an answer. somethins like : whois is not installed. try to install it using ....
    – malyy
    May 19, 2016 at 13:27
  • Hmm, when I run "bash -x ./whois.sh google.com" it gives me what seems to be just a printout of my code. Thanks for the recommendation, any idea what this could mean? pastebin.com/raw/88X3jksF
    – Egrodo
    May 19, 2016 at 13:35
  • Looks like there is no output into temp.txt... try to use tee at line 19 (egrep -i "ate: " temp.txt | tee), or don't remove the file while you investigate
    – malyy
    May 19, 2016 at 13:47
  • Try and take a look at the contents of temp.txt before you delete it or don't delete it at the end so you can examine it after the command runs. That way you can make sure the contents of that file are correct and you can determine where the issue is. May 19, 2016 at 13:47
  • Doing so, I investigated the temp file to find that the example I was attempting to use, google.com, resolved to show 50 records like "google.com.ar, google.com.forsale, google.com.do", and it seems it's not sure which one to use. When I type a domain that doesn't have any alternates it seems to work fine. The strange thing is that the same command worked at home, hmm..
    – Egrodo
    May 19, 2016 at 13:50

1 Answer 1

1

Your comments and blank lines are destroying the pipe connectivity. Use this:

#!/bin/bash

echo ""
echo "######## WHOIS: "$1

whois $1 |
tr -d '\015\032' |
sed 's/^ *//' |
grep -v -e "@" -e "http://" -e "WHOIS" |
egrep -i "ate: " 

echo "------- DONE!"
echo ""

You don't need a line continuation if the pipe is at the end of the line. If you want your comments, put them in a block above the pipeline.

1
  • 4
    Actually you can put comments at the end of the line, provided that you terminate the line with |, not with ``. A backslash only means “the command continues on the next line” if it's immediately before the newline character, which leaves no room for a command. A pipe as the last token of the line indicates that the command continues on the next line, it can be followed by whitespace and a comment. May 19, 2016 at 21:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .