Avatar of royjayd
royjayd
 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.
Java

Avatar of undefined
Last Comment
CEHJ

8/22/2022 - Mon
CEHJ

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

royjayd

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
Am P

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 ?
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
royjayd

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
Am P

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
CEHJ

/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
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
royjayd

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
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Sharon Seth

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
Sharon Seth

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

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!
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
CEHJ

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

royjayd

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
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.