String fileLocation = BASE_DIR + domain + SUB_DIR_CAKE + fileName; File newFile = new File(fileLocation); System.out.println("Permission file location: " + fileLocation); if(newFile.exists()) { String command; String[] commandArray; command = "/root/new_scripts/setpermission.sh"; File commandFile = new File(command); if(commandFile.exists()) { System.out.println("\n\n\n\n\nFILE EXISTS"); } else { System.out.println("\n\n\n\n\nFILE NOT EXISTS"); } commandArray = new String[]{"/bin/sh", command, fileLocation}; try { Process p = Runtime.getRuntime().exec(commandArray); return "HERE OK"; } catch (Exception e) { e.printStackTrace(); return e.getMessage(); } // try { // String command2 = "/bin/sh /root/new_scripts/setpermission.sh " + fileLocation; // Runtime.getRuntime().exec(command2); // return "OK"; // } catch (Exception ex) { // return "execution error"; // } } else { return "file not exists"; }