Last change
on this file since 31555 was 30038, checked in by ak19, 9 years ago |
Modified IPv4 scripts to take the parameter -format-for-tomcat-context if it needs to format the IPv4 address. If not passed this flag, it will return the IPv4 address unformatted. build.xml is now updated to pass this flag to the scripts.
|
-
Property svn:executable
set to
*
|
File size:
1.6 KB
|
Line | |
---|
1 | #!/bin/bash
|
---|
2 |
|
---|
3 | # This script will echo the IPv4 of this unix machine. E.g. 100.200.300.45
|
---|
4 | # If passed -format-for-tomcat-context, it will echo the same with a pipe
|
---|
5 | # symbol up front and all the . escaped with a "\". E.g. "|100\.200\.300\.45"
|
---|
6 |
|
---|
7 | #http://www.wikihow.com/Find-Your-IP-Address-on-a-Mac#Finding_Your_Internal_IP_Using_the_Terminal_sub
|
---|
8 | #http://stackoverflow.com/questions/1469849/how-to-split-one-string-into-multiple-strings-in-bash-shell
|
---|
9 | #http://www.linuxforums.org/forum/red-hat-fedora-linux/193076-ifconfig-doesnt-display-ipv4-address.html
|
---|
10 |
|
---|
11 |
|
---|
12 | # The following echoes the IPv4, e.g. 100.200.300.45
|
---|
13 | # But need to still replace the . with \.
|
---|
14 |
|
---|
15 | #echo `ifconfig | grep "inet " | grep -v 127.0.0.1`|cut -d' ' -f 2|cut -d':' -f 2
|
---|
16 |
|
---|
17 | tmp=`ifconfig | grep "inet " | grep -v 127.0.0.1`
|
---|
18 |
|
---|
19 | tmp=`echo $tmp|cut -d' ' -f 2|cut -d':' -f 2`
|
---|
20 |
|
---|
21 | # if requested to format the IPv4 for the solr.xml tomcat context file
|
---|
22 | if [ "$1" == "-format-for-tomcat-context" ]; then
|
---|
23 |
|
---|
24 | #http://stackoverflow.com/questions/13210880/replace-one-substring-for-another-string-in-shell-script
|
---|
25 | #${original_string//searchterm/$string_to_replace_searchterm_with}
|
---|
26 | replace="."
|
---|
27 | replacement="\."
|
---|
28 |
|
---|
29 | tmp=${tmp//$replace/$replacement}
|
---|
30 |
|
---|
31 | # next, if the tmp variable is not the empty string, prefix the | operator
|
---|
32 | # http://unix.stackexchange.com/questions/146942/how-can-i-test-if-a-variable-is-empty-or-contains-only-spaces
|
---|
33 | # Can just return | if $tmp is empty, as that doesn't really matter. Will be consistent with windows
|
---|
34 | if [[ ! -z "${tmp// }" ]]; then
|
---|
35 | tmp="|$tmp"
|
---|
36 | else
|
---|
37 | tmp="|"
|
---|
38 | fi
|
---|
39 |
|
---|
40 | fi
|
---|
41 |
|
---|
42 | echo $tmp
|
---|
43 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.