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
fiif [[ $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$fileif [ $verbose = “true” ]
then
cat $map$file
fi# Get curent file
ncftpget -cV -u $serverU -p $serverP $server $serverMAP$file > $map$file.Oif [[ ! -z $( diff -q $map$file $map$file.O ) ]]
then
# Upload fileif [ $verbose = “true” ]
then
diff $map$file $map$file.O
echo Uploading file
fincftpput -V -u $serverU -p $serverP -r2 -t600 -DD -m $server $serverMAP $map$file
elseif [ $verbose = “true” ]
then
echo Online file up to date
fi
fifi
# 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”
fiecho $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 🙂