Storing received value from send, spawned telnet session
Hi Guys,
I'm completely new to bash and trying to write a script to spawn a telnet session to retrieve the RSSI value of my device and log the average value of the RSSI over 20 samples. I know that my command does return the RSSI value successfully but my bash scripting is letting me down.
I'm attempting to send the command, store the returned value over 20 samples and then averaging it - storing it in a log file.
Any help would be greatly appreciated.
Here's what i've got so far
Code:
#!/usr/bin/expect
set ip [lindex $argv 0]
spawn telnet $ip
exec > "$2"
sleep 2
for h in {0..20}
do
echo "Running test $h"
send "iwconfig wlan0 | grep -o \"Signal level=....\" | cut -c14-16"
set val $expect_out(buffer)
echo "RSSI: $val"
result +=val
done
result = result/20
echo "Average RSSI &result"
Last edited by vbe; 02-13-2014 at 11:11 AM..
Reason: code tags not icode!
---------- Post updated at 07:38 AM ---------- Previous update was at 04:59 AM ----------
Additional question - I have to convert the numbers as the value of the RSSI is in dB, how do i print out the values rather than just the formula:
Code:
#!/usr/bin/expect -f
set timeout 8
log_user 0
set ip [lindex $argv 0]
spawn -noecho telnet $ip
sleep 2
set count 0
set result 0
set value 0
set resultDb 0
send "PS1='PROMPT# '\r"
expect -re "PROMPT# '(.*)PROMPT# "
while {$count < 20} {
send "iwconfig wlan0 | grep -o \"Signal level=....\" | cut -c14-16\r"
expect -re "\r\n(.*)\r\n(.*)PROMPT# "
set valdB $expect_out(1,string)
set value 10^($valdB/10)
set result [expr $result+$value ]
set count [expr $count+1 ]
}
send "exit\r"
expect eof
set result [expr $result/20 ]
set resultdB 10*log(($result/10)/log(10))
puts "Average RSSI $resultdB"
I'm still having a problem with this code.
After a little bit of digging to figure out which calculation was going wrong, I found it to be the line:
Code:
set val [expr 10^($val/10)]
For an RSSI of -73 the output of result says -14 when it should be
10 ^(-73/10) = 5 * 10^-08
My guess is that it's some kind of wrapping going on, how do I avoid this?
Again, thank you so much for all your time and help.
Here is my code so far, please ignore my debug puts "$ "
Code:
#!/usr/bin/expect -f
set timeout 8
log_user 0
set ip [lindex $argv 0]
spawn -noecho telnet $ip
sleep 2
set count 0
set result 0.0
set val 0.0
send "PS1='PROMPT# '\r"
expect -re "PROMPT# '(.*)PROMPT# "
while {$count < 20} {
send "iwconfig wlan0 | grep -o \"Signal level=....\" | cut -c14-16\r"
expect -re "\r\n(.*)\r\n(.*)PROMPT# "
set val $expect_out(1,string)
puts "$val"
#convert
set val [expr 10^($val/10)]
puts "$val"
set result [expr $result+$val ]
puts "$result"
set count [expr $count+1 ]
}
send "exit\r"
expect eof
puts "$result"
#average
set result [expr $result/20.0 ]
puts "$result"
#convert back to dB
puts "$result"
set result [expr 10*log(($result/10.0)/log(10))]
puts "Average RSSI $result"
As you can probably guess tcl is not a very powerful mathematical language. The ^ operator is bitwise exclusive OR not a power function. What you are after is pow():
Code:
set val [expr pow(10,$val/10.0)]
Checkout this tcl expr for more info on the expr command.
Last edited by Chubler_XL; 02-18-2014 at 01:21 PM..
Reason: Added helpfull link
Hi,
I'm trying to spawn a telnet process and trying to do some actions in the remote host using expect script. I would like to know how to suppress all the output in order the user using the script should not be able to see any actions done on the remote host. I tried using the "log_user 0"... (8 Replies)
Our network administrators implemented some sort of check to kill idle sessions and now burden is on us to run some sort of keep alive. Client based keep alive doesn't do a very good job. I have same issue with ssh. Does solution 2 provided above apply for ssh sessions also? (1 Reply)
How can I disconnect an existing telnet session? The host is a serial port server with multiple ports. The users login using the host's name and a port, i.e. telnet host01 1235.
Thanks. (14 Replies)
Hello,
I have AIX 5.3 at home connected to netgear router. Port Forwarding has been enabled on the router. Problem is that if I want to telnet, I have to try 2 or 3 times before I can get a logon prompt. It times out for first or second time (Connection to session <IP_Address> failed: Connection... (1 Reply)
{
sleep 2
echo "$user"
sleep 2
echo "$password"
sleep 2
echo " ls"
sleep 10
echo "exit"
}| telnet $server
I have a machine x and i have executed the above script on machine 'x'.
i entered the... (6 Replies)
Dear friends..
Our project has a module that runs on handheld devices. Through the handheld we telnet to solaris where the application actually runs. I noticed that after starting a session through the handheld, if i go out of range or if i remove and replace the battery in the handheld, the... (1 Reply)
Hello Experts,
Happy New Year to all of us,
In AIX 4.3.3 I am trying to figure out how is possible to find out the IP address that a telnet session - user uses to login in to host machine. My objective is by finding the login IP address to allow the user to login or not.
All users uses the... (6 Replies)