Beispiel #1
0
int main( int argc, char *argv[] )
{
    int res=0;
    if (argc < 3)
    {
        printf
            ("frunssh <nodelistfile> \"command\" [options] \n"
            "    options: -i:<identity-file> \n"
            "             -u:<user> \n"
            "             -n:<number_of_threads>\n"
            "             -t:<connect-timeout-secs>\n"
            "             -a:<connect-attempts>\n"
            "             -d:<working_directory>\n"
            "             -s                -- strict, must match known_hosts\n"
            "             -b                -- background\n"
            "             -pw:<password>    -- INSECURE: requires pssh (NB identity file preferred)\n"
            "             -pe:<password>    -- INSECURE: as -pw except encrypted password\n"
            "             -pl               -- use plink (on windows)\n"
            "             -v                -- verbose, lists commands run\n"
            "             -d                -- dry run (for testing, enables verbose)\n"
            );
        return 255;
    }


    InitModuleObjects();

#ifndef __64BIT__
    // Restrict stack sizes on 32-bit systems
    Thread::setDefaultStackSize(0x10000);   // NB under windows requires linker setting (/stack:)
#endif

    try  {
        StringBuffer logname;
        splitFilename(argv[0], NULL, NULL, &logname, NULL);

        Owned<IComponentLogFileCreator> lf = createComponentLogFileCreator("frunssh");
        lf->setCreateAliasFile(false);
        lf->setMsgFields(MSGFIELD_prefix);
        lf->beginLogging();

        Owned<IFRunSSH> runssh = createFRunSSH();
        runssh->init(argc,argv);
        runssh->exec();
    }
    catch(IException *e)
    {
        EXCLOG(e,"frunssh");
        e->Release();
        res=255;
    }
    releaseAtoms();
    return res;
}
Beispiel #2
0
int main( int argc, char *argv[] )
{
    int res=0;
    if (argc < 3)
    {
        printf
            ("frunssh <nodelistfile> \"command\" [options] \n"
            "    options: -i:<identity-file> \n"
            "             -u:<user> \n"
            "             -n:<number_of_threads>\n"
            "             -t:<connect-timeout-secs>\n"
            "             -a:<connect-attempts>\n"
            "             -d:<working_directory>\n"
            "             -s                -- strict, must match known_hosts\n"
            "             -b                -- background\n"
            "             -pw:<password>    -- INSECURE: requires pssh (NB identity file preferred)\n"
            "             -pe:<password>    -- INSECURE: as -pw except encrypted password\n"
            "             -pl               -- use plink (on windows)\n"
            "             -v                -- verbose, lists commands run\n"
            "             -d                -- dry run (for testing, enables verbose)\n"
            );
        return 255;
    }


    InitModuleObjects();
    try  {
        StringBuffer logname;
        splitFilename(argv[0], NULL, NULL, &logname, NULL);
        StringBuffer logdir;
        if (getConfigurationDirectory(NULL,"log","frunssh",logname.str(),logdir)) {
            recursiveCreateDirectory(logdir.str());
            StringBuffer tmp(logname);
            addPathSepChar(logname.clear().append(logdir)).append(tmp);
        }
        addFileTimestamp(logname, true);
        logname.append(".log");
        appendLogFile(logname.str(),0,false);
        queryStderrLogMsgHandler()->setMessageFields(MSGFIELD_prefix);

        Owned<IFRunSSH> runssh = createFRunSSH();
        runssh->init(argc,argv);
        runssh->exec();
    }
    catch(IException *e)
    {
        EXCLOG(e,"frunssh");
        e->Release();
        res=255;
    }
    releaseAtoms();
    return res;
}
    virtual void doWork()
    {
        try
        {
            StringBuffer userId;
            StringBuffer password;
            bool bLinux;

            if (m_sConfigAddress.length() < 1)
            {
                m_pService->getAccountAndPlatformInfo(m_sAddress.str(), userId, password, bLinux);
            }
            else
            {
                m_pService->getAccountAndPlatformInfo(m_sConfigAddress.str(), userId, password, bLinux);
            }

            if (!m_userId.length() || !m_password.length())
            {
                //BUG: 9825 - remote execution on linux needs to use individual accounts
                //use userid/password in ESP context for remote execution...
                if (bLinux)
                {
                    userId.clear();
                    password.clear();
                    m_context.getUserID(userId);
                    m_context.getPassword(password);
                }
            }
            else
            {
                userId.clear().append(m_userId);
                password.clear().append(m_password);
            }

            if (!m_sCommand.length())
                setResultCode(-1);
            else
            {
                IFRunSSH * connection = createFRunSSH();
                connection->init(m_sCommand.str(),NULL,NULL,NULL,5,0);
                connection->exec(m_sAddress.str(),NULL,true);
            }
        }
        // CFRunSSH uses a MakeStringExceptionDirect throw to pass code and result string to caller
        catch(IException* e)
        {
            // errorCode == -1 on successful CFRunSSH execution
            if(e->errorCode() == -1)
                setResultCode(0);
            else
                setResultCode(e->errorCode());
            StringBuffer buf;
            e->errorMessage(buf);
            if (buf.length() && buf.charAt(buf.length() - 1) == '\n') // strip newline
                buf.setLength(buf.length() - 1);
            // set regardless of return
            setResponse(buf.str());
            e->Release();
        }
#ifndef NO_CATCHALL
        catch(...)
        {
            setResponse("An unknown exception occurred!");
            setResultCode(-1);
        }
#endif
    }//doWork()