mirror of
https://github.com/Hizenberg469/Makefile-tutorial.git
synced 2026-04-20 06:12:23 +03:00
created shell dir
This commit is contained in:
38
shell/regex.sh
Normal file
38
shell/regex.sh
Normal file
@@ -0,0 +1,38 @@
|
||||
#!/bin/bash
|
||||
|
||||
#provide one word/sentence as an argument to the script.
|
||||
#If in that sentence will be ip addresss, find out, if that
|
||||
#ip address is reachable or not.
|
||||
|
||||
#argument check
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "Provide exactly one argument e.g. $0 argument"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
VAR1=$1
|
||||
#ip address regex
|
||||
REGEX="[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[[:digit:]]{1,3}"
|
||||
|
||||
#regex check
|
||||
if ! [[ $VAR1 =~ $REGEX ]]; then
|
||||
echo "No IP address provided"
|
||||
exit 2
|
||||
fi
|
||||
|
||||
IP=${BASH_REMATCH[0]}
|
||||
|
||||
#find if ip address is reachable or not
|
||||
ping -c4 $IP 1>/dev/null
|
||||
|
||||
#1>/dev/null
|
||||
#It will redirect standard output and prevent
|
||||
#any output to print on screen.
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
STATUS="ALIVE"
|
||||
else
|
||||
STATUS="DEAD"
|
||||
fi
|
||||
|
||||
echo "IP found: $IP ($STATUS)"
|
||||
Reference in New Issue
Block a user