繁体   English   中英

使用部署在oracle weblogic服务器上的Java代码,数据泵目录中的chmod命令第二次不起作用

[英]chmod command in data pump directory not working second time using Java code deployed on oracle weblogic server

我正在尝试使用expdp cmd创建表A_LOCKER的dmp文件,然后将其通过ftp发送回部署了Java代码的本地计算机。该服务器是oracle weblogic服务器。 该代码第一次可以正常工作,但是从第二次开始它给出错误为:权限被拒绝

dmp文件是在我创建的数据泵目录Extract中创建的。

现在,我尝试对dmp文件进行sftp传输,为此,我需要为该文件提供sudo权限,因此我在Java代码中尝试了以下操作:1)创建会话:

    StringBuffer cmd = new StringBuffer();        

    FileOutputStream fileOutputStream = null;

    SshClient ssh = new SshClient();
    SessionChannelClient session = null;
    SftpClient sftp = null;


    HostKeyVerification host = new IgnoreHostKeyVerification();

    // Try to connect to the machine that includes the shared folder
    // Throw an exception when a connection is failed.
    try {
        ssh.connect(machine, host);
    } catch (IOException e) {


        logger.error("Cannot connect to dbserver in machine "
                        + machine,e);
        throw new EPCShareFileException(
                "Cannot connect to dbserver location in machine "
                        + machine, e);
    }


    PasswordAuthenticationClient auth = new PasswordAuthenticationClient();
    auth.setUsername(user);
    auth.setPassword(password);
    // Authenticate user name and password for connection
    // Throw an exception if authentication is failed

    try {
        ssh.authenticate(auth);
    } catch (IOException e) {
        logger.error("Cannot authenticate user "
                + user + " " + " password " + password);
        ssh.disconnect();

        throw new EPCShareFileException("Cannot authenticate user "
                + user + " " + " password " + password, e);
    }

2)使用伪权限执行chmod命令

                  cmd.append("/usr/local/bin/sudo /bin/chmod -R 777 ")
                     .append(location+dbDumpFileName);
                   try{
        session = ssh.openSessionChannel();
        session.executeCommand(cmd.toString());

    } catch (IOException e){
        logger.error("Cannot execute chmod cmd");
    } 
    finally{
        try {
            session.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            logger.info("Cannot close the session:"+e.getMessage());
        }

    }

3)然后我正在尝试将dmp文件sftp到本地服务器

                   try {
        sftp = ssh.openSftpClient();
        } catch (IOException e) {
        logger.error("Cannot open connection to database server");
        ssh.disconnect();
        throw new EPCShareFileException(
                "Cannot open connection to database server");

    }

    try{
        fileOutputStream = new FileOutputStream(dbDumpFileName);

        sftp.get(location+dbDumpFileName, fileOutputStream);
    }catch (IOException e) {
        **throw new EPCShareFileException("Cannot retrive file "
                +"Error:"+e.getMessage());**
    }finally{
        try {
            fileOutputStream.close();
            sftp.quit();
            fileOutputStream = null;
            sftp = null;

        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        ssh.disconnect();
        ssh = null;
    }

第一次,当我将代码作为耳文件部署到oracle weblogic服务器上时,它是工作文件,并且创建了dmp文件并将sftpd到所需位置,但是从第二次开始,我收到错误消息: 错误:权限被拒绝

请帮忙..

首先,永远不要使用chmod -R 777就像将数据发布给有权访问该计算机的任何人一样,没有任何问题。 如果您使用它来调试问题,那么可以,但是不要忘了将其改回(或者摆脱它;您根本不需要它)。

要调试“权限被拒绝”错误,您需要有权访问计算机。 在计算机上,您需要以遇到错误的用户身份登录(不要以root用户或其他用户身份尝试)。

以该用户身份,尝试访问您无法访问的路径中的每个文件夹。 因此,如果/srv/www/foo/bar/x/y/z/file.txt失败,则需要

ls /srv
ls /srv/www/
ls /srv/www/foo/
ls /srv/www/foo/bar/
ls /srv/www/foo/bar/x/
ls /srv/www/foo/bar/x/y/
ls /srv/www/foo/bar/x/y/z/
ls /srv/www/foo/bar/x/y/z/file.txt

按此顺序执行。 查找第一个失败的命令,然后检查为什么该用户没有问题文件夹的权限。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM