简体   繁体   中英

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. 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.

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:

    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

                  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

                   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

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. 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).

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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