exp ly_cloud_xtglly$_cloud_xtgl192168352031521orcl file=tmpbackup1691633904031dmp log=tmpbackup1691633904031log statistics=none这个oracle exp备份导出命令密码存在$特殊符号怎么使用java JSch #!binbash 执行
您可以使用Java的JSch库来执行该命令。下面是一个示例代码:
import com.jcraft.jsch.*;
public class SSHCommandExecutor {
public static void main(String[] args) {
String username = "your-username";
String password = "your-password";
String command = "exp ly_cloud_xtgl/ly\\$_cloud_xtgl@192.168.35.203:1521/orcl file=/tmp/backup/1691633904031.dmp log=/tmp/backup/1691633904031.log statistics=none";
try {
JSch jsch = new JSch();
Session session = jsch.getSession(username, "your-server-ip", 22);
session.setPassword(password);
session.setConfig("StrictHostKeyChecking", "no");
session.connect();
Channel channel = session.openChannel("exec");
((ChannelExec) channel).setCommand(command);
channel.setInputStream(null);
((ChannelExec) channel).setErrStream(System.err);
InputStream in = channel.getInputStream();
channel.connect();
byte[] tmp = new byte[1024];
while (true) {
while (in.available() > 0) {
int i = in.read(tmp, 0, 1024);
if (i < 0) break;
System.out.print(new String(tmp, 0, i));
}
if (channel.isClosed()) {
if (in.available() > 0) continue;
System.out.println("exit-status: " + channel.getExitStatus());
break;
}
try {
Thread.sleep(1000);
} catch (Exception ee) {
}
}
channel.disconnect();
session.disconnect();
} catch (JSchException | IOException e) {
e.printStackTrace();
}
}
}
在上述代码中,您需要将"your-username"和"your-password"替换为您的SSH登录凭据,将"your-server-ip"替换为您的服务器IP地址。然后,您可以直接运行此Java程序来执行该命令
原文地址: https://www.cveoy.top/t/topic/izpf 著作权归作者所有。请勿转载和采集!