This discussion is archived
1 2 3 Previous Next 30 Replies Latest reply: Dec 16, 2013 7:06 AM by f5af4ed6-d9eb-4a60-ab07-b8728143a148 RSS

Linux daemon connect to oracle.

f5af4ed6-d9eb-4a60-ab07-b8728143a148 Newbie
Currently Being Moderated

My linux is kubuntu-12.04. I installed oracle client 10.2.0.5 and trying to connect to Oracle from Linux daemon. Daemon start, but don't connect to oracle.

if I authenticates in Linux as a specific user and run the daemon, the daemon connects to Oracle without any problems.

Help. How can I connect without authentication?

  • 1. Re: Linux daemon connect to oracle.
    sb92075 Guru
    Currently Being Moderated

    I don't know what you have.

    I don't know what you do.

    I don't know what you see.

    It is really, Really, REALLY difficult to fix a problem that can not be seen.

    use COPY & PASTE so we can see what you do & how Oracle responds.

  • 2. Re: Linux daemon connect to oracle.
    f5af4ed6-d9eb-4a60-ab07-b8728143a148 Newbie
    Currently Being Moderated

    Thank you for your answer.

    Today is Sunday. Please wait one day for more detailed information.

  • 3. Re: Linux daemon connect to oracle.
    f5af4ed6-d9eb-4a60-ab07-b8728143a148 Newbie
    Currently Being Moderated

    This is my linux.

    root@akrashenin:/home/capthree# uname -a

    Linux akrashenin.room209 3.5.0-42-generic #65-Ubuntu SMP Tue Oct 1 21:38:59 UTC 2013 i686 i686 i686 GNU/Linux

     

    file /etc/environment

    ORACLE_HOME="/usr/lib/oracle-10.2.0.5.client"

    PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"

     

    tnsnames.ora

    ORCL209 =

        (DESCRIPTION =

            (ADDRESS_LIST =

                (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.222.111)(PORT = 1521))

            )

            (CONNECT_DATA =

                (SERVICE_NAME = orcl209)

                (SERVER = DEDICATED)

            )

        )

  • 4. Re: Linux daemon connect to oracle.
    f5af4ed6-d9eb-4a60-ab07-b8728143a148 Newbie
    Currently Being Moderated

    /etc/profile

    # /etc/profile: system-wide .profile file for the Bourne shell (sh(1))

    # and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).

     

    if [ "$PS1" ]; then

      if [ "$BASH" ] && [ "$BASH" != "/bin/sh" ]; then

        # The file bash.bashrc already sets the default PS1.

        # PS1='\h:\w\$ '

        if [ -f /etc/bash.bashrc ]; then

          . /etc/bash.bashrc

        fi

      else

        if [ "`id -u`" -eq 0 ]; then

          PS1='# '

        else

          PS1='$ '

        fi

      fi

    fi

     

    # The default umask is now handled by pam_umask.

    # See pam_umask(8) and /etc/login.defs.

     

    if [ -d /etc/profile.d ]; then

      for i in /etc/profile.d/*.sh; do

        if [ -r $i ]; then

          . $i

        fi

      done

      unset i

    fi

     

    TNS_ADMIN=/usr/lib/oracle-10.2.0.5.client/network/admin/tnsnames.ora

    export TNS_ADMIN

    ORACLE_HOME=/usr/lib/oracle-10.2.0.5.client

    export ORACLE_PATH

    PATH=$PATH:/usr/lib/oracle-10.2.0.5.client/lib

    export PATH

    LD_LIBRARY_PATH=/usr/lib/oracle-10.2.0.5.client/lib

    export LD_LIBRARY_PATH

  • 5. Re: Linux daemon connect to oracle.
    f5af4ed6-d9eb-4a60-ab07-b8728143a148 Newbie
    Currently Being Moderated

    /etc/rc.local

    #!/bin/sh -e

    #

    # rc.local

    #

    # This script is executed at the end of each multiuser runlevel.

    # Make sure that the script will "exit 0" on success or any other

    # value on error.

    #

    # In order to enable or disable this script just change the execution

    # bits.

    #

    # By default this script does nothing.

     

    #./usr/sbin/demo_daemon

     

    #export LD_LIBRARY_PATH=/home/capthree/oracle-10.2.0.5.client/lib

    #export LD_LIBRARY_PATH=/usr/lib/oracle-10.2.0.5.client/lib

    /usr/sbin/mlget

    /usr/sbin/mltrans

     

    exit 0

  • 6. Re: Linux daemon connect to oracle.
    f5af4ed6-d9eb-4a60-ab07-b8728143a148 Newbie
    Currently Being Moderated

    main.cpp

     

    #include <iostream>

    #include <time.h>

    #include <fstream>

    #include "sys/stat.h"

    #include "use_oracle_db.h"

    #include "log_linux.h"

    #include "analyzer.h"

     

    #define TRANSMIT_LOG "transmit_email.log"

    #define CONFIG_FILE "transmit_email.cfg"

    #define USER_NAME_DEFAULT "USERRS1"

    #define CONNECT_STRING_DEFAULT "DBRS"

    #define PATH_EMAIL_DEFAULT "/home/mailuser/mail/email_from_ora"

    #define PATH_SCRIPT_DEFAULT "/home/mailuser/mail/email_script"

    #define EMAIL_DIR_DEFAULT "/home/mailuser/mail/from_space/"

    #define DELAY_DEFAULT 30

    #define DELAY_ORA_DEFAULT 999999999

     

    CLogFile *pLog = NULL;

    CAnalyzer *pAnlz = NULL;

     

    using namespace std;

    using namespace oracle::occi;

     

    int main(int argc, char *argv[])

    {

        string strLogFile;

        strLogFile = TRANSMIT_LOG;

     

    #ifdef DAEMON

        pid_t pid, sid;

     

      /* ╨₧╤é╨▓╨╡╤é╨▓╨╗╤Å╨╡╨╝╤ü╤Å ╨╛╤é ╤Ç╨╛╨┤╨╕╤é╨╡╨╗╤î╤ü╨║╨╛╨│╨╛ ╨┐╤Ç╨╛╤å╨╡╤ü╤ü╨░ */

          pid = fork();

          if (pid < 0) {

            exit(EXIT_FAILURE);

          }

          /* ╨ò╤ü╨╗╨╕ ╤ü PID'╨╛╨╝ ╨▓╤ü╨╡ ╨┐╨╛╨╗╤â╤ç╨╕╨╗╨╛╤ü╤î, ╤é╨╛ ╤Ç╨╛╨┤╨╕╤é╨╡╨╗╤î╤ü╨║╨╕╨╣ ╨┐╤Ç╨╛╤å╨╡╤ü╤ü ╨╝╨╛╨╢╨╜╨╛ ╨╖╨░╨▓╨╡╤Ç╤ê╨╕╤é╤î. */

          if (pid > 0) {

            exit(EXIT_SUCCESS);

          }

     

          /* ╨ÿ╨╖╨╝╨╡╨╜╤Å╨╡╨╝ ╤ä╨░╨╣╨╗╨╛╨▓╤â╤Ä ╨╝╨░╤ü╨║╤â */

          umask(0);

     

          /* ╨ù╨┤╨╡╤ü╤î ╨╝╨╛╨╢╨╜╨╛ ╨╛╤é╨║╤Ç╤ï╨▓╨░╤é╤î ╨╗╤Ä╨▒╤ï╨╡ ╨╢╤â╤Ç╨╜╨░╨╗╤ï */

          pLog = new CLogFile(strLogFile);

          pLog->writeLog("=== Daemon start");

          pLog->reopen();

     

          /* ╨í╨╛╨╖╨┤╨░╨╜╨╕╨╡ ╨╜╨╛╨▓╨╛╨│╨╛ SID ╨┤╨╗╤Å ╨┤╨╛╤ç╨╡╤Ç╨╜╨╡╨│╨╛ ╨┐╤Ç╨╛╤å╨╡╤ü╤ü╨░ */

          sid = setsid();

          if (sid < 0) {

            /* ╨û╤â╤Ç╨╜╨░╨╗╨╕╤Ç╤â╨╡╨╝ ╨╗╤Ä╨▒╨╛╨╣ ╤ü╨▒╨╛╨╣ */

            exit(EXIT_FAILURE);

          }

     

          /* ╨ÿ╨╖╨╝╨╡╨╜╤Å╨╡╨╝ ╤é╨╡╨║╤â╤ë╨╕╨╣ ╤Ç╨░╨▒╨╛╤ç╨╕╨╣ ╨║╨░╤é╨░╨╗╨╛╨│ */

          if ((chdir("/")) < 0) {

            /* ╨û╤â╤Ç╨╜╨░╨╗╨╕╤Ç╤â╨╡╨╝ ╨╗╤Ä╨▒╨╛╨╣ ╤ü╨▒╨╛╨╣ */

            exit(EXIT_FAILURE);

          }

     

          /* ╨ù╨░╨║╤Ç╤ï╨▓╨░╨╡╨╝ ╤ü╤é╨░╨╜╨┤╨░╤Ç╤é╨╜╤ï╨╡ ╤ä╨░╨╣╨╗╨╛╨▓╤ï╨╡ ╨┤╨╡╤ü╨║╤Ç╨╕╨┐╤é╨╛╤Ç╤ï */

          close(STDIN_FILENO);

          close(STDOUT_FILENO);

          close(STDERR_FILENO);

    #else

        pLog = new CLogFile(strLogFile);

    #endif

     

    //--------------------------------------------------------------------------

    #ifdef MY_DEBUG

        if(!pLog->isCreated()){

            cout << "Can't open or create logfile." << endl;

            return -1;

        }

    #endif

        std::string str;

        str = "=== Transmit of the message from Oracle for email is started!!!";

    #ifdef MY_DEBUG

        cout << str.c_str() << endl;

    #endif

        pLog->writeLog((char*)str.c_str());

        pLog->reopen();

    //----- analyzer configuration file

        try{

            pAnlz = new CAnalyzer((char*)CONFIG_FILE);

        }

        catch(...){

            str = "- Error: Can't open config file.";

            pLog->writeLog((char*)str.c_str());

            pLog->reopen();

            return -1;

        }

        int iRes = pAnlz->run();

        if(iRes == -1){

            pLog->writeLog("- Error: Can't open configure file.");

            pLog->reopen();

            return -1;

     

        }

        else{

            pLog->writeLog("+ Parsing the config file successful.");

            pLog->reopen();

        }

    //-------------------------------------------------------------------

        string strUser;

        string strPasswd;

        string strConnStr;

     

    //----- read config for user ----------------------------------------

        if(pAnlz){

            parsedIdentifier prsID;

            if(pAnlz->getIdentifier("USER_NAME","DATABASE",&prsID))

                strUser = prsID.strValue;

            else

                strUser = USER_NAME_DEFAULT;

        }

        else

            strUser = USER_NAME_DEFAULT;

    //----- read config for password ------------------------------------

        if(pAnlz){

            parsedIdentifier prsID;

            if(pAnlz->getIdentifier("PASS_WORD","DATABASE",&prsID))

                strPasswd = prsID.strValue;

            else

                strPasswd = "123";

        }

        else

            strPasswd = "123";

    //----- read config for connection string ---------------------------

        if(pAnlz){

            parsedIdentifier prsID;

            if(pAnlz->getIdentifier("CONNECT_STRING","DATABASE",&prsID))

                strConnStr = prsID.strValue;

            else

                strConnStr = CONNECT_STRING_DEFAULT;

        }

        else

            strConnStr = CONNECT_STRING_DEFAULT;

    //----- connect to Oracle -------------------------------------------

        CocciDML *pOra;

        std::string strValue;

        std::string strSQL;

        std::string strSQLSel;

        std::string strSQLUpd;

        FILE *fl;

     

        str = "* Try to connect to Oracle.";

    #ifdef MY_DEBUG

        cout << str.c_str() << endl;

    #endif

        pLog->writeLog((char*)str.c_str());

        pLog->reopen();

        try{

            pOra = new CocciDML(strUser,strPasswd,strConnStr);

        }

        catch(SQLException *ex){

    #ifdef MY_DEBUG

            cout << ex->what() << endl;

    #endif

        }

        unsigned int iRez=pOra->isConn();

        if(!iRez){

            str = "- Error: connection to Oracle is not successful.";

    #ifdef MY_DEBUG

            cout << str.c_str() << endl;

    #endif

            pLog->writeLog((char*)str.c_str());

            pLog->reopen();

            return -2;

        }

        else{

            str = "+ Connection to Oracle is successful.";

    #ifdef MY_DEBUG

            cout << str.c_str() << endl;

    #endif

            pLog->writeLog((char*)str.c_str());

            pLog->reopen();

        }

     

        string strDelay;

        string strDelayOra;

        int iDelay;

        int iDelayOra;

    //----- read config for delay ---------------------------------------

        if(pAnlz){

            parsedIdentifier prsID;

            if(pAnlz->getIdentifier("DELAY","DELAY",&prsID)){

                strDelay = prsID.strValue;

                iDelay = atoi(strDelay.c_str());

            }

            else

                iDelay = DELAY_DEFAULT;

        }

        else

            iDelay = DELAY_DEFAULT;

    //----- read config for Oracle delay --------------------------------

        if(pAnlz){

            parsedIdentifier prsID;

            if(pAnlz->getIdentifier("DELAY_ORA","DELAY",&prsID)){

                strDelay = prsID.strValue;

                iDelayOra = atoi(strDelay.c_str());

            }

            else

                iDelayOra = DELAY_ORA_DEFAULT;

        }

        else

            iDelayOra = DELAY_ORA_DEFAULT;

    //-------------------------------------------------------------------

        string strEmailPath;

        string strScriptPath;

        string strEmailDir;

    //----- read for emails ---------------------------------------------

        if(pAnlz){

            parsedIdentifier prsID;

            if(pAnlz->getIdentifier("PATH_EMAIL","EMAIL",&prsID))

                strEmailPath = prsID.strValue;

            else

                strEmailPath = PATH_EMAIL_DEFAULT;

        }

        else

                strEmailPath = PATH_EMAIL_DEFAULT;

    //-----

        if(pAnlz){

            parsedIdentifier prsID;

            if(pAnlz->getIdentifier("PATH_SCRIPT","EMAIL",&prsID))

                strScriptPath = prsID.strValue;

            else

                strScriptPath = PATH_SCRIPT_DEFAULT;

        }

        else

            strScriptPath = PATH_SCRIPT_DEFAULT;

    //-----

        if(pAnlz){

            parsedIdentifier prsID;

            if(pAnlz->getIdentifier("EMAIL_DIR","EMAIL",&prsID))

                strEmailDir = prsID.strValue;

            else

                strEmailDir = EMAIL_DIR_DEFAULT;

        }

        else

            strEmailDir = EMAIL_DIR_DEFAULT;

    //-------------------------------------------------------------------

     

        timespec tm_ora, tm_ora_rem;

        tm_ora.tv_sec = 0;

        tm_ora.tv_nsec = iDelayOra; //DELAY_ORA;

     

        pid_t pIDNew;

        pid_t pIDCur;

        pid_t pIDFork;

        pIDCur=getpid();

     

        char *newargv[] = {NULL,NULL};

        char *newenv[] = {NULL};

     

        string strPath;

     

        while(true){

            sleep(iDelay);

            iRes = pOra->isConn();

            if(iRes==-1){

                    delete pOra;

                try{

                    pOra = new CocciDML(strUser,strPasswd,strConnStr);

                }

                catch(SQLException *ex){

                    cout << "- ERROR: Disconnect from database!" << endl;

                    continue;

                }

                str = "* Reconnect to Oracle!!!";

    #ifdef MY_DEBUG

                cout << str.c_str() << endl;

    #endif

                pLog->writeLog((char*)str.c_str());

                pLog->reopen();

            }

    #ifdef RS

            strSQL = "select AUTOKEY from MSG_USR_DOWN where MSG_CLASS=3 and MSG_TYPE=1 \

            and STATE=1 order by AUTOKEY";

    #else

            strSQL = "select AUTOKEY from MSG_USER_DOWN where CLASS_MSG=3 and T_MSG=1 \

            and STATE=1 order by AUTOKEY";

    #endif

            pOra->selectData(strSQL.c_str());

            while(true){    // internal while

                int iNum = pOra->nextRow();

                if(iNum==ZERO){

                    break;

                }

                pOra->getStringFieldByNumber(strValue, 1);

    #ifdef RS

                strSQLSel="SELECT DATA FROM MSG_USR_DOWN WHERE AUTOKEY=";

    #else

                strSQLSel="SELECT DATA FROM MSG_USER_DOWN WHERE AUTOKEY=";

    #endif

                strSQLSel+=strValue;

                pOra->readBlob(strSQLSel.c_str());

                char *pData = pOra->getData();

    #ifdef MY_DEBUG

                cout << "data:\n" << pData << endl;

    #endif

    //------ write mail to file for transmit --------------------

                fl=fopen(strEmailPath.c_str(),"w");

                fwrite(pData,sizeof(char),pOra->getBlobLen(),fl);

                fclose(fl);

    //----- write email to local-mail directory -----------------

                char chBuffTM[32];

                pLog->timeInStr(chBuffTM);

                strPath = strEmailDir;

                strPath += chBuffTM;

     

                fl=fopen(strPath.c_str(),"a+");

                fwrite(pData,sizeof(char),pOra->getBlobLen(),fl);

    //-----------------------------------------------------------

                fclose(fl);

    #ifdef MY_DEBUG

                cout << "pIDFork: " << pIDFork << endl;

    #endif

                pIDFork=fork();

                pIDNew=getpid();

                if(pIDCur!=pIDNew){

    #ifdef MY_DEBUG

                    cout << "pIDCur: " << pIDCur << endl;

                    cout << "pIDNew: " << pIDNew << endl;

    #endif

                    execve(strScriptPath.c_str(),newargv,newenv);

                }

    #ifdef RS

                strSQLUpd="UPDATE MSG_USR_DOWN SET STATE=3 WHERE AUTOKEY=";

    #else

                strSQLUpd="UPDATE MSG_USER_DOWN SET STATE=3 WHERE AUTOKEY=";

    #endif

                strSQLUpd+=strValue;

                pOra->updateData(strSQLUpd.c_str());

                pOra->commitData();

     

                str = "* Transmit record, autokey: ";

                str += strValue;

    #ifdef MY_DEBUG

                cout << str.c_str() << endl;

    #endif

                pLog->writeLog((char*)str.c_str());

                pLog->reopen();

                nanosleep(&tm_ora,&tm_ora_rem);

            }   // end internal while

     

    #ifdef MY_DEBUG

            cout << "After sleep() function..." << endl;

    #endif

        };  // end while

     

        return 0;

    }

  • 7. Re: Linux daemon connect to oracle.
    f5af4ed6-d9eb-4a60-ab07-b8728143a148 Newbie
    Currently Being Moderated

    use_oracle_db.h

     

    #ifndef USE_ORACLE_DB

    #define USE_ORACLE_DB

     

    #include <occi.h>

    #include <oci.h>

    #include <occiControl.h>

    #include <string.h>

    #include "analyzer.h"

    #include "log_linux.h"

     

    #define ZERO 0

    #define BUFF_SIZE_ORA 5000000

     

    extern CLogFile *pLog;

    extern CAnalyzer *pAnlz;

     

    enum err_code{

        SUCCESS = 0,

        FAILURE_STM = -1,

        FAILURE_RES = -2,

        EODATA = -3,

        FAILURE_PNT = -4

    };

     

    using namespace oracle::occi;

    using namespace std;

     

    class CocciDML{

    private:

        Environment *m_env;

        Connection *m_conn;

        Statement *m_stmt;

        Statement *m_stmtBlob;

        Statement *m_stmtIns;

        Statement *m_stmtUpd;

        ResultSet *m_rset;

        ResultSet *m_rsetBlob;

        char m_buff[BUFF_SIZE_ORA];

        size_t m_uLenBlob;

    public:

        CocciDML(string userName = "DBTEST2", string password = "123"

                 , string connectString = "DB209"){

            m_env = Environment::createEnvironment();

            m_conn = NULL; m_stmt = NULL; m_rset =NULL; m_stmtIns = NULL;

            m_stmtBlob=NULL;

            m_rsetBlob=NULL;

            m_stmtUpd=NULL;

            m_uLenBlob=0;

            if(pAnlz){

                parsedIdentifier prsID;

                pAnlz->getIdentifier("USER_NAME","DATABASE",&prsID);

                userName = prsID.strValue;

     

                pAnlz->getIdentifier("PASS_WORD","DATABASE",&prsID);

                password = prsID.strValue;

     

                pAnlz->getIdentifier("CONNECT_STRING","DATABASE",&prsID);

                connectString = prsID.strValue;

            }

            try{

                std::string strMsg;

                strMsg = "* Begin of connection to Oracle.";

                pLog->writeLog(strMsg.c_str());

                pLog->reopen();

                m_conn = m_env->createConnection(userName,password,connectString);

            }

            catch(SQLException *ex){

                throw ex->what();

            }

        }

        ~CocciDML(){

            m_env->terminateConnection(m_conn);

            Environment::terminateEnvironment(m_env);

     

            //if(!m_pBlob) delete m_pBlob;

        }

        int isConn(){

            return (unsigned int) m_conn;

        }

        void commitData(){

            m_conn->commit();

        }

        ResultSet* selectData(const std::string strQuery){

            if(m_stmt){

                m_conn->terminateStatement(m_stmt);

                m_stmt = NULL;

            }

            m_stmt = m_conn->createStatement(strQuery);

            m_rset = m_stmt->executeQuery ();

            return m_rset;

        }

        int updateData(const std::string strQuery){

            m_stmtUpd = m_conn->createStatement(strQuery);

            int iRes = m_stmtUpd->executeUpdate();

            return iRes;

        }

        unsigned int getIntFieldByNumber(int iNum = 1){

            if(!m_stmt) return FAILURE_STM;

            if(!m_rset) return FAILURE_RES;

            return m_rset->getInt(iNum);

        }

        void getStringFieldByNumber(std::string& strValue, int iNum = 1){

            //std::string strValue;

            //strValue = "";

            if(!m_stmt) return; // NULL;

            if(!m_rset) return; // NULL;

            strValue = m_rset->getString(iNum);

            //return (char *) strValue.c_str();

        }

        int nextRow(){

            if(!m_stmt) return FAILURE_PNT;

            return m_rset->next();

        }

        void prepareInsertRow(const std::string sqlQuery){

            if(m_stmtIns) m_stmtIns = NULL;

            m_stmtIns = m_conn->createStatement(sqlQuery);

        }

        int executeInsert(){

            if(!m_stmtIns) return FAILURE_STM;

            return (int) m_stmtIns->executeUpdate();

        }

        void insertRowWithBlob(const string sqlQueryIns){

            Blob bl(m_conn);

            bl.setEmpty();

            if(m_stmt)

                m_conn->terminateStatement(m_stmt);

            m_stmt = m_conn->createStatement(sqlQueryIns);

            m_stmt->setBlob(1,bl);

            m_stmt->executeUpdate();

            m_conn->commit();

        }

        void updateBlobInRow(const string sqlQuerySel, char* buff, unsigned int nSize){

            Blob bl(m_conn);

            m_conn->terminateStatement(m_stmt);

            m_stmt = m_conn->createStatement(sqlQuerySel);

            this->m_rset = m_stmt->executeQuery();

            m_rset->next();

            bl = m_rset->getBlob(1);

            bl.write(nSize,(unsigned char*) buff,nSize,1);

            /*

            bl.open(OCCI_LOB_READWRITE);

            pBlob->write(unsigned int amt, // numder of bytes to be written

                     unsigned char *buffer, // buffer with the data

                     unsigned int bufsize,  // size of the buffer

                     unsigned int offset);    //starting position into the BLOB 1 or more.

            */

            m_conn->commit();

        }

        void readBlob(const string sqlQuerySel){

            //"SELECT DATA FROM USR_MSG_UP WHERE= "

            if(m_stmtBlob)

                m_conn->terminateStatement(m_stmtBlob);

            m_stmtBlob = m_conn->createStatement(sqlQuerySel);

            m_rsetBlob = m_stmtBlob->executeQuery();

            m_rsetBlob->next();

            Blob bl = m_rsetBlob->getBlob(1);

            memset(m_buff,'\0',BUFF_SIZE_ORA);

            int iSize = 0, offset = 1;

            char *pBuff;

            pBuff = m_buff;

            while(true){

                iSize = bl.read(64, (unsigned char*) pBuff, 64, offset);

                //process data read

                //move offset to read next

                if(iSize<=0 || (offset+iSize)>BUFF_SIZE_ORA) break;

                offset = offset + iSize;

                pBuff = pBuff+iSize;

            }

            m_uLenBlob = offset;

        }

        char *getData(){

            return m_buff;

        }

        size_t getBlobLen(){

            return m_uLenBlob;

        }

    };

     

    #endif  // USE_ORACLE_DB

  • 8. Re: Linux daemon connect to oracle.
    f5af4ed6-d9eb-4a60-ab07-b8728143a148 Newbie
    Currently Being Moderated

    log

     

    2013-12-09 13:17:51 === Daemon start

    2013-12-09 13:17:51 === Transmit of the message from Oracle for email is started!!!

    2013-12-09 13:17:51 + Parsing the config file successful.

    2013-12-09 13:17:51 * Try to connect to Oracle.

    2013-12-09 13:17:51 * Begin of connection to Oracle.

  • 9. Re: Linux daemon connect to oracle.
    BillyVerreynne Oracle ACE
    Currently Being Moderated

    OCI questions and issues should be raised in the Call Interface forum space.

     

    Also keep some basic Unix principles in mind for writing a daemon - it should run on the root file system, it should change its process owner, it should support a signal handler, etc.

  • 10. Re: Linux daemon connect to oracle.
    jgarry Guru
    Currently Being Moderated

    f5af4ed6-d9eb-4a60-ab07-b8728143a148 wrote:

     

    main.cpp

     

    #include <iostream>

    #include <time.h>

    #include <fstream>

    #include "sys/stat.h"

    #include "use_oracle_db.h"

    #include "log_linux.h"

    #include "analyzer.h"

     

    #define TRANSMIT_LOG "transmit_email.log"

    #define CONFIG_FILE "transmit_email.cfg"

    #define USER_NAME_DEFAULT "USERRS1"

    #define CONNECT_STRING_DEFAULT "DBRS"

    #define PATH_EMAIL_DEFAULT "/home/mailuser/mail/email_from_ora"

    #define PATH_SCRIPT_DEFAULT "/home/mailuser/mail/email_script"

    #define EMAIL_DIR_DEFAULT "/home/mailuser/mail/from_space/"

    #define DELAY_DEFAULT 30

    #define DELAY_ORA_DEFAULT 999999999

     

    CLogFile *pLog = NULL;

    CAnalyzer *pAnlz = NULL;

     

    using namespace std;

    using namespace oracle::occi;

     

    int main(int argc, char *argv[])

    {

        string strLogFile;

        strLogFile = TRANSMIT_LOG;

     

    #ifdef DAEMON

        pid_t pid, sid;

     

      /* ╨₧╤é╨▓╨╡╤é╨▓╨╗╤Å╨╡╨╝╤ü╤Å ╨╛╤é ╤Ç╨╛╨┤╨╕╤é╨╡╨╗╤î╤ü╨║╨╛╨│╨╛ ╨┐╤Ç╨╛╤å╨╡╤ü╤ü╨░ */

          pid = fork();

          if (pid < 0) {

            exit(EXIT_FAILURE);

          }

          /* ╨ò╤ü╨╗╨╕ ╤ü PID'╨╛╨╝ ╨▓╤ü╨╡ ╨┐╨╛╨╗╤â╤ç╨╕╨╗╨╛╤ü╤î, ╤é╨╛ ╤Ç╨╛╨┤╨╕╤é╨╡╨╗╤î╤ü╨║╨╕╨╣ ╨┐╤Ç╨╛╤å╨╡╤ü╤ü ╨╝╨╛╨╢╨╜╨╛ ╨╖╨░╨▓╨╡╤Ç╤ê╨╕╤é╤î. */

          if (pid > 0) {

            exit(EXIT_SUCCESS);

          }

     

          /* ╨ÿ╨╖╨╝╨╡╨╜╤Å╨╡╨╝ ╤ä╨░╨╣╨╗╨╛╨▓╤â╤Ä ╨╝╨░╤ü╨║╤â */

          umask(0);

     

          /* ╨ù╨┤╨╡╤ü╤î ╨╝╨╛╨╢╨╜╨╛ ╨╛╤é╨║╤Ç╤ï╨▓╨░╤é╤î ╨╗╤Ä╨▒╤ï╨╡ ╨╢╤â╤Ç╨╜╨░╨╗╤ï */

          pLog = new CLogFile(strLogFile);

          pLog->writeLog("=== Daemon start");

          pLog->reopen();

     

          /* ╨í╨╛╨╖╨┤╨░╨╜╨╕╨╡ ╨╜╨╛╨▓╨╛╨│╨╛ SID ╨┤╨╗╤Å ╨┤╨╛╤ç╨╡╤Ç╨╜╨╡╨│╨╛ ╨┐╤Ç╨╛╤å╨╡╤ü╤ü╨░ */

          sid = setsid();

          if (sid < 0) {

            /* ╨û╤â╤Ç╨╜╨░╨╗╨╕╤Ç╤â╨╡╨╝ ╨╗╤Ä╨▒╨╛╨╣ ╤ü╨▒╨╛╨╣ */

            exit(EXIT_FAILURE);

          }

     

          /* ╨ÿ╨╖╨╝╨╡╨╜╤Å╨╡╨╝ ╤é╨╡╨║╤â╤ë╨╕╨╣ ╤Ç╨░╨▒╨╛╤ç╨╕╨╣ ╨║╨░╤é╨░╨╗╨╛╨│ */

          if ((chdir("/")) < 0) {

            /* ╨û╤â╤Ç╨╜╨░╨╗╨╕╤Ç╤â╨╡╨╝ ╨╗╤Ä╨▒╨╛╨╣ ╤ü╨▒╨╛╨╣ */

            exit(EXIT_FAILURE);

          }

     

          /* ╨ù╨░╨║╤Ç╤ï╨▓╨░╨╡╨╝ ╤ü╤é╨░╨╜╨┤╨░╤Ç╤é╨╜╤ï╨╡ ╤ä╨░╨╣╨╗╨╛╨▓╤ï╨╡ ╨┤╨╡╤ü╨║╤Ç╨╕╨┐╤é╨╛╤Ç╤ï */

          close(STDIN_FILENO);

          close(STDOUT_FILENO);

          close(STDERR_FILENO);

    #else

        pLog = new CLogFile(strLogFile);

    #endif

     

     

    Aliens have taken over your network.

  • 11. Re: Linux daemon connect to oracle.
    rukbat Guru Moderator
    Currently Being Moderated

    Moderator Comment:

     

    User f5af4ed6-d9eb-4a60-ab07-b8728143a148


    Stop clicking on the "Report Abuse" icon.

    If you need additional responses from someone that has responded to your post then reply to that response.

     

    The "Abuse" icon is for reporting spam or cursing or immoral posts of some sort.

    When you click it as you just did, then YOU are posting inappropriate content.

  • 12. Re: Linux daemon connect to oracle.
    f5af4ed6-d9eb-4a60-ab07-b8728143a148 Newbie
    Currently Being Moderated

    more details please. What is the "aliens"?

  • 13. Re: Linux daemon connect to oracle.
    EdStevens Guru
    Currently Being Moderated

    f5af4ed6-d9eb-4a60-ab07-b8728143a148 wrote:

     

    more details please. What is the "aliens"?

     

    He's pointing out that what you posted in an English language forum is rendered as mostly unprintable characters.

  • 14. Re: Linux daemon connect to oracle.
    davidp 2 Pro
    Currently Being Moderated

    It sounds like your Daemon is connecting as the current authenticated user, when you run it after authenticating. To run it without authenticating you will have to give it an Oracle username and password in the configuration file. A null username or "/" is taken to mean "use the currently authenticated user".

1 2 3 Previous Next

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points