Email: bknpk@hotmail.com Phone: +972-54-7649119
V

 

ASIC/FPGA Design and Verification Out Source Services

Sending Mail via Kmail and Dcop From The Command Line

Motivation:
Sometime there is a need to operate KMAIL from the command line. You may want to create a better mail filter or an automatic response etc. I use it to send an e-mail to myself whenever the ISP cheanges my IP.

What is my IP?:
The scripts, which follow, will show two ways to detect your external IP on a linux machine.
In one case the linux is connected to the net via an ADSL modem. In this case the command:
/sbin/ifconfig | grep "inet addr" is used and the response is:
inet addr:192.168.25.1 Bcast:192.168.25.255 Mask:255.255.255.0
inet addr:127.0.0.1 Mask:255.0.0.0
inet addr:88.152.109.103 P-t-P:88.152.109.1 Mask:255.255.255.255

If the network is via router than finding out the external IP of the router might be by getting a response form a site, which tells you your IP address. To get the IP address, execute the command:
perl web_req.pl http://www.whatismyip.org/ whatismyip
The response is 88.152.109.103.
The perl script is at web_req.pl

How To Send Mail:

  1. First I configured KMAIL to send mail without asking for confirmation.
  2. Here is a little script, which sends mail:
  3. #!/bin/bash
    #1 To address
    #2 CC address
    #3 BCC address
    #4 subject
    #5 body
    dcop kmail KMailIface openComposer "$1" "$2" "$3" "$4" "$5" 0
    dcop kmail kmail-composer#1 activateAction "send_default"

    PERL script to check IP and notify on change:
    A few notes on the script:

  4. The script runs forever. It does its check every hour.
  5. If it sees a file stop.txt, regardless of its content, it'll stop.
  6. Invocation is like this: perl ip_update.pl "88.2.3.4"
  7. #!/bin/perl
    system("rm -f stop.txt");
    $flg=1;
    $last=$ARGV[0];
    print("$last\n");
    while($flg == 1) {
      $ip=`/sbin/ifconfig | grep "inet addr.*P-t-P"`;
      if($ip =~ /inet addr:(.*\..*\..*\..*) *P-t-P/) {
        $ip1=$1;
        $ip1 =~ s/ //g;
        $ip =~ s/^ *//g; chomp($ip);
      }
      $cmd="\/home\/lxuser\/bin\/PKsend.unx bknpk\@hotmail.com beky1\@walla.co.il \"\" \"" . $ip1 . "\" \"" . $ip . "\"";
      if($ip1 ne $last) {
        print("$cmd\n");
        system("$cmd");
        $last=$ip1;
      }
      sleep(3600);
      if( (-e "stop.txt") ) {
        die("ended by user\n");
      }
    }#while

Contact me now at:

  ...


I would be happy to offer my services. Call ASAP !


Home

Send mail With Telnet

Download Area






Search This Site


Feedback This Site




new pages on this site