Results 1 to 14 of 14
  1. #1
    Join Date
    Mar 2009
    Posts
    6

    Question Unanswered: Monitor sybase connections

    How could I write shell scripts in UNIX to monitor the connection to serveral sybase servers?

    Say, to send email alert when I fail to connect or connected with errors?

    These monitor should be run perioldically and alert me once there is connection issues.

    Could anybody advice?

  2. #2
    Join Date
    Mar 2007
    Posts
    72
    Sam,
    First you need to set a setting in sybase "log audit logon failure" which will record any login failure in the sybase error log. you shell script should read the error log and look for new entries and grep for the message where there is a login failue and then send emails appropriately. you could make use of "xp" server.

  3. #3
    Join Date
    Mar 2009
    Posts
    6
    Thanks sudarao.

    But my difficulty is, the sybase servers are not owned by me and I only got a unix server. How could I do it in this way? Thanks

  4. #4
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    Do you have an ID and passwd
    if isql fail to cennect your return code will not be 0

  5. #5
    Join Date
    Mar 2009
    Posts
    6
    I have id and password.

    The most usual case I need to handle is that, how I could get noticed when the sybase servers are down (i.e. I attempt to connect but nothing returns, or returned with errors)

  6. #6
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    Run something like this from cron
    Code:
    #!/usr/bin/ksh
    log1="/tmp/${0##*/}.$$.log"
    . $HOME/SYBASE.sh # set sybase env
    isql -Ume -P`cat .$1` -S$1 -i /dev/null 2>&1 >$log1
    test $? -ne 0 && mailx -s "Error connecting to $1" "$2" <$log1
    rm -f $log1

  7. #7
    Join Date
    Mar 2009
    Location
    Sydney, Australia
    Posts
    258
    That's a fairly common need, and a conventional method of going about it. Also check for timeouts (if it cannot connect, it is still waiting, at 60 secs, then the servers are very slow, and you want to be notified).

    Nice tight script. However the password will be visible to anyone executing "ps ...". Therefore ensure the login has no privileges whatsoever, or hide it.
    Regards
    Derek Asirvadem (Formerly DerekA)
    Information Architect / Senior Sybase DBA
    Copyright 2009 Software Gems Pty Ltd

    I answer questions from the Original Poster only. If you have a genuine question, as the moderators have requested, start a new thread.

    http://www.softwaregems.com.au

  8. #8
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    Quote Originally Posted by Derek Asirvadem
    the password will be visible to anyone executing "ps ..."
    Not the case with later versions
    But be safe and check yours to be sure
    Code:
    isql -v
    Sybase CTISQL Utility/12.5.1/P-EBF13140 ESD #12/DRV.12.5.1.4/SPARC/Solaris 2.8/BUILD1251-045/64bit/OPT/Thu Jan 12 21:17:43 2006
    
    isql -Ume -P`cat .$DSQUERY` -w333
    1> !!ps -ef | grep isql
    [sh:ps -ef | grep isql]
      syb125 29113 29090   0 16:26:44 pts/1       0:00 isql -Ume - -w333
      syb125 29127 29126   0 16:27:22 pts/1       0:00 grep isql
      syb125 29126 29113   0 16:27:22 pts/1       0:00 sh -c ps -ef | grep isql
    PS. To prevent continues notification when a server is down
    On sending the error mail
    touch a file notified.<srv_name>
    before sending another mail check for this files existence
    On successful connect remove the file notified.<srv_name>

  9. #9
    Join Date
    Mar 2009
    Posts
    6
    Quote Originally Posted by Derek Asirvadem
    That's a fairly common need, and a conventional method of going about it. Also check for timeouts (if it cannot connect, it is still waiting, at 60 secs, then the servers are very slow, and you want to be notified).

    Nice tight script. However the password will be visible to anyone executing "ps ...". Therefore ensure the login has no privileges whatsoever, or hide it.
    Yes, this is exactly what I need to have. But, how?

  10. #10
    Join Date
    Mar 2009
    Posts
    6
    Quote Originally Posted by pdreyer
    Run something like this from cron
    Code:
    #!/usr/bin/ksh
    log1="/tmp/${0##*/}.$$.log"
    . $HOME/SYBASE.sh # set sybase env
    isql -Ume -P`cat .$1` -S$1 -i /dev/null 2>&1 >$log1
    test $? -ne 0 && mailx -s "Error connecting to $1" "$2" <$log1
    rm -f $log1
    Thanks pdreyer, I am also writing sth similar, but not as concise as yours

    I need a better mechanism to manage the case when the server is slow. Is there any nice script to do so?

  11. #11
    Join Date
    Mar 2009
    Location
    Sydney, Australia
    Posts
    258
    Quote Originally Posted by penguinsam
    Yes, this is exactly what I need to have. But, how?
    From the Utility Ref Manual:

    -l login_timeout
    specifies the maximum timeout value allowed when connecting to Adaptive
    Server. The default is 60 seconds. This value affects only the time that isql
    waits for the server to respond to a login attempt. To specify a timeout period
    for command processing, use the -t timeout parameter.

    Therefore, the default is 60 secs, and good enough for most sites, but for your purpose (indicating a slow or busy server) you might use 15 secs. The following gets you past the naked password issue, and having to strip "Password:" out of the output file, as well.

    echo $PASSWD | isql -Uname -iin_file -oout_file ...

    Simply trap all errors (grep is easy), and check for the specific error. IIRC, it is a Net-Library error (you did not get to the server, there is no Sybase error number):
    Net-lib protocol driver call to connect two endpoints failed.

    And you are right, shell script code needs to be really simple and maintainable. This is one of the few cases that more is better; one function per line, scripting for dummies; is a Good Thing.
    Last edited by Derek Asirvadem; 04-07-09 at 11:50.
    Regards
    Derek Asirvadem (Formerly DerekA)
    Information Architect / Senior Sybase DBA
    Copyright 2009 Software Gems Pty Ltd

    I answer questions from the Original Poster only. If you have a genuine question, as the moderators have requested, start a new thread.

    http://www.softwaregems.com.au

  12. #12
    Join Date
    Mar 2007
    Posts
    86

    Sybase error log script -- Rob Verschoor open source

    Tool for automatically checking the ASE errorlog

    I've used this script for years .. I run it in cron every 15 minutes.

    I've made mods to it to extend the error checking for Sybase 15, and other customizations (pager etc).
    Search on egrep and add your error msgs there ..

    .

  13. #13
    Join Date
    Mar 2009
    Location
    Sydney, Australia
    Posts
    258
    It looks like PenguinSam wants to monitor dataserver, not the errorlog.
    Regards
    Derek Asirvadem (Formerly DerekA)
    Information Architect / Senior Sybase DBA
    Copyright 2009 Software Gems Pty Ltd

    I answer questions from the Original Poster only. If you have a genuine question, as the moderators have requested, start a new thread.

    http://www.softwaregems.com.au

  14. #14
    Join Date
    Mar 2009
    Posts
    6
    Quote Originally Posted by Derek Asirvadem
    It looks like PenguinSam wants to monitor dataserver, not the errorlog.
    Yes But the script by stuarta is still worth-studying

Posting Permissions

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