small, useful scripts
Results 1 to 5 of 5

Thread: small, useful scripts

  1. #1
    Senior Member
    Join Date
    Mar 2004
    Posts
    557

    small, useful scripts

    Hi

    Here on AO, quite a few creative minds hang around.
    Hence, I had the following idea:

    I think a lot of us use some tiny scripts on a daily basis -
    scripts which (at least ) you think are "killer"-scripts
    ie are amazingly useful and elegant and ..., you know.
    These could be scripts showing all shares on your LAN,
    making use of nmap and other tools to create an extended
    fingerprinting, whatever - and you want to present
    them to us.

    There is no such a thing like a criterion which script you
    can share with us, however it would be nice if it is <4kb
    (without comments) and written by yourself. You can also
    assume that we are omnipotent ie have all programs, tools
    and services available.

    Note: it is the idea which is important, not the actual
    implementation.



    My contribution:


    Motivation: Writing sms on a cell phone is cumbersome, and it
    costs money. Crucial server notification mails are somewhere in your
    mailbox, while you are enjoying your cocktail at the beach.

    Description: Friends can send me short emails, which will be
    sent to my cell phone as a sms (can be extended to server
    notifications etc. and hence is security related).
    This is done by including a "[SMS]" in the subject.

    Requirements:
    - procmail[1]. Excellent tutorial, here on AO[2].
    - email-sms-service (by your cell-phone provider, ISP, ...). In my case: it's free.


    procmail-block:
    Code:
    :0 HB
    * ^Subject:.*\[SMS\]
    {
    #create a email-copy anyway in your mailbox
     :0 c
     /var/spool/mail/yourname
    
    #create a a file in your procmail directory, e.g. ~/mail/pm
     :0 c
     |cat >/home/yourname/mail/pm/tmp.dat
    
    #start a script in your procmail directory, e.g. ~/mail/pm
     :0 
     |/home/yourname/mail/pm/sms.sh
    
    }

    shell script sms.sh:
    Code:
    #!/bin/bash
    #cell phone info
    my_number=1234567890
    my_roamer=sms.myprovider.com
    
    #maximal message length
    max_message=110
    
    #header delimiter (check yourself how your email-headers ends)
    header_end="version=2.64"
    
    #switch to the procmail directory
    cd /home/yourname/mail/pm
    
    #prepare info short message (subject and sender)
    cat tmp.dat |grep Subject >tmp.sms
    cat tmp.dat |grep From: >>tmp.sms
    tail -c$max_message tmp.sms > tmp.sms.cut
    
    #send the info short message (maybe identify yourself, depending on your local settings)
    mail $my_number@$my_roamer < tmp.sms.cut > /dev/null
    
    #a short message with just the tail of the file (not a good idea due to the possible existence of signatures)
    #tail -c$max_message tmp.dat >tmp.sms.cut
    
    #a short message send the first $max_message chars of the body (better choice, but "end of header" has to be checked from time to time)
    cut_here=`grep -n $header_end tmp.dat | awk -F: '{print $1}' |head -1`
    length_of_tmp=`wc -l tmp.dat | awk '{print $1}'`
    cut_here=$(($length_of_tmp-$cut_here))
    cat  tmp.dat |tail -$cut_here >tmp.sms
    
    head -c$max_message tmp.sms > tmp.sms.cut
    
    #send the body short message  (maybe identify yourself, depending on your local settings)
    mail $my_number@$my_roamer < tmp.sms.cut > /dev/null
    
    #clean up
    rm tmp.dat
    rm tmp.sms
    rm tmp.sms.cut
    Remarks:
    Here, one email generates two messages: A subject-from message and one message based on the "body".
    You could of course split the whole email into blocks and send several short messages, but be careful:
    what happens if a friend of yours sends you a 2MB pdf-file...



    I hope, that some of you can contribute to this thread.
    It's always astonishing, which ideas are floating around on
    this very planet earth.

    Cheers




    [1] http://www.icewalkers.com/Linux/Soft.../procmail.html
    or cygwin: http://linux.rz.ruhr-uni-bochum.de/d...ease/procmail/
    [2] http://www.antionline.com/showthread...hreadid=237207
    If the only tool you have is a hammer, you tend to see every problem as a nail.
    (Abraham Maslow, Psychologist, 1908-70)

  2. #2
    Junior Member
    Join Date
    Oct 2004
    Posts
    2
    Good not so bad . some errors are hidden find
    it up

  3. #3
    Junior Member
    Join Date
    Jan 2005
    Posts
    1

    automatic fetching some infos from telnet servers

    i need a script to connect to my 100+ solaris boxes and retrieve some info into a local log file.
    i was thinking about using netcat from my Windows box to do it, but so far i am too stupid to figure out how to make it connect automatically, execute some commands and log the output locally.

    my 1st (failed) attemt :
    nc -v -v -t 10.11.12.13 23 < inputext.txt > output.txt

    [input.txt contains:]
    username
    password
    command1
    exit

    [output.txt receives:]
    #'$#'$SunOS 5.7login: Password:

    looks like i would need some delay control or something to get this working...
    can somebody help me out a here?
    any other scripts doing the same stuff would be fine too (eg. python for example)

    cheers, blood.omen

  4. #4
    AO Senior Cow-beller
    Moderator
    zencoder's Avatar
    Join Date
    Dec 2004
    Location
    Mountain standard tribe.
    Posts
    1,177

    Re: automatic fetching some infos from telnet servers

    Originally posted here by blood.omen
    <snipped>

    looks like i would need some delay control or something to get this working...
    can somebody help me out a here?
    any other scripts doing the same stuff would be fine too (eg. python for example)
    Check out Expect for Windows. I am unfamiliar with Expect on the Windows platform, but I know it is very powerful for scripting this sort of thing with *NIX platforms.
    "Data is not necessarily information. Information does not necessarily lead to knowledge. And knowledge is not always sufficient to discover truth and breed wisdom." --Spaf
    Anyone who is capable of getting themselves made president should on no account be allowed to do the job. --Douglas Adams (1952-2001)
    "...people find it far easier to forgive others for being wrong than being right." - Albus Percival Wulfric Brian Dumbledore

  5. #5
    AO Curmudgeon rcgreen's Avatar
    Join Date
    Nov 2001
    Posts
    2,716
    [output.txt receives:]
    #'$#'$SunOS 5.7login: Password:
    Don't use the telnet port. It's just sending you a login prompt. Use a random
    port instead.
    I came in to the world with nothing. I still have most of it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

 Security News

     Patches

       Security Trends

         How-To

           Buying Guides