简体   繁体   English

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

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

I am trying to create dmp file of a table A_LOCKER using expdp cmd and then sftp it back to local machine on which my java code is deployed.The server is an oracle weblogic server. 我正在尝试使用expdp cmd创建表A_LOCKER的dmp文件,然后将其通过ftp发送回部署了Java代码的本地计算机。该服务器是oracle weblogic服务器。 The code is working fine for first time but from second time it is giving error as:Permission denied 该代码第一次可以正常工作,但是从第二次开始它给出错误为:权限被拒绝

The dmp file is created in a data pump directory Extract which is create by me. dmp文件是在我创建的数据泵目录Extract中创建的。

Now i try to sftp the dmp file and for that i need to provide sudo permission for the file so i tried following in my java code: 1)To create session: 现在,我尝试对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)Execute chmod command using pseudo permission 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)Then i am trying to sftp the dmp file to local server 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;
    }

For first time when i am deploying my code as ear file on oracle weblogic server it is working file and dmp file is created and sftped to desired location as well But from second time i am getting error: Error:Permission denied 第一次,当我将代码作为耳文件部署到oracle weblogic服务器上时,它是工作文件,并且创建了dmp文件并将sftpd到所需位置,但是从第二次开始,我收到错误消息: 错误:权限被拒绝

Please Help.. 请帮忙..

First of all, don't ever use chmod -R 777 - that's like publishing your data for anyone with access to the machine, no questions asked. 首先,永远不要使用chmod -R 777就像将数据发布给有权访问该计算机的任何人一样,没有任何问题。 If you used this to debug the issue, then okay, but don't forget to change it back (or get rid of it; you shouldn't need it at all). 如果您使用它来调试问题,那么可以,但是不要忘了将其改回(或者摆脱它;您根本不需要它)。

To debug "Permission denied" errors, you need to have access to the machine. 要调试“权限被拒绝”错误,您需要有权访问计算机。 On the machine, you need to login as the user that got the error (don't try as root or another user). 在计算机上,您需要以遇到错误的用户身份登录(不要以root用户或其他用户身份尝试)。

As this user, try to access every folder in the path that you couldn't access. 以该用户身份,尝试访问您无法访问的路径中的每个文件夹。 So if it failed for /srv/www/foo/bar/x/y/z/file.txt , then you need to 因此,如果/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

Do it in this order. 按此顺序执行。 Find the first command that failed and then check why this user doesn't have permissions for the folder in question. 查找第一个失败的命令,然后检查为什么该用户没有问题文件夹的权限。

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

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