Login to remote server

I mentioned earlier to someone – I dont have a fixed ip; so I need some tricks to be able to connect from anywhere. The first trick is server side.

This script is on my server & hourly run.. I posted this earlier already

# Variables
## Location & filename for temporary files
map=”/tmp/”
file=”telenet”

## Remote Webserver settings
server= #webserver adress
serverU= #User
serverP= #Pass
serverMAP= # Server map

## Webpage with IP info page
IPpage=http://192.168.0.1/st_device.html
IPu= #Router User
IPp= #Router Pass

## IP base to ignore – to filter out local IPs
IPbase=192.168.0.

## Do not edit beyond this point 😉

if [[ $1 == “-v” ]]
then
verbose=true
else
verbose=false
fi

if [[ $map == “” || $map == “/” || $file == “” ]]
then
echo “Thank god I didnt trust you to fill these out wisely.”
echo ” (dont get over confident tough, this is an EXTREMELY basic test!!)”
echo “At least One of the following errors was found!”
echo
echo “* the map and file variable can NOT be empty!”
echo “* the map can NOT be / (the root).”
echo “Since we re doing rm -f, these settings might cost you your OS!”
echo “  ;)”
echo
echo $map$file
exit 1
fi

# make sure there s no files that could screw the process 😉
rm $map$file* -f

# Get IP
wget -q –user $IPu –password $IPp $IPpage -O $map$file.router

# check for file existance
if [[ -e $map$file.router ]]
then
grep Address $map$file.router -A 5 |  grep -oE [0-9]+.[0-9]+.[0-9]+.[0-9]+ | grep -v $IPbase > $map$file

if [ $verbose = “true” ]
then
cat $map$file
fi

# Get curent file
ncftpget -cV -u $serverU -p $serverP $server $serverMAP$file > $map$file.O

if [[ ! -z $( diff -q $map$file $map$file.O ) ]]
then
# Upload file

if [ $verbose = “true” ]
then
diff $map$file $map$file.O
echo Uploading file
fi

ncftpput -V -u $serverU -p $serverP -r2 -t600 -DD -m $server $serverMAP $map$file
else

if [ $verbose = “true” ]
then
echo Online file up to date
fi
fi

fi

# remove residual files
rm $map$file* -f

This works nice!

And to make it easy on my end, there s this one too..

 # Global
user=”gert” #SSH User
command=”ssh”

# Internal
IIp=”192.168.0.100″
IMagicWord=”Kabouter” # Word in internal page to check on

# External
EIp_Source=”” #External IP location
ETunnel=”-L 80:localhost:80″ # What SSH tunnel you want – optional
EPort=”-p 1234″ #SSH port on server should it be differen – optional

# The Magic
if [[ $( curl -s –connect-timeout 1 $IIp | grep -o $IMagicWord ) = $IMagicWord ]];
then
command=”$command $user@$IIp”
else
command=”sudo $command $user@$( curl -s $EIp_Source ) $EPort $ETunnel”
fi

echo $command
$command

God I need this on my ever active Soekris box.. Instead of having to keep my noisy old server on :/I REALLY look forward to having that machine in place! And a second one 🙂

Published by Gert

Person-at-large.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: