Ok, ik heb het aan de gang! met het programma Expect inderdaad.. (die kan je zo vinden op
www.rpmfind.net)
Allereerst het script dat test of er verbdinding is, en zonodig reboot (deze kan je bijvoorbeeld met cron schedulen):
PHP:
1
2
3
4
5
6
7
8
9
10
11
| ping www.xs4all.nl -c 4 > /root/modem/online
pings=`grep 64 /root/modem/online -c`
if [ "$pings" = "4" ]; then
#Hier dus niks doen
echo Internet online $(date +%Y-%m-%dat%k:%M) >> /root/modem/log
exit
else
#Hier rebooten
echo Internet Reboot $(date +%Y-%m-%dat%k:%M) >> /root/modem/log
expect /root/modem/script.exp
fi |
Als er geen verbinding is, wordt dus 'expect /root/modem/script.exp' uitgevoerd.
Ik heb script.exp gemaakt met 'autoexpect' dat programma logt je telnet sessie en maakt er een .exp van. Om eem file te maken (voor bijvoorbeeld rebooten) type je
'autoexpect -f script.exp telnet 10.0.0.138'
Alles tot je uitlog van telnet wordt dan in script.exp gestopt.
Mijn script.exp ziet er zo uit:
PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
| #!/usr/bin/expect -f
set force_conservative 0 ;# set to 1 to force conservative mode even if
;# script wasn't run conservatively originally
if {$force_conservative} {
set send_slow {1 .1}
proc send {ignore arg} {
sleep .1
exp_send -s -- $arg
}
}
set timeout -1
spawn telnet 10.0.0.138
match_max 100000
expect -exact "Trying 10.0.0.138...\r\r
Connected to 10.0.0.138.\r\r
Escape character is '^\]'.\r\r
User : "
send -- "\r"
expect -exact "\r
\rSpeedTouch (00-90-D0-1C-FF-EC)\r
\rPassword : "
send -- "p"
expect -exact "#"
send -- "a"
expect -exact "#"
send -- "s"
expect -exact "#"
send -- "s"
expect -exact "#"
send -- "w"
expect -exact "#"
send -- "o"
expect -exact "#"
send -- "r"
expect -exact "#"
send -- "d"
expect -exact "#"
send -- "\r"
send -- "s"
expect -exact "\r=>s"
send -- "y"
expect -exact "\r=>sy"
send -- "s"
expect -exact "\r=>sys"
send -- "t"
expect -exact "\r=>syst"
send -- "e"
expect -exact "\r=>syste"
send -- "m"
expect -exact "\r=>system"
send -- "\r"
expect -exact "\r
\r\\[system\]=>"
send -- "r"
expect -exact "\r\\[system\]=>r"
send -- "e"
expect -exact "\r\\[system\]=>re"
send -- "b"
expect -exact "\r\\[system\]=>reb"
send -- "o"
expect -exact "\r\\[system\]=>rebo"
send -- "o"
expect -exact "\r\\[system\]=>reboo"
send -- "t"
expect -exact "\r\\[system\]=>reboot"
send -- "\r"
expect -exact "\r
\r"
send -- "\r"
expect eof |
[
Voor 0% gewijzigd door
mocean op 27-10-2002 19:54
. Reden: Klein foutje in path (/root/modem vergeten) ]