Solved How to get hostname IP address

Hi,

I am writing a script that will be part of a jail flavour...
What I want to do is to add the host IP to /etc/ssh/sshd.conf so it only listen to that IP.

So far I managed to find the IP address using the script bellow:
Code:
#!/bin/sh
#
# Test ssh listen address swap

test1=$(ifconfig | grep 'inet')
echo "ListenAddress $test1"
This script return
Code:
ListenAddress      inet 10.5.20.15 netmask 0xffffffff

How can I get rid of the 'inet' and the netmask so I am left with only the IP?

Thank you in advance
 
Just one more question if I may.
Code:
#!/bin/sh
#
# Test ssh listen address swap
hostname_ip=$(ifconfig lo1 | grep inet | cut -w -f3)
#echo "ListenAddress $hostname_ip"


INIFILE="/etc/ssh/sshd_config"
perl -p -i -e '
s/.*#ListenAddress[[:space:]]0.0.0.0.*/ListenAddress $hostname_ip/;
' "$INIFILE"
When I run that script and look at the /etc/ssh/sshd_config I get from
Code:
#ListenAddress 0.0.0.0
to
Code:
ListenAddress
It is missing the $hostname_ip value.
Can I pass a variable value when running a perl script?
Do I need to do it a different way?
 
On a machine that hasn't got Perl install which of the pkg should iI install for such small job?
is pecl-perl-1.0.1 the right one to go for?
 
on a machine that hasn't got perl install which of the pkg should i install for such small job?
is pecl-perl-1.0.1 the righ one to go for?
Why not just use: sed -i "" "s/.*#ListenAddress[[:space:]]0.0.0.0.*/ListenAddress $hostname_ip/" /etc/sshd/sshd_config
 
tobik the script doesn;t work for some reason.. I don't get the cursor back and the swap didn't occur
I have quickly edited the line after I posted it to add -i "" for inline editing, but you were too fast and quoted the old version. Sorry about that. Which one did you use?
 
First one..
Changed it sed -i "" "s/.*#ListenAddress[[:space:]]0.0.0.0.*/ListenAddress $hostname_ip/" /etc/ssh/sshd_config and I'm a very happy chap :)

Thank you for educating me.. I need to check man to understand how sed work so I know how..
 
Back
Top