Tag Archives: shell script

Shell Script to Detect If the IP Address Is Googlebot

Recently I wanted to check if the IPs ( I had around 45) belonged to google bot. One option was to run host <ip> and host <domain name> for each of the IPs, but this was practically not possible and if possible it would be time consuming. So I came up with a simple shell script to do this job.

Let the IPs be in the file googlebots, for example let us add these IPs:

The shell script is given below:

while read -r line
    hostName=`host $line | cut -d" " -f 5`
    domainName=`echo $hostName | cut -d"." -f2,3`
    #echo $domainName
    #echo "$hostName"
    hostIp=`host $hostName | cut -d" " -f 4`
    #echo "$hostIp"
    if [ $line == $hostIp ] && [ $domainName == "googlebot.com" ]
        echo "Googlebot: $hostIp -> $hostName"
done < "$file"

Shell script for clearing the Trash

I was facing a problem while clearing the Trash in Ubuntu. I wasn’t able to delete certaion folder and i got the message stating “Access Denied”. So i was wondering that there should be some way to do it from the command prompt using sudo and some command. I did a google for the requirement and found the following shell snippet:

rm -rf ~/.local/share/Trash/

Source: Ubuntu Forum.