-eq 0 ] then /root/scripts/test1.sh exit 0 fi done It will check after if the command succeeds. Hello, I am trying to develop a script to check for valid hostnames. Below are the prerequisites for a valid hostname which I got from wiki : Hostnames are composed of series of labels concatenated with dots, as are all domain names. last searches back through the file /var/log/wtmp (or the file designated by the -f flag) and displays a list of all users logged in (and out) since that file was created. And here goes the e-mail body, test test test.. I think it is best to do a loop that contains one ping and check if this ping succeed. Line 6 - The backslash ( \ ) in front of the single quote ( ' ) is needed as the single quote has a special meaning for bash and we don't want that special meaning. Following example proves the same. Bash Strings Equal – In this tutorial, we shall learn how to check if two strings are equal in bash scripting.. Bash Strings Equal. if [ -f / home / tutorialkart / sample.txt ]; then echo "sample.txt - File exists." Check the current hostname using /etc/hostname file. bash if -f #!/bin/bash . To check if two strings are equal in bash scripting, use bash if statement and double equal to == operator.. To check if two strings are not equal in bash scripting, use bash if statement and not equal to!= operator.. In this tutorial you will learn how to find your IP address using a Linux operating system. @0xC0000022L: Nobody "keeps me" from doing that, but the answer specifically suggests hosts, and so far 4 people have upvoted vinc17's comment expressing the pain caused by "suddenly IPv6".Being prepared for IPv6 is not always the issue: many programs need a way to determine whether two names/addresses refer to the same host. One can test that a bash variable starts with a string or character in bash efficiently using any one of the following methods. That's it - you can now test sendmail from command line and even send full e-mails including headers from Linux/UNIX shell. It is useful to verify A record and provides warning if ‘A’ record is not same on all master / slave nameservers. By passing the parameters '-c 30' to ping, it will try 30 ping and stop. For example, "en.wikipedia.org" is a hostname. How do I ping a specific port? This shell script uses host DNS lookup utility to check A record for given domain / host against all nameservers. Something like that: while true; do ping -c1 google.com if [ $? ping works with both IPv4 and IPv6. $ cat /etc/hostname daygeek-Y700 Method-4: Check the HostName using uname Command in Linux. bash if -f : Check if file exists and is a regular file. At last we send the e-mail template we just created with: sendmail -vt < ~/mail.txt. Names of users and tty's can be given, in which case last will show only those entries matching the arguments. An IP address is a codename assigned to a computer on a network. It works as a postal address, ensuring that network traffic is sent to the correct computer. Is it possible possible to ping an 192.168.1.254:80 or 192.168.1.254:23 ports? Below is an example of how the simple sendmail test could look like on a live system: You use the ping command to send ICMP ECHO_REQUEST packets to network computers, routers, switches and more. I wanted to see if a specific port of a desktop computer or server is open from a Linux or Unix command line shell. You can have as many commands here as you like. uname (stands for unix name) is an utility that prints the system information like name, version and other details about the system and the operating system running on it. Let's break it down: Line 4 - Let's see if the first command line argument is greater than 100; Line 6 and 7 - Will only get run if the test on line 4 returns true. 3.) if statement when used with option f , returns true if the length of the string is zero. 2. Using last command. Example – Strings Equal Scenario Introduction – In bash, we can check if a string begins with some value using regex comparison operator =~.