Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # PING WRAPPER ------------------------------------------------
- # source: http://www.cyberciti.biz/tips/unix-linux-bash-shell-script-wrapper-examples.html
- _getdomainnameonly(){
- # Name: _getdomainnameonly
- # Arg: Url/domain/ip
- # Returns: Only domain name
- # Purpose: Get domain name and remove protocol part, username:password and other parts from url
- # get url
- local h="$1"
- # upper to lowercase
- local f="${h:l}"
- # remove protocol part of hostname
- f="${f#http://}"
- f="${f#https://}"
- f="${f#ftp://}"
- f="${f#scp://}"
- f="${f#scp://}"
- f="${f#sftp://}"
- # Remove username and/or username:password part of hostname
- f="${f#*:*@}"
- f="${f#*@}"
- # remove all /foo/xyz.html*
- f=${f%%/*}
- # show domain name only
- echo "$f"
- }
- # Name: ping() wrapper
- # Arg: url/domain/ip
- # Purpose: Send ping request to domain by removing urls, protocol, username:pass using system /usr/bin/ping
- ping(){
- local t="$1"
- local _ping="/usr/bin/ping"
- local c=$(_getdomainnameonly "$t")
- [ "$t" != "$c" ] && echo "Sending ICMP ECHO_REQUEST to \"$c\"..."
- $_ping -n -c 4 -i 0.2 -W1 $c
- }
- # END PING WRAPPER ------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement