1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 * BatchManager_Local_SSH.cxx :
25 * Auteur : Ivan DUTKA-MALEN - EDF R&D
26 * Mail : mailto:ivan.dutka-malen@der.edf.fr
27 * Date : Thu Nov 6 10:17:22 2003
33 # include <SALOMEconfig.h>
40 #include <sys/types.h>
51 #include "Batch_IOMutex.hxx"
52 #include "Batch_BatchManager_Local_SSH.hxx"
54 #include "Batch_config.h"
57 #error "RM undefined. You must set RM to a valid path to a rm-like command."
61 #error "SCP undefined. You must set SCP to a valid path to a scp-like command."
65 #error "SSH undefined. You must set SSH to a valid path to a ssh-like command."
74 BatchManager_Local_SSH::BatchManager_Local_SSH(const FactBatchManager * parent, const char * host) throw(InvalidArgumentException,ConnexionFailureException) : BatchManager_Local(parent, host)
79 BatchManager_Local_SSH::~BatchManager_Local_SSH()
84 // Methode abstraite qui renvoie la commande de copie du fichier source en destination
85 string BatchManager_Local_SSH::copy_command(const std::string & user_source,
86 const std::string & host_source,
87 const std::string & source,
88 const std::string & user_destination,
89 const std::string & host_destination,
90 const std::string & destination) const
92 ostringstream fullsource;
93 if (host_source.size() != 0) {
94 fullsource << host_source << ":";
98 ostringstream fulldestination;
99 if (host_destination.size() != 0) {
100 fulldestination << host_destination << ":";
102 fulldestination << destination;
104 ostringstream copy_cmd;
105 // Option -p is used to keep the same permissions for the destination file (particularly useful to keep scripts
106 // executable when copying them)
107 copy_cmd << SCP << " -p " << fullsource.str() << " " << fulldestination.str();
108 return copy_cmd.str();
111 // Methode abstraite qui renvoie la commande a executer
112 string BatchManager_Local_SSH::exec_command(Parametre & param) const
114 ostringstream exec_sub_cmd;
115 exec_sub_cmd << "cd " << param[WORKDIR] << ";";
116 exec_sub_cmd << param[EXECUTABLE];
118 if (param.find(ARGUMENTS) != param.end()) {
119 Versatile V = param[ARGUMENTS];
120 for(Versatile::const_iterator it=V.begin(); it!=V.end(); it++) {
121 StringType argt = * static_cast<StringType *>(*it);
123 exec_sub_cmd << " " << arg;
128 Versatile new_arguments;
129 new_arguments.setMaxSize(0);
130 new_arguments = string(param[EXECUTIONHOST]);
133 if (param.find(USER) != param.end()) {
134 new_arguments += "-l";
135 new_arguments += string(param[USER]);
138 new_arguments += exec_sub_cmd.str();
140 param[ARGUMENTS] = new_arguments;
142 // Sous Linux on est oblige de modifier ces deux parametres pour faire fonctionner la commande rsh
143 param[EXECUTABLE] = SSH;
149 // Methode qui renvoie la commande d'effacement du fichier
150 string BatchManager_Local_SSH::remove_command(const std::string & user_destination,
151 const std::string & host_destination,
152 const std::string & destination) const
154 string host = (host_destination.size()) ? host_destination : "localhost:";
156 ostringstream remove_cmd;
157 remove_cmd << SSH << " " << host << " \"" << RM << " " << destination << "\"";
158 return remove_cmd.str();