I think the attached code I edited fixes this problem.
Ron
---
Ronald Cohen
Geophysical Laboratory
Carnegie Institution
5251 Broad Branch Rd., N.W.
Washington, D.C. 20015
[email protected]
office: 202-478-8937
skype: ronaldcohen
https://twitter.com/recohen3
https://www.linkedin.com/profile/view?id=163327727
On Fri, Aug 21, 2015 at 12:08 PM, Cohen, Ronald
<[email protected]> wrote:
> Unfortunately the CLI is not correct! I get:
>
> Warning: "Optimizer::Update: Error loading structure at
> /home/ucfbcoh/XTALOPT/C12H12/200GPa//00003x00051/"
>
> and when I look at that directory I find on the client:
>
> ls /home/ucfbcoh/XTALOPT/C12H12/200GPa//00003x00051/
> 00003x00051 job.sh structure.state xtal.in
> ucfbcoh@tomcat:~/src/xtalopt2/build$ ls
> /home/ucfbcoh/XTALOPT/C12H12/200GPa//00003x00051/00003x00051/
> job.sh pwscf.save xtal.in xtal.out
>
> I had fixed this also long ago, but it is back again. It is storing
> one directory down.
>
> Ron
>
> ---
> Ronald Cohen
> Geophysical Laboratory
> Carnegie Institution
> 5251 Broad Branch Rd., N.W.
> Washington, D.C. 20015
> [email protected]
> office: 202-478-8937
> skype: ronaldcohen
> https://twitter.com/recohen3
> https://www.linkedin.com/profile/view?id=163327727
>
>
> On Fri, Aug 21, 2015 at 1:48 AM, Ronald Cohen
> <[email protected]> wrote:
>> I switched to the CLI ssh and so far no problems! I guess it is a problem
>> with sshlib.
>> Ron
>> Sent from my iPad
>>
>> On Aug 17, 2015, at 9:41 AM, David Lonie <[email protected]> wrote:
>>
>> On Fri, Aug 14, 2015 at 4:35 PM, Cohen, Ronald <[email protected]>
>> wrote:
>>>
>>> I had fixed this in an earlier version but don't remember how.
>>> Sometimes the connection to the server or nameserver goes down (about
>>> once a day) and I see an error like:
>>>
>>> SSHConnectionLibSSH::isConnected(): server timeout.
>>> SSH error: Failed to resolve hostname legion.rc.ucl.ac.uk (Name or
>>> service not known)
>>> "Cannot connect to ssh server [email protected]:22"
>>> Warning: "Cannot connect to ssh server"
>>
>>
>> If you're having issues resolving hosts, there's not much that can be done
>> about that from the XtalOpt side of things. Might be VPN related?
>>
>> Dave
>>
>> ------------------------------------------------------------------------------
>>
>> _______________________________________________
>> Avogadro-Discuss mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/avogadro-discuss
/**********************************************************************
SSHConnection - Connection to an ssh server for execution, sftp, etc.
Copyright (C) 2010-2012 by David C. Lonie
This source code is released under the New BSD License, (the "License").
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
***********************************************************************/
#ifdef ENABLE_SSH
#include <globalsearch/sshconnection_cli.h>
#include <globalsearch/sshmanager_cli.h>
#include <QtCore/QDebug>
#include <QtCore/QProcess>
namespace GlobalSearch {
SSHConnectionCLI::SSHConnectionCLI(SSHManagerCLI *parent)
: SSHConnection(parent)
{
}
SSHConnectionCLI::~SSHConnectionCLI()
{
}
bool SSHConnectionCLI::execute(const QString &command,
QString &stdout_str,
QString &stderr_str,
int &exitcode)
{
return this->executeSSH(command, QStringList(),
&stdout_str, &stderr_str, &exitcode);
}
bool SSHConnectionCLI::copyFileToServer(const QString &localpath,
const QString &remotepath)
{
return this->executeSCPTo(localpath, remotepath);
}
bool SSHConnectionCLI::copyFileFromServer(const QString &remotepath,
const QString &localpath)
{
return this->executeSCPFrom(remotepath, localpath);
}
bool SSHConnectionCLI::readRemoteFile(const QString &filename,
QString &contents)
{
return this->executeSSH("cat", QStringList(filename), &contents);
}
bool SSHConnectionCLI::removeRemoteFile(const QString &filename)
{
return this->executeSSH("rm", QStringList(filename));
}
bool SSHConnectionCLI::copyDirectoryToServer(const QString &localpath,
const QString &remotepath)
{
QStringList args ("-p ");
args << remotepath;
this->executeSSH("mkdir", args);
QString arg1;
arg1 = remotepath + "/.." ;
return this->executeSCPTo(localpath, arg1, QStringList("-r"));
}
bool SSHConnectionCLI::copyDirectoryFromServer(const QString &remotepath,
const QString &localpath)
{
QStringList args ("-p ");
args << localpath;
this->executeSSH("mkdir", args);
QString arg1;
arg1 = localpath + "/.." ;
return this->executeSCPFrom(remotepath, arg1, QStringList("-r"));
}
bool SSHConnectionCLI::readRemoteDirectoryContents(const QString &remotepath,
QStringList &contents)
{
QString contents_str;
// This is to produce an output similar to the libssh implementation.
QStringList args;
args << remotepath + "/*" << "|" << "xargs" << "ls" << "-Fd";
if (!this->executeSSH("find", args, &contents_str)) {
return false;
}
contents = contents_str.split("\n", QString::SkipEmptyParts);
return true;
}
bool SSHConnectionCLI::removeRemoteDirectory(const QString &remotepath,
bool onlyDeleteContents)
{
if (remotepath.isEmpty() || remotepath == "/") {
qWarning() << QString("Refusing to remove directory \"%1\".")
.arg(remotepath);
return false;
}
QStringList args ("-rf");
if (onlyDeleteContents)
args << remotepath + "/*";
else
args << remotepath;
return this->executeSSH("rm", args);
}
bool SSHConnectionCLI::executeSSH(const QString &command,
const QStringList &args,
QString *stdout_str,
QString *stderr_str, int *ec)
{
QProcess proc;
QStringList fullArgs;
// Add username
if (!m_user.isEmpty())
fullArgs << "-l" << m_user;
// Add port number
fullArgs << "-p" << QString::number(m_port);
// Add hostname
fullArgs << m_host;
// Add command and original arguments
fullArgs << command;
fullArgs << args;
proc.start("ssh", fullArgs);
int timeout_ms = 60000; // one minute
if (!proc.waitForStarted(timeout_ms)) {
qWarning() << QString("Failed to start ssh command with args \"%1\" "
"after %2 seconds.")
.arg(fullArgs.join(","))
.arg(timeout_ms / 1000);
return false;
}
proc.closeWriteChannel();
if (!proc.waitForFinished(timeout_ms)) {
qWarning() << QString("ssh command with args \"%1\" failed to finish "
"within %2 seconds.")
.arg(fullArgs.join(","))
.arg(timeout_ms / 1000);
return false;
}
if (proc.exitCode() == 255) {
qWarning() << QString("ssh command with args \"%1\" returned an exit "
"code of 255. This usually means that ssh failed "
"to connect, but it may also be a valid exit code"
" for the command which was run. Assuming that "
"ssh has errored. Contact the development team "
"if you believe this is an error.")
.arg(fullArgs.join(","))
<< "\nstdout:\n" << QString(proc.readAllStandardOutput())
<< "\nstderr:\n" << QString(proc.readAllStandardError());
return false;
}
if (stdout_str != NULL)
*stdout_str = QString(proc.readAllStandardOutput());
if (stderr_str != NULL)
*stderr_str = QString(proc.readAllStandardError());
if (ec != NULL)
*ec = proc.exitCode();
proc.close();
return true;
}
bool SSHConnectionCLI::executeSCPTo(const QString &source,
const QString &dest,
const QStringList &args,
QString *stdout_str,
QString *stderr_str, int *ec)
{
QProcess proc;
// Start with input args
QStringList fullArgs (args);
// Add port number
fullArgs << "-P" << QString::number(m_port);
// Add source
fullArgs << source;
// Add destination
fullArgs << QString("%1%2%3:%4")
.arg(m_user)
.arg(m_user.isEmpty() ? "" : "@")
.arg(m_host)
.arg(dest);
proc.start("scp", fullArgs);
int timeout_ms = 60000; // one minute
if (!proc.waitForStarted(timeout_ms)) {
qWarning() << QString("Failed to start scp command with args \"%1\" "
"after %2 seconds.")
.arg(fullArgs.join(","))
.arg(timeout_ms / 1000);
return false;
}
proc.closeWriteChannel();
if (!proc.waitForFinished(timeout_ms)) {
qWarning() << QString("scp command with args \"%1\" failed to finish "
"within %2 seconds.")
.arg(fullArgs.join(","))
.arg(timeout_ms / 1000);
return false;
}
if (proc.exitCode() != 0) {
qWarning() << QString("scp command with args \"%1\" failed with an exit "
"code of %2.")
.arg(fullArgs.join(","))
.arg(proc.exitCode())
<< "\nstdout:\n" << QString(proc.readAllStandardOutput())
<< "\nstderr:\n" << QString(proc.readAllStandardError());
return false;
}
if (stdout_str != NULL)
*stdout_str = QString(proc.readAllStandardOutput());
if (stderr_str != NULL)
*stderr_str = QString(proc.readAllStandardError());
if (ec != NULL)
*ec = proc.exitCode();
proc.close();
return true;
}
bool SSHConnectionCLI::executeSCPFrom(const QString &source,
const QString &dest,
const QStringList &args,
QString *stdout_str,
QString *stderr_str, int *ec)
{
QProcess proc;
// Start with input args
QStringList fullArgs (args);
// Add port number
fullArgs << "-P" << QString::number(m_port);
// Add source
fullArgs << QString("%1%2%3:%4")
.arg(m_user)
.arg(m_user.isEmpty() ? "" : "@")
.arg(m_host)
.arg(source);
// Add destination
fullArgs << dest;
proc.start("scp", fullArgs);
int timeout_ms = 60000; // one minute
if (!proc.waitForStarted(timeout_ms)) {
qWarning() << QString("Failed to start scp command with args \"%1\" "
"after %2 seconds.")
.arg(fullArgs.join(","))
.arg(timeout_ms / 1000);
return false;
}
proc.closeWriteChannel();
if (!proc.waitForFinished(timeout_ms)) {
qWarning() << QString("scp command with args \"%1\" failed to finish "
"within %2 seconds.")
.arg(fullArgs.join(","))
.arg(timeout_ms / 1000);
return false;
}
if (proc.exitCode() != 0) {
qWarning() << QString("scp command with args \"%1\" failed with an exit "
"code of %2.")
.arg(fullArgs.join(","))
.arg(proc.exitCode())
<< "\nstdout:\n" << QString(proc.readAllStandardOutput())
<< "\nstderr:\n" << QString(proc.readAllStandardError());
return false;
}
if (stdout_str != NULL)
*stdout_str = QString(proc.readAllStandardOutput());
if (stderr_str != NULL)
*stderr_str = QString(proc.readAllStandardError());
if (ec != NULL)
*ec = proc.exitCode();
proc.close();
return true;
}
} // end namespace GlobalSearch
#endif // ENABLE_SSH
------------------------------------------------------------------------------
_______________________________________________
Avogadro-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/avogadro-devel