Plh01

From Harding
Jump to: navigation, search
[root@melchior eli]# more client.py 
from sys import argv
from socket import *


#if ($#argv <> 4) then
#        echo "you must give exactly four parameters From, To, Subject ,Message"
#endif

set from=$argv[1]
set to=$argv[2]
set subject=$argv[3]
set msg=$argv[4]

temp='-from:'+from+' -to:'+ to +' -s:'+subject+' -msg:'+ message
print temp

print argv[1]
socketObj=socket(AF_INET,SOCK_STREAM)
socketObj.connect(('203.3.69.60',1111))
socketObj.send(temp)
socketObj.close()


#!/usr/bin/env python

import os,time
from socket import *

#---------------------------------------------------------------------

class server:
   """
   This is ....
   """

   myHost='203.3.69.60'
   myPort=1112

   def __init__(self):
      print "hi"
      self.initCon() 
      self.dispatcher()


   def initCon(self):
      self.serverSocket=socket(AF_INET,SOCK_STREAM)   
      self.serverSocket.bind((self.myHost,self.myPort))
      self.serverSocket.listen(5)

   #----- dispatcher ----------------------------------------

   def dispatcher(self):
      while 1 :
         self.con , self.add =self.serverSocket.accept()
         print 'Client connected fron ', self.add, 'at ', time.ctime(time.time()) 
         self.handleClient()

   
   def handleClient(self):
      data=self.con.recv(1024)
      print data
      self.sendMail(data)
      #self.sendNetMsg(data)
      self.con.close()


   def sendSMS(self,msg):
      os.system('minicom configuration ttyS2set -S sms.sh')


   def sendMail(self,msg):
      temp='postie -host:maia.pha.com.au '+ msg
      print temp
      os.system(temp)

   def sendNetMsg(self,msg):
   #   'net send 192.168.69.9 sg'
      temp= 'net send 192.168.69.9 %s'%msg
      print temp
      os.system(temp)


   def __del__(self):
      print "bye"

#---------------------------------------------------------------------

s = server()

#---------------------------------------------------------------------


[root@melchior eli]# cat sendmail.sh 
#/bin/sh 


if ($#argv <> 4) then
        echo "you must give exactly four parameters From, To, Subject ,Message"
endif

set from=$argv[1]
set to=$argv[2]
set subject=$argv[3]
set msg=$argv[4]

echo $from
echo $to
echo $subject 
echo $msg

#sendmail -t
#From:$from
#To:$to
#Subject:$subject
#$msg


[root@melchior eli]# cat sms.sh 
#!/bin/sh

cat -u < /dev/ttyS1  >> /var/log/sms.log &

MSG=`cat /tmp/msg`
DATE=`date`

cat > /dev/ttyS1 << XxXxX
atz
at+csca="+61418706700"
at+csas
at+cmgs="+61405232969"
$DATE
$MSG

XxXxX

ps -ef | grep "cat -u" | grep -v grep 
PID=`ps -ef | grep "cat -u" | grep -v grep  | awk '{print $2}'`

sleep 10

if [ "$PID" != "" ] ; then
   kill -9 $PID
fi


[root@melchior eli]# cat sms.sh 
#!/bin/sh

cat -u < /dev/ttyS1  >> /var/log/sms.log &

MSG=`cat /tmp/msg`
DATE=`date`

cat > /dev/ttyS1 << XxXxX
atz
at+csca="+61418706700"
at+csas
at+cmgs="+61405232969"
$DATE
$MSG

XxXxX

ps -ef | grep "cat -u" | grep -v grep 
PID=`ps -ef | grep "cat -u" | grep -v grep  | awk '{print $2}'`

sleep 10

if [ "$PID" != "" ] ; then
   kill -9 $PID
fi


[root@melchior eli]# cat sendSms.sh 
#/bin/sh

minicom configuration ttyS1set -S sms.minicom