Here it is!!! My first Python script!
PHP Code:
#!/usr/bin/env python
#
# This script will ping to google.bg and if network is
# unreachable it will connect to the modem and reboot it.
import os
import commands
import pexpect
def adsl_reboot():
p = pexpect.spawn('telnet 192.168.1.1')
p.expect('Login user: ')
p.sendline('root') # Sending Username.
p.expect('Password: ')
p.sendline('GSrootaccess') # Sending Password.
p.expect('> ')
p.sendline('reboot') # Sending command to the shell.
os.system('zenity --notification --text="The modem has been rebooted."')
# Show an icon in the notification area
result = commands.getoutput("ping -c 1 google.bg")
if result.find("Unreachable") == -1:
result = True
print 'Connected!'
else:
result = False
print 'Not connected! - Rebooting the modem.'
if result == False:
adsl_reboot()
#
# This was my first script.
# Author: Boris Bolgradov
#
# Big thanks to: walkerk, days_of_ruin and Psykotik!
# http://ubuntuforums.org
http://ubuntuforums.org/showthread.php?t=847218
http://www.noah.org/wiki/Pexpect#Description_of_Pexpect
Edit: I fixed it. Thanks LaRoza.