problem with permissions(i think?)..
prt
shaharsa at pelephone.co.il
Sun Jul 8 08:12:53 UTC 2007
Hi to all,
I have aproblem to run Mplayer from java process.
At first i have Apache Tomcat(run as root) that runs process every minute,
That process
convert video file to images by "calling" Mplayer,
The java process create shell file and than execute it,
This the code that create the .sh file..
###############################
private void createShFile(String sMid, String sFile, String sSuffix){
//sMid = the video file ID(number)
//sFile = the video file full path (/data/video/345/safew4543rfd.avi)
//sSuffix = the video file suffix (avi,wmv,...)
FileOutputStream out;
PrintStream p;
String[] sArr = sFile.split("." + sSuffix);
try {
//Create .sh file (for example proc68.sh)
out = new FileOutputStream("/data/mplayerproc/proc" + sMid + ".sh");
p = new PrintStream(out);
p.println("#!/bin/sh");
p.println("cd /data/mplayerproc/");
//Make directory fot the mplayer put all the images in
p.println("mkdir tmp" + sMid);
//Run the mplayer to convert video to images, create first 20 images
p.println("mplayer -osdlevel 0 -nosound -frames 20 -vo
jpeg:quality=50:outdir=tmp" + sMid + " \"" + sFile + "\"");
//Move the last image to other folder
p.println("mv -f tmp" + sMid + "/00000019.jpg \"" + sArr[0] +
"p.jpg\"");
//Remove the tmp directory
p.println("rm -f -r tmp" + sMid);
//Remove the .sh file
p.println("rm -f proc" + sMid + ".sh");
p.close();
}
catch (Exception e){System.out.println("Err in createShFile: " +
e);}
sArr = null;
p = null;
out = null;
}
###############################
Next step after the .sh file is created by the java process, the java
process run it, the code is..
###############################
private void runMPlayerProcess(String sMid, String sFile, String sSuffix){
//sMid = the video file ID(number)
//sFile = the video file full path (/data/video/345/safew4543rfd.avi)
//sSuffix = the video file suffix (avi,wmv,...)
String s = null;
Process p;
String sLine;
BufferedReader input;
try {
//The function that create the .sh file
createShFile(sMid,sFile,sSuffix);
//Runtime.getRuntime().exec() this is for to run system commands..
//Change the .sh file mod to be executable
p = Runtime.getRuntime().exec("chmod 755
/data/mplayerproc/proc" + sMid + ".sh");
input = new BufferedReader(new
InputStreamReader(p.getInputStream()));
while ((sLine = input.readLine()) != null) {log(sLine);}
input.close();
//The most important part, at list run the .sh file
p = Runtime.getRuntime().exec("/data/mplayerproc/./proc" +
sMid + ".sh");
input = new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((sLine = input.readLine()) != null) {log(sLine);}
input.close();
}
catch (Exception e) {System.out.println("Err in runMPlayerProcess: "
+ e);}
p = null;
s = null;
sLine = null;
input = null;
}
###############################
So, the .sh file is create and run by the java process called by the tomcat
and its works just perfect. The images are created by the mplayer and it
work!!!
But now, i want to run the java process from the crontab and not from the
tomcat.
So i canceled the process from the tomcat and add line in crontab to run the
process every 5 minute.
The crontab run the process as root.
The process is same process, everything work, the .sh fiel is created, all
the command in the .sh file are
executed except the command that call the mplayer, this command is not
executed.
I try to run the process as other user and still the same problem.
I try to get any error message by change part of the code to this..
#########################
p = Runtime.getRuntime().exec("/data/mplayerproc/proc" + sMid + ".sh >
/data/log 2>&1");
#########################
Still the same problem, and no log file was created in /data/.
I try to run the .sh that the process create by my self,
So i canceled the this part in the java process so i can run the .sh file by
my self..
#########################
//p = Runtime.getRuntime().exec("/data/mplayerproc/proc" + sMid + ".sh >
/data/log 2>&1");
#########################
And when i run the .sh file as root everything wark, and the mplayer command
is executed.
I dont know what the problem, I run the java process as root, even the .sh
file that the java
create have root owner.
I try to run the mplayer command directly and not by .sh filthis is the
part..
#########################
p = Runtime.getRuntime().exec("mplayer -osdlevel 0 -nosound -frames 20 -vo
jpeg:quality=50:outdir=tmp" + sMid + " \"" + sFile + "\"");
#########################
Still not work but at least i catch a JavaException "mplayer command not
found.."
This the message that java get from the system..
I dont know what to do..
With the tomcat is work good, when i run the process as root from crontab
the mplayer command
is not executed..
I think that the problem is in user permissions, but way the java run as
root, even the .sh file is created
as root owner..
Any body can give me any advice ???
Thanks to all for reading the message and sorry about my english.
--
View this message in context: http://www.nabble.com/problem-with-permissions%28i-think-%29..-tf4043831.html#a11486819
Sent from the ubuntu-users mailing list archive at Nabble.com.
More information about the ubuntu-users
mailing list