Want to shutdown solaris 10 using java application

Greetings all!
I have been unsuccessful at creating my application to shut down a Solaris 10 server with a java application. I am hoping someone might be able to point me in a good direction here.
I want to log on as a regular user and run a java application that monitors remote information (UPS battery voltage) and will gracefully shutdown the server if there is a problem. If I run my application as root all is well, except that I am running as root :)
I can write code to access the shell:
Process proc = Runtime.getRuntime().exec("ls");
BufferedReader Input = new BufferedReader(new InputStreamReader(proc.getInputStream()));
while ((s = Input.readLine()) != null) {out.println(s);}
But I can't do a "su"?
I've tried multiple examples out there of code that allows shell communication, and good examples of using Runtime.getRuntime()
I think the conclusion is that you can't issue a su command via java application.
I've also tried to telnet from a console to localhost and log in as root - no joy there either.
Would someone have information that might point me in the right direction to solve this problem? Even better, if there is a sample snippet to go along with any help.
Thank You very much!
Ray

Wow,
Thank you for the very detailed response! I read the referenced web page last night, I'll read it again today too. RBAC sounds like a pretty complicated administrative tool. Coming from the Win32 domain, most of this security stuff is sadly uncharted territory for me (except for my mac).
Let me see if I understand your method:
Create a role, javarole, this role needs Primary Administrator priviliges (in order to invoke "shutdown -y -i5 -g0") only available to root
Create a powerdown profile, essentially a script:
this line creates the file:
# echo "powerdown:::profile to powerdown server:help=powerdown.html" >> /etc/security/prof_attr
I think this is the actual added script: (instead of the shutdown command just use init 5)
# chmod 755 /usr/sbin/powerdown
# cat > /usr/sbin/powerdown <<EOF
#!/bin/sh
/usr/sbin/init 5
EOF
This line is a bit confusing to me, is it also part of the script?
# echo "powerdown:suser:cmd:::/usr/sbin/powerdown:uid=0" >> /etc/security/exec_attr
I see the uid=0 (root)
It seems obvious to me that I log in a root to create this script, which is the reason it has permission to shutdown...right?
Also, I tried the su command using runTime.exec("su poweroff"); // a user I created to try poweroff scripts
It seems that su is generally not available, I will create the role and try to telnet to it.
What about creating a generic user script that includes the javarole name and password, and then run the script "/usr/sbin/powerdown"
Yes, it leaves a role password exposed, however it is a very limited role, that is not accessible by a user login, but the turn off script is available to every user?
Regards,
Ray

Similar Messages

  • How to send attachments using java application and outlook

    Hi ,
    I created an application in java which is as
    on the Conference Tab i can schedule a conference and with the send command on page it map all the scheduled data to outlook(with all conference details) and using outlook send option the mails are send to appropriate user.
    but now i want to modify this application such as when i use the send command from my jsp page it should attach the file that is in .vcs or .ics format for auto updation of user calender.
    can any one know how to send attachment using java application .

    Last time I checked, SMS was a service between carriers and doing SMS yourself was really tricky. Some services existed to let you do it but as I recall they wanted non-trivial money.
    However, most phone carriers provide an email-to-SMS bridge of some kind.
    So the easiest thing is just to send an email.
    That's sending from a non-phone to a phone. There's a J2ME library to send/receive SMS from/to a phone.
    However, this is from memory, and a little out of date, so I could be entirely wrong. Hope it helps anyway.

  • We have a requirement to print the w2 forms for employees using java application, how can i implement this. Please give some suggestion.

    We have a requirement to print the w2 forms for employees using java application, how can i implement this. Please give some suggestion.

    Anyone any ideas to help please?

  • How to import the image by using java application

    1.how to import the image by using java APPLICATION and display it on the textarea that you have been created.
    2.how to store the image into the file.
    3. what class should i used?
    4. how to create an object to keep track the image in java application.
    * important : not java applet.
    plzzzzzzz.
    regards fenny

    follow the link:
    http://java.sun.com/docs/books/tutorial/2d/images/index.html

  • Want To create Zip file  using java,And Unzip without Java Program

    I want to create a zip text file using java, I know Using ZipOutputStream , we can create a zip file, , But i want to open that zip file without java program. suppose i use ZipOutputStream , then zip file is created But for unZip also difftrent program require. We cant open that zip file without writing diff java program.
    Actually i have one text file of big size want to create zip file using java , and unzip simply without java program.Its Possible??
    Here is one answer But I want to open that file normal way(
    For Exp. using winzip we can create a zip file and also open simply)
    http://forum.java.sun.com/thread.jspa?threadID=5182691&tstart=0

    Thanks for your Reply,
    I m creating a zip file using this program, Zip file Created successfully But when im trying to open .zip file i m getting error like "Canot open a zip file, it does not appear to be valid Archive"
    import java.io.*;
    import java.util.zip.*;
    public class ZipFileCreation
         public static void main (String argv[])
         try {
         FileOutputStream fos = new FileOutputStream ( "c:/a.zip" );
         ZipOutputStream zip = new ZipOutputStream ( fos );
         zip.setLevel( 9 );
         zip.setMethod( ZipOutputStream.DEFLATED );
    //     get the element file we are going to add, using slashes in name.
         String elementName = "c:/kalpesh/GetSigRoleInfo092702828.txt";
         File elementFile = new File ( elementName );
    //     create the entry
         ZipEntry entry = new ZipEntry( elementName );
         entry.setTime( elementFile.lastModified() );
    //     read contents of file we are going to put in the zip
         int fileLength = (int)elementFile.length();
         System.out.println("fileLength = " +fileLength);
         FileInputStream fis = new FileInputStream ( elementFile );
         byte[] wholeFile = new byte [fileLength];
         int bytesRead = fis.read( wholeFile , 0 /* offset */ , fileLength );
    //     checking bytesRead not shown.
         fis.close();
    //     no need to setCRC, or setSize as they are computed automatically.
         zip.putNextEntry( entry );
    //     write the contents into the zip element
         zip.write( wholeFile , 0, fileLength );
         zip.closeEntry(); System.out.println("Completed");
    //     close the entire zip
         catch(Exception e) {
    e.printStackTrace();
    }

  • Want to hide a folder using Java

    I want to hide a folder using Java. Can anyone give me API to do this.
    I have checked the I/O package in that only isHidden() is there which shows if the file is hidden or not. But i want to hide a folder using Java code.
    Can you please help me.
    Thanking you in advance

    If your dealing with a Linux directory you could hide it by prepending a dot. Or, if a directory of that name already exists, prepending a number of dots. Unhiding would consist of removing all the leading dots (and this operation might not always be possible).
    If it's a Windows directory you might want to look at the "attrib" command.
    [http://www.computerhope.com/attribhl.htm]

  • How to invoke Default printer of my system by using java application

    I need to invoke default printer of my system by using java application ? could u plz help me out with sample code?

    VoodooMagic.getDefaultPrinter().print();
    http://www.javaworld.com/javaworld/jw-10-2000/jw-1020-print.html
    Look for more at Google.

  • Manage Windows Using Java Application

    Hi,
    I am now developing a project, where we need to track the total time working.
    Eg. If i am working with outlook in my machine in various times, at the end, it should give me the total time of working with outlook.
    For this, i need to get the Windows ID (this case outlook). How can i access OS windows using java applications.
    Any idea how to do this???

    Hello,
    Syntax for Running report as JSP is as follow. The parameters can be passed by using "+" or "&".
    http://server.com/Employee.jsp?server=sac&destype=cache&desformat=html&userid=scott/tiger@database
    Use can pass reference parameters(user parameters)while ruuning the report.
    User can use User Parameters in his reports:
    "select * from emp where hiredate = :P_1"
    User can pass this parameter to Reports(while running it as JSP)as a parameter.
    http://server.com/Employee.jsp?server=sac&destype=cache&desformat=html&userid=scott/tiger@database&P_1=17-09-2000
    With Regards
    Sachin

  • Closing cd tray using java application

    sir,
    i want to close the cd tray using java program.i opened it using a vbs file which can be called through Runtime.getRuntime().exec("WScript <filename.vbs> ");
    But i want to know how can close this cd tray using java programming...
    the vbs file cotains the code for opening as
    CreateObject(\"Shell.Application\").NameSpace(17).ParseName(\"g\" & \":\\\").InvokeVerb(\"e&ject\")");
    Now i want to close the cd tray using a vbscript or through any other method which can be implemented in java..plz help me...........

    You can not do it directly, it would have to be via Runtime.exec, or JNI.
    As to how to do it via VBScript, this would not be the best forum to ask on. I'm sure Google will tell you if you ask it nicely.

  • Unable load jasperreports using java application

    I have created a report using jasperassistant.
    But i could'nt run the report using my java
    application.below given is the code sgment to call the
    report.
    try{
    String rFile="/root/Production.jasper";
    HashMap rptHash=null;
    FileInputStream fs=new FileInputStream(rFile);
    System.out.println("loading report file , read " +fs.available());
    JasperReport template=(JasperReport)JRLoader.loadObject(fs);
    System.out.println("Successfully created the report");
    JasperPrint report=JasperFillManager.fillReport(template,rptHash,conn);
    System.out.println("Report filled with data");
    }catch(JRException jex)
    System.out.println("Jasper Exception :"+jex.getMessage());
    System.out.println("Jasper Exception :"+jex.fillnStackTrace());
    System.out.println("Jasper Exception :"+jex.getStackTrace());
    System.out.println("Jasper Exception :"+jex.getLocalizedMessage());
    While running this application ,it throws into the
    exception section.
    Out put of the program is
    Loading report file ,read 15275
    Jasper Exception : Error loading object from InputStream
    Jasper Exception :net.sf.jasperreports.engine.JRException :Error loading object from InputStream Jasper Exception :[Ljava.lang.StackTraceElement;@e7b241
    Jasper Exception :Error loading object from InputStream
    I request you to go through my code and give me some help to solve this asap.
    thanking you

    Do you actually mean you want to make sure that only one instance of a GIVEN Java program is running at one time? If so then search this forum becuse this question comes up frequently.

  • Want to open a URL from java application?

    I want to open a URL (say http://yahoo.com) from my java application without using servlets. PLzzz help asap

    Include these packages:
    import java.net.*;
    import java.io.*;
    Proxy Setting If any:
    //getProxy your proxy address default "No Proxy".
    if (!getProxy.equals("No Proxy"))
    System.getProperties().put("proxySet","true");
    System.getProperties().put("proxyHost",getProxy);
    System.getProperties().put("proxyPort","80");
    Main code:
    URL url = new URL("http://mail.yahoo.com");
    URLConnection connection1 = url.openConnection();
    String filetext=postURL(connection1);
    Function postURL:
    public String postURL(URLConnection connection)
    try
    BufferedReader httpResponse = new BufferedReader(new InputStreamReader(connection.getInputStream()));
    String line = new String();
    StringBuffer buffer = new StringBuffer();
    while((line=httpResponse.readLine())!=null)
    buffer.append(line);
    httpResponse.close();
    return buffer.toString();
    catch(Exception e)
    System.out.println("Error:"+e);
    return "Error4" ;

  • Error in sending mail Using java application using SMTP.

    Hi,
    I have created a java application of self user registration which also sends email to the user.
    I have also added two JAR files ie mail.jar and activation.jar under the PORTAL_INF/lib.
    The code works well in other servers but its showing the error-
    java.lang.NoSuchMethodError: com.sun.activation.registries.MailcapFile.getMailcapList(Ljava/lang/String;)Ljava/util/Map;
    Thanks & Regards,
    Amarys.

    Hi Amarys,
    Please check if you have configure the mail server in SAP protal.
    Refer to below documents:
    [Send email, using SMTP on remote host|Send email, using SMTP on remote host]
    [Mailing throw webdynpro for java|Mailing throw webdynpro for java]
    Best Regards
    Arun Jaiswal

  • Hardware identification using Java-application

    Hi,
    please help me! I would like to get some hardware-specific information using a Java-application? Is it possible?
    Thanks everybody,
    dzsitter

    Probably not, in pure Java. Depends on what the "hardware" is that you had in mind.

  • Unable to run jasperreport using java application

    I have created a report using jasperassistant.
    But i could'nt run the report using my java
    application.below given is the code sgment to call the
    report.
    try{
    String rFile="/root/Production.jasper";
    HashMap rptHash=null;
    FileInputStream fs=new FileInputStream(rFile);
    System.out.println("loading report file , read " +
    fs.available());
    JasperReport
    template=(JasperReport)JRLoader.loadObject(fs);
    System.out.println("Successfully created the report");
    JasperPrint
    report=JasperFillManager.fillReport(template,rptHash,conn);
    System.out.println("Report filled with data");
    }catch(JRException jex)
    {System.out.println("Jasper Exception
    :"+jex.getMessage());
    System.out.println("Jasper Exception
    :"+jex.fillnStackTrace());
    System.out.println("Jasper Exception
    :"+jex.getStackTrace());
    System.out.println("Jasper Exception
    :"+jex.getLocalizedMessage());
    While running this application ,it throws into the
    exception section.
    Out put of the program is
    Loading report file ,read 15275
    Jasper Exception : Error loading object from
    InputStream
    Jasper Exception
    :net.sf.jasperreports.engine.JRException :Error
    loading object from InputStream
    Jasper Exception
    :[Ljava.lang.StackTraceElement;@e7b241
    Jasper Exception :Error loading object from
    InputStream
    I request you to go through my code and give me some help to solve this asap.
    thanking you

    Hi Again Monty.
    I may have given up too soon.
    Click once on the downloaded TheGame.zip file to highlight it.
    Press the Command⌘ + I keys, to Get Info.
    Change Open With to Stuffit Expander.
    Double-Click on TheGame.zip.
    A folder titled TheGame will be created. Open that.
    In there will be:
    decks An Empty Folder
    Game.jar
    game.xml
    images Folder This one has many sub entries.
    preferences.properties
    readme.txt
    release_notes.txt
    runme.bat
    When I Get Info on Game.jar, Open With is set to Jar Launcher.
    That's as far as I am going though. does that help any?
    ali b

  • X high CPU when using Java applications

    Only recently, my Freemind program has become extremely sluggish and unresponsive (big lag) when moving my mind map around. Freemind is made with Java. If I move the mind map around, the X process shoots to 20% CPU, doesn't seem a lot but something between X and Java programs are really bringing their performance down.
    I can barely use Freemind now. Freeplane is also affected.
    I noticed if I keep the Freemind window really small, it's responsive. If I maximise it, everything slows down within the application. Adding new notes, or move the map around, shoots X to a high CPU and there is a 5+ second lag in anything I do in the app.
    Is there anything I can do to improve performance? It's only started recently, everything is up-to-date.
    Last edited by nLinked (2013-06-08 13:57:31)

    Hi
    Try to use -Xloggc parameter with the jvm in order to see if problem comes on garbage colector. May be the mem usage is little and the gc thread is in active state. Try, also modify the mem usage with -Xms and -Xmx parameters and see the gc efects.
    You can use the -Xprof to output cpu profiling data.
    Also, find if there is a bug on servlet container / hard /SO you are using.
    Hope this helps

Maybe you are looking for