Link to home
Start Free TrialLog in
Avatar of Jay Roy
Jay RoyFlag for United States of America

asked on

FileNotFoundException:. ...(Permission denied)

hi guys

In my application i have this problem which i am struggling for past 2 days

My java process is trying to write a file to the directory in unix box using FileOutputStream
The code goes like this

public class CustomExport{
...
	public void saveReport() {
		try {
			SimpleDateFormat dateFormatter = new SimpleDateFormat("MM_dd_yyyy");
			String date = dateFormatter.format(new Date());
			FileOutputStream out = new FileOutputStream(new File("custom" + date + ".xls"));
			hSSFWorkbook.write(out);  //org.apache.poi.hssf.usermodel.HSSFWorkbook  api is used to generate excel
			out.flush();
			out.close();

		} catch (IOException e) {
			LOG.error(" Error occured  {} " + e);
			LOG.error(" Error Message  {} " + e.getMessage());
		}

	}
}

Open in new window

The above java process runs from this folder in unix box :  /custom/export/excel/custom.sh

custom.sh contains
java -Dproj.env=dev -jar $ROOT/CustomExport.jar   (this is the jar which contains the above java code)

Open in new window


so when i run custom.sh it inovkes the saveReport() and it goes to the catch block and prints the following errors

12337 [main] ERROR com.crisp.excel.CustomExport  -  Error occured  {} java.io.FileNotFoundException: custom_03_26_2013.xls (Permission denied)

 1va.io.FileNotFoundException: custom_03_26_2013.xls (Permission denied)
2337 [main] ERROR com.crisp.excel.CustomExport  -  Error Message  {} custom_03_26_2013.xls (Permission denied)


I understand i am missing permissions but where am i missing the permissions ?
Is this write permission of the file custom_03_26_2013.xls  which is generated on the fly  or the permission of /custom/export/excel folder where it is supposed to write?

Any help would be greatly apprecaited
thanks.
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

The above java process runs from this folder in unix box :  /custom/export/excel/custom.sh
That's not a folder - it's a path to a script. Start by finding your current directory

Then you need to examine whether that file exists there and has suitable permissions

File f = new File("custom" + date + ".xls");
System.out.println(f.exists());
System.out.println(f.canRead());
System.out.println(f.canWrite());

Open in new window

Avatar of Jay Roy

ASKER

/custom/export/excel is the current directory
The file which is generated is supposed to be written in that directory
(/custom/export/excel).
When its trying to write it it throws permission denied error
I agree with CEHJ.

From which directory are you executing a command. You will need to give a write permission to that directory.

Give the write permission to a directory from where you execute the command (/custom/export/excel/custom.sh).

One more question, are you changing directory in custom.sh ?
Avatar of Jay Roy

ASKER

>>From which directory are you executing a command
/custom/export/excel

The job is running through Autosys tool, we dont manually invoke it.


>One more question, are you changing directory in custom.sh ?
no.
SOLUTION
Avatar of Am P
Am P
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
/custom/export/excel is the current directory

That's an odd root directory on a Unix-based system. Please post output of following command:

ls -ld /custom/export/excel

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jay Roy

ASKER

sharonseth,

the job works fine if i run it from command line (No PERMISSION DENIED issue)but fails when i run it through Autosys job

$ls -ld  /custom/export/excel


drwxrwxrwx+ 15 excel grapbpm 2048 Mar 26 18:18 /custom/export/excel
So , the problem is with scheduing the job thru autosys . Probably you need to give autosys proper permissions.

As I said , can you pull up the job definition and paste the contents here pls
BTW , is autosys configured to start the job with the same user that runs it from the command line?
Avatar of Jay Roy

ASKER

>> is autosys configured to start the job with the same user that runs it from the command line?

i belive so
this is what we did
$id
uid=14564545(grapbpm ) gid=34489(grapbpm ) groups=34489(texgmpb)

In Autosys we have a 'Owner' field which we specifid as grapbpm
insert_job: 455_Report_Job    job_type: cmd
description: Generate email with excel attachment
machine: texmex01.mau.rsroot.net
owner: grapbpm 
max_run_alarm: 15
alarm_if_fail: y
date_conditions: y
days_of_week: we
start_times: "17:25"
profile: /custom/export/AutosysProfile.sh
std_out_file: /custom/export/excel_report.log
std_err_file: /custom/export/excel_report.log
command: $EXCELDIR/Report.sh

Open in new window


thanks!
Please insert the following into your code and then post the output

System.out.println(System.getProperty("user.dir"));
File f = new File("custom" + date + ".xls");
System.out.println(f.exists());
System.out.println(f.canRead());
System.out.println(f.canWrite());

Open in new window

Avatar of Jay Roy

ASKER

here it is:

1. when i run the job using Autosys

12666 [main] INFO  com.crisp.excel.CustomExport  - user.dir = /opt/CA/WorkloadAutomationAE/SystemAgent/WA1_AGENT
 12666 [main] INFO  com.crisp.excel.CustomExportImpl-  file exists false
 12666 [main] INFO  com.crisp.excel.CustomExportImpl-  file can read false
 12666 [main] INFO  com.crisp.excel.CustomExportImpl-  file can wirte false

12337 [main] ERROR com.crisp.excel.CustomExport  -  Error occured  {} java.io.FileNotFoundException: custom_03_26_2013.xls (Permission denied)

 1va.io.FileNotFoundException: custom_03_26_2013.xls (Permission denied)
2337 [main] ERROR com.crisp.excel.CustomExport  -  Error Message  {} custom_03_26_2013.xls (Permission denied)

------------------

2. when ran manually from command prompt

 11621 [main] INFO  com.crisp.excel.CustomExportImpl- user.dir = /custom/export/excel
 11621 [main] INFO  com.crisp.excel.CustomExportImpl-  file exists false
 11621 [main] INFO  com.crisp.excel.CustomExportImpl-  file can read false
 11621 [main] INFO  com.crisp.excel.CustomExportImpl-  file can wirte false
...
No permission denied error and job ran sucessfully..


thanks
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial