Sudoing a command with a redirection to a place owned by root

I want to :
echo "some text" > /path/owned/by/root
With sudo., I would :
sudo sh -c 'echo "some text" > /path/owned/by/root'
, and it asks me for a password. Now I want to do it from a script with no password, so I put in the following lines in sudoers :
Cmnd_Alias TESTBACKUPMEDIA = /bin/sh -c 'echo * /path/owned/by/root/*'
dlsa oraculo = NOPASSWD: TESTBACKUPMEDIA
and it still asks for the password. How do I make the configuration in sudoers match the command line ?

Oops, I didn't notice ...
sudo sh -c 'echo "some text" > /path/owned/by/root'
... which accomplishes exactly the same thing as my script. To accomplish what you want, something only root can do with no password required, I'd bury it a little deeper in a little C program. The binary would be setuid on exec (chmod 4750) and access to it contolled by group ownership. Setuid on exec only sets the effective user id of a process and that's not enough for a shell script. The C wrapper is necessary to set the real user id as well.
#include <sys/types.h>
#include <unistd.h>
main()
    setuid((uid_t) 0);
    execl("/path2/script", "/path2/script");
You also want to be sure that the script and its directory are appropriately protected by ownership and permissions. Before doing this sort of thing, I like to look for other ways to accomplish the same thing that do not require root access. Often there is.

Similar Messages

  • Mac hangs for any ipfwd command with uid.

    Hi,
    I need to resolve problem with ipfw firewall. When I add any new route which filter based on uid, I lost all connectivity and my Mac hangs. It only can be restored by power cycle.
    This is example of command I use:
    sudo ipfw add 100 allow ip from any to any uid root
    Tried to use different user ids, but it didn't help. My colleagues told me that it was a similar problem in FreeBSD, but it was fixed some time ago. This also affects version 10.5 and 10.6.
    Looks like it is Mac OS problem, but may be there are any workarround.

    Start with this comprehensive troubleshooting article:
    https://discussions.apple.com/docs/DOC-3521
    Look at this one for possible solutions:
    https://discussions.apple.com/docs/DOC-3353
    Ciao.

  • Create app to run Sudo rm command

    I would like to develop a simple application that runs the sudo rm command. I would like the interface to be a simple drag-and-drop window and an execute button. I have xcode but im not familiar with how to use it. I have also heard that people can use automator to create apps.
    Any help is appreciated, and i have an email if more regular correspondence is needed. Thanks in advance!
    Kenny

    X Windows Manager provides an interface to render the windows and basic widgets on screen, see http://en.wikipedia.org/wiki/X_Window_System.
    LabVIEW for Linux has in principle a rather hard dependency on some form of Windows manager being present. During startup of LabVIEW this X Window manager is initialized and if it isn't present all kind of havoc can occur.
    I think there was some semi documented INI file setting that one could use to allow a LabVIEW app to start up even if no X Window manager was installed but that had its own difficulties. In my experience it wasn't really worth the hassles. The easier solution was usually to install a minimal X Window server such as a text only variant so that the dependency was properly satisfied and LabVIEW could initialize everything properly, eventhough no user interface was later displayed in the LabVIEW app.
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • Executing sudo linux commands through a JSP page.

    Hi,
    I need to execute some superuser commands through a JSP page under Linux.
    I added users apache and tomcat to the /etc/sudoers file with no password prompting.
    My JSP page works fine with any usual linux command, but when I call a “sudo cmd” I have a message (when reading the ErrorStream instead of the InputStream) that “sudo can’t be executed because it needs a tty” even when I call the shell before the sudo command.
    Here is a piece of my code (very basic):
    String cmd="linux_cmd";
    Process proc = Runtime.getRuntime().exec(cmd);
    InputStream stdin = proc.getInputStream();
    InputStreamReader isr = new InputStreamReader(stdin);
    BufferedReader br = new BufferedReader(isr);
    String line = null;
    while ( (line = br.readLine()) != null)
    out.println(line);
    Is there any way I can make sudo calls from a JSP page ?
    I know that making root calls from a web application is a bad thing, but for now security is not my concern.
    Thank you for any tips.

    JavaFan2 wrote:
    In fact, I help supervising a student project who is supposed to write an admin application to offert graphical interfaces for some security and system tools under Linux (like fdisk, iptables etc) using J2EE, ... something like Webmin.
    As I said, I know that is has a huge security risk but this app has the only purpose of learning J2EE, no security issues are treated.If you want to say "I will leave my office door open because there's no security risk in doing that" then that's a valid statement. But what you are trying to do here isn't the equivalent of leaving your office door open. It's the equivalent of finding a master key for all the offices in the world. And as such it is in fact a serious security risk which should not be circumvented.
    And no, it's no good saying "But I'm only going to use this all-powerful master key to open my own office door". If you get the key then anybody else can get the key too.

  • Sudo: user: command not found

    Hi there,
    I'm struggling with this sudo problem.
    All i've been doing with terminal was logging into another account on my iMac and running an application, so i write sudo disk (disk is username for the other account)
    then i enter password and path to the application
    i've been doing this for past 3-4 month every day, bet since yesterday after entering pasword i get this error - sudo: user: command not found
    Any help here would be appreciated!
    Thank you

    which sudo returns: /usr/bin/sudo
    i used First Aid to verify disk permissions 3 times.. repaired them, but it keeps giving me the same errors every time i hit Verify Disk Permissions..
    List of errors:
    Permissions differ on "System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/jconsole.ja r", should be lrwxr-xr-x , they are lrw-r--r-- .
    User differs on "System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib", should be 0, user is 95.
    User differs on "System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Libraries", should be 0, user is 95.
    Permissions differ on "System/Library/Java/Support/Deploy.bundle/Contents/Home/lib/security/cacerts", should be lrwxr-xr-x , they are lrw-r--r-- .
    Permissions differ on "System/Library/Java/Support/Deploy.bundle/Contents/Resources/Java/deploy.jar", should be lrwxr-xr-x , they are lrw-r--r-- .
    Permissions differ on "System/Library/Java/Support/Deploy.bundle/Contents/Resources/JavaPluginCocoa.b undle/Contents/Resources/Java/deploy.jar", should be lrwxr-xr-x , they are lrw-r--r-- .
    Permissions differ on "System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Classes/jconsole.jar ", should be -rw-r--r-- , they are lrw-r--r-- .
    Permissions differ on "System/Library/Frameworks/JavaVM.framework/Versions/A/Resources/Deploy.bundle/ Contents/Home/lib/security/cacerts", should be -rw-r--r-- , they are lrw-r--r-- .
    Permissions differ on "System/Library/Frameworks/JavaVM.framework/Versions/A/Resources/Deploy.bundle/ Contents/Resources/Java/deploy.jar", should be -rw-r--r-- , they are lrw-r--r-- .
    Permissions differ on "System/Library/Frameworks/JavaVM.framework/Versions/A/Resources/Deploy.bundle/ Contents/Resources/Java/libdeploy.jnilib", should be -rwxr-xr-x , they are lrwxr-xr-x .
    Permissions differ on "System/Library/Frameworks/JavaVM.framework/Versions/A/Resources/Deploy.bundle/ Contents/Resources/JavaPluginCocoa.bundle/Contents/Resources/Java/deploy.jar", should be lrwxr-xr-x , they are lrw-r--r-- .
    Permissions differ on "System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Resources/JavaPlugin Cocoa.bundle/Contents/Resources/Java/deploy.jar", should be -rw-r--r-- , they are lrw-r--r-- .
    Permissions differ on "System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Resources/JavaPlugin Cocoa.bundle/Contents/Resources/Java/libdeploy.jnilib", should be -rwxr-xr-x , they are lrwxr-xr-x .
    Warning: SUID file "System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/MacOS/ARDAg ent" has been modified and will not be repaired.
    Permissions verification complete
    Are these pretty bad errors? Are these causing sudo not to work?

  • Terminal commands with automator

    So I am not really used to scripts and the script language nor in automator, I only made a few apps with automator like resize picture and show/hide hidden files.
    Now I am about to make an app which cleans my OS, I would like to run all these commands with one click, rather then copy pasting them into terminal one- by-one.
    sudo rm -rf /private/var/log/*
    sudo rm -rf /private/var/folders/
    cd /private/var/tmp/; rm -rf TM*
    cd ~/Library/Caches/; rm -rf ~/Library/Caches/*
    this would clean my mac caches and logs, like i would run it every week as im a power user.
    Please someone tell me how to put all these into automator and try to be detailed. Thanks for the support!

    Thanks for both positive, useful and sarcastic responses. The main reason is why I want to do this is becasuse I use different browsers, and all the cache they make is 2-3GB/day, as I use the web the most.
    I see the reason why NOT TO clear it and I do understand it, but after a week it is 10-15GB for me.
    And no, there isnt anyone else using my Mac, and the logs which I would nuke at every start and only keep the last and updated logs. I only need the startup and boot log.
    @barney-15E yes it would be fun though
    So then, I wont do anythings, as it cannot be done the way I wanted. I'll keep using Onyx.

  • Returning from a JSF flow with faces-redirect

    I'm using Glassfish 4.1 with JSF 2.2.9. I can't figure out how to return from a JSF flow with a redirect. I've tried this in the flow definition xml:
    <flow-return id="returnFromFlow">
        <from-outcome>/index.xhtml?faces-redirect=true</from-outcome>
    </flow-return>
    This does the redirect but results in navigation errors on the page, specifically the button that enters the flow again: "Unable to find matching navigation case from view ID '/index.xhtml' for outcome 'select-person'" (the flow is called select-person).
    I've also tried appending faces-redirect=true to the action of the commandButton that exits the flow. Now the flow does not exit, it reloads the current page within the flow and says "Unable to find matching navigation case with from-view-id '/select-person/select-person.xhtml' for action 'returnFromFlow?faces-redirect=true' with outcome 'returnFromFlow?faces-redirect=true'"
    Exiting the flow with h:link works, but I want to be able to call an action and submit form values with the button so that isn't a good workaround for me.
    What's kind of interesting is that navigating between views within the flow DOES work with faces-redirect=true. I can add a "step2" node, and a commandButton with action="step2?faces-redirect=true", and it works. It's just exiting the flow that does not work.
    Any ideas?

    Hi Frank,
    Thanks so much for your response.
    Yes, since the user can do a commit prior to exiting my edit task flow, option 1 will not work for me.
    Option 2 sounded feasible, but jdeveloper would not let me set the restore point to true, since my btf didn't require a transaction. Is there a step I'm missing here??
    The thing that is really getting me when return via the cancel button from this edit task flow, back to my parent task flow, the record pointer is always moving back to the beginning of the data set in my parent task flow. For example,if I have a data set
    rec1, rec2, rec3..
    On my parent taskflow call it browser task flow, I navigate (via the next button) to rec3, and I click edit. At this point, my edit task flow kicks off, and since both task flows share the same data control, the edit task flow rec pointer is the same as the browse one.
    Okay I decide I don't want to change anything in my rec3, so I click cancel.
    At this point, when I return back to the navigator task flow, it points me back to rec1 ..
    HOwever, the savepoint seems to fix this. When I set my cancel return from edit taskflow to savePoint = true, the rec pointer stays in the correct spot. However, I cannot always do this, because the user can make iterative saves in the edit task flow which (based on your previous email) stales out the savepoint id.
    Question, so in this case, how can I make the parent browser task flow call stay on the same record I was just editing, opposed to going back to the beginning of the data set(ie. rec1)??

  • App-v 5.0 sp3 Publish application icons/ shourtcut missed on 2nd time logon on terminal server 2012 r2 with roaming profile with folder redirection

    1. I updated app-v 5.0 sp3 environment on 2012 R2. Roaming profile users with folder redirection logon fine at first time applications icons available but at 2nd logon applicaitons icons are missed while packages are available. we are using existing
    roaming profiles with folder redirection which are running in current environment through APP-V 4.6 2008 R2. Please suggest work around to resolve this issue.
    2. TS Nodes of 2008 R2 with App-v 4.6 running fine on Microsoft 2012 private cloud but we are facing performance issue (stuck, slow logon, slow performance etc) when we are moving in new 2012 R2 private cloud. SAP, SCSM and other sevices are running
    fine, please provide solution.
    Thanks

    1.) What are you doing with the App-V Icon path? e.g. %LOCALAPPDATA%\Microsoft\AppV\Client\Integration\<GUID>\Root\AppVClientUX.exe.0.ico ?
    I guess you could workaround it with deploying the icons to a central location and then pointing to the icon out on a central share. Or put the icons in a machine location...I haven't had this issue but that's just off the top of my head.
    2.) I have not used App-V 4.6 in an environment like yours BUT would pre-caching the applications be possible? Any chance you'll be moving those apps into App-V 5.0 soon?
    PLEASE MARK ANY ANSWERS TO HELP OTHERS Blog:
    rorymon.com Twitter: @Rorymon

  • Disk repair using the format - repair command with a mounted partition

    I was going to repair some bad blocks on a disk by using the format command with the repair option. When I entered the block number to be fixed it came back withthe question of:
    "Repair is in a mounted partition, continue?"
    Will I hurt anything on my system if I answer yes to continue or should the partition be unmounted before I do this?
    Thanks

    Did you have any answer?

  • Tcp/ip write help - need to send a motor command with parameters

    hello - i have one small, main labview 7.0 vi that i use to control a drill's two motors.
    right now i press a button on the front panel to move the motor, and when i do, a sub vi window pops up so the operator can set a couple of parameters and press an ok button.....the vi then sends the command with the parameters to the drill's motors.
    i am trying to change it so i can send the move command from another computer, in another room, while the main vi sits on the computer with the drill. i know i will use TCP listen, write, read, and close in both the main vi (the TCP server?) and the client which is on the remote computer.
    my problem is with setting the parameters for the subvi's that usually pops up. how do i set the parameters from the remote-client and have them be sent into the subvi on the main vi. if i can do this, i would have to also have a way to close the sub vi after it pops up in the main program too.
    OR should i use something else like and application reference or an invoke node function?????
    please help
    thanks!!!!
    sam

    Hi again,
    If the VI in the lab will be running continuously, then you will need
    to alter some things from the example I sent you or look at an
    alternate implementation. The example I sent you assumed that the VI in
    the lab was not running. This technique actually starts the VI and runs
    it somewhat like a subVI. It inputs values into the connector pane,
    runs it, and then returns values from the outputs on the connector pane
    after it finishes executing. It will not work to call a VI by reference
    if it is already continuously running.
    Instead I imagine you would want to have your VI in the lab have some
    sort of State Machine that polls a certain control value, such as an
    enum control, to determine which state to execute next. You could
    modify the technique I first sent to still open a reference to the VI
    in the lab, but it wouldn't try to run it. Instead you could use the VI
    method Set Control Value to set the value of a certain control or
    controls in the lab VI to certain values. The VI in the lab would then
    hopefully be in some Idle state where it polled one of those control
    values continuously to decide what to do next. That would allow the VI
    in the office to programmatically send commands to the other VI, as
    well as parameters for those commands. Simply set control values for
    the VI in the lab and let the VI in the lab go about its business. I've
    attached an example below.
    That's just one idea. Other options you have would be to use a
    DataSocket connection to send parameters and commands back and forth
    between computers. This is a pretty simple API to use. If you have
    LabVIEW 8, Shared Variables are an option. Or you might look into
    simply using Remote Front panels, which allows you to connect to a VIs
    Front Panel across the network. You could then have the whole VI in the
    Lab, but you could connect to it, view it, modify the controls and so
    on from your office. If you want to view and control a VI without
    having LabVIEW installed on the viewing computer, you can use the Web
    Publishing Tool to create a web interface for your front panel. Lots of
    options. Let me know what sounds interesting.
    Jarrod S.
    National Instruments
    Attachments:
    Lab_VI.vi ‏29 KB
    Office_VI.vi ‏51 KB

  • FTP STOR command with REST capability

    Hi folk,
    I have a cRIO on a remote field, and I need that the program running on that platform periodically uploaded, through the internet, the data files to an FTP server.
    I have used the FTP VIs included in the Internet Toolkit to develop this functionality and I am experiencing some problems.
    During the uploading of files of medium or large size, via FTP, can happen that the FTP server closes the connection.
    The reasons can be different, network operation exceeded the user-specified or system time limit, bandwidth usage is restricted or the bandwidth is limited, etc..
    To overcome this issue the correct strategy is to reopen the FTP connection and to restart the upload from the point where it was interrupted.
    It is very important to finish to upload only the remaining part of the file, and not to restart from the beginning, otherwise you could not end the upload if the FTP server closes the connection again and again.
    For implementing the resume, the FTP protocol supports a number of commands:
    SIZE <remote file-name>  Returns the size of a file (Binary mode) .
    REST <file-size>         Sets the following STOR command to restart transfer
                             from the specified point.
    STOR <remote file-name>  If anticipated from a REST command, store (upload)
                             only the part of the file starting from the
                             specified point.
    At the present, it seams to me that the LabVIEW Internet Toolkit does not support the capability of FTP resume.
    Furthermore, if during a FTP upload the connection is closed by the FTP server, the FTP [STOR].vi exits sometime with ambiguous errors.
    Exit with a correct error:
    Error 56 occurred at TCP Read in NI_InternetTK_Common_VIs.lvlib:TCP Read xTP Reply.vi:2->NI_InternetTK_FTP_VIs.lvlib:FTP Get Command Reply.vi:1->NI_InternetTK_FTP_VIs.lvlib:FTP Data Send.vi->NI_InternetTK_FTP_VIs.lvlib:FTP [STOR].vi
    Possible reason(s):
    LabVIEW:  The network operation exceeded the user-specified or system time limit.
    Exit with an ambiguous error:
    Error 54 occurred at TCP Open Connection in NI_InternetTK_FTP_VIs.lvlib:FTP Open Data Connection.vi->NI_InternetTK_FTP_VIs.lvlib:FTP Data Send.vi->NI_InternetTK_FTP_VIs.lvlib:FTP [STOR].vi
    Possible reason(s):
    LabVIEW:  The network address is ill-formed. Make sure the address is in a valid format. For TCP/IP, the address can be either a machine name or an IP address in the form xxx.xxx.xxx.xxx. If this error occurs when specifying a machine name, make sure the machine name is valid. Try to ping the machine name. Check that you have a DNS server properly configured.
    Do you have idea or suggestion of how  realize an FTP STOR command with REST capability?
    Thanks,
    Asper

    Unfortunately the best advice I could give you would be to make a copy of the FTP toolkit and add this functionality yourself. You should have most of the building blocks available to you so it should be fairly starightforward. You could reference the RFC (RFC 959 and RFC 3659 for extensions) for any specifics you need on the packet format. You will need to save some state information so you can resume your download from the correct point.
    Would it be possible to use TFTP? This is much leaner and more likely to succeed if the other ends supports it. I recently wrote a very basic TFTP Write. I'm sure I could do the TFTP Read in short order. I'm still working on packaging it up in a distributable form but I could provide you with a basic VI if needed.
    Mark Yedinak
    "Does anyone know where the love of God goes when the waves turn the minutes to hours?"
    Wreck of the Edmund Fitzgerald - Gordon Lightfoot

  • At CRS-1,how can i use show command with pipe | ?

    HI,ALL
    when I use show command with pipe on the CRS-1,the command invalid
    RP/0/RP0/CPU0:JA-DL-CR-1.MAN.CRS-1#show interfaces | include line |errors 
                                                                       ^
    % Invalid input detected at '^' marker.
    ========================================================
    But Previously on the cisco 7609,I can use the show command
    GZ-DM-SR-1.MAN.7609#show int | include line |err
    Vlan1 is down, line protocol is down
         0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored
         0 packets output, 0 bytes, 0 underruns
         0 output errors, 0 interface resets
    Vlan11 is administratively down, line protocol is down
         0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored
         0 packets output, 0 bytes, 0 underruns
         0 output errors, 0 interface resets
    Vlan99 is down, line protocol is down
         0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored
         0 packets output, 0 bytes, 0 underruns
         0 output errors, 0 interface resets

    RP/0/RP0/CPU0:JA-DL-CR-1.MAN.CRS-1#show interfaces | include line |errors 
                                                                       ^
    % Invalid input detected at '^' marker.
    RP/0/RP0/CPU0:JA-DL-CR-1.MAN.CRS-1#show interfaces | include line |?    

    RP/0/RP0/CPU0:JA-DL-CR-1.MAN.CRS-1#show interfaces | include line | |?
                                                                        ^
    % Invalid input detected at '^' marker.
    RP/0/RP0/CPU0:JA-DL-CR-1.MAN.CRS-1#show interfaces | include line | ?
      begin    Begin with the line that matches
      exclude  Exclude lines that match
      file     Save the configuration
      include  Include lines that match
      utility  A set of common unix utilities
      <cr>    
    RP/0/RP0/CPU0:JA-DL-CR-1.MAN.CRS-1#show interfaces | include line |
    % Incomplete command.
    RP/0/RP0/CPU0:JA-DL-CR-1.MAN.CRS-1#show interfaces | include line |errors
                                                                       ^
    % Invalid input detected at '^' marker.
    RP/0/RP0/CPU0:JA-DL-CR-1.MAN.CRS-1#                                     
    RP/0/RP0/CPU0:JA-DL-CR-1.MAN.CRS-1#show interfaces | include line | ?   
      begin    Begin with the line that matches
      exclude  Exclude lines that match
      file     Save the configuration
      include  Include lines that match
      utility  A set of common unix utilities
      <cr>    
    RP/0/RP0/CPU0:JA-DL-CR-1.MAN.CRS-1#show interfaces | include line |?

    RP/0/RP0/CPU0:JA-DL-CR-1.MAN.CRS-1#show interfaces | include line | include er$
    Thu Jan 15 22:36:24.120 GMT
    RP/0/RP0/CPU0:JA-DL-CR-1.MAN.CRS-1#
    RP/0/RP0/CPU0:JA-DL-CR-1.MAN.CRS-1#show interfaces | include line           
    Thu Jan 15 22:37:05.013 GMT
    Loopback0 is up, line protocol is up
    Loopback1 is up, line protocol is up
    Loopback6 is up, line protocol is up
    Null0 is up, line protocol is up
    POS0/0/0/0 is up, line protocol is up  (APS not Configured )
    POS0/0/1/0 is up, line protocol is up  (APS not Configured )
    TenGigE0/0/4/0 is up, line protocol is up

  • Send SOAP commands with a header

    I have been playing with the SOAP function in applescript and would really like to be able to send a xml command with a header and a body. I need to send the header because it contains the authentication info.
    Is there a way to send commands with a custom header?
    or is there a shell command that would work better here?
    this is the info I have been referencing:
    http://developer.apple.com/documentation/AppleScript/Conceptual/soapXMLRPC/chapt er3/chapter3_section_3.html#//apple_ref/doc/uid/TP30001126-//appleref/doc/uid/20001723-BAJBFJBD

    first, SOAP services don't work that way. Here is a snippet of my SOAP call to check my email:
    on getPOPmessageCount(popserver, _popserverport, _login, _password)
    tell application "http://www.cosme.nu/services/pop.php"
    set POPmessageCount to (call soap ¬
    {method name:"countmessages", method namespace uri:"http://www.cosme.nu/services/", parameters:¬
    {popserver:_popserver, popserverport:_popserverport, login:_login, |password|:_password} ¬
    , SOAPAction:"http://www.cosme.nu/services/pop.php"})
    end tell
    return POPmessageCount
    end get_POPmessageCount
    There are required parameters for login name & password by www.cosme.nu. AS SOAP call takes care of formatting.
    Since we are hosting the services ourselves
    internally, is there something that I can change on
    the server that would help?
    You need to check with your system admin, is your server running SOAP/RPC services?

  • Execute an Unix command with pipe

    Hi,
    How do I execute a unix command with pipe from JAVA runTime.exec(cmd)? for example: "ls -l |wc -l"
    should return number of files. However, there is no output result. If I use "ls -l" as command argument, it gives file list.
    Here is my program:
    public static void main(String[] args) {
    try {
    Runtime runCmd = Runtime.getRuntime();
    System.out.println("sys testing");
    Process retProc = runCmd.exec(args[0]);
    BufferedReader bread = new BufferedReader
    (new InputStreamReader(retProc.getInputStream()) );
    String out = bread.readLine();
    while ( out != null ) {
    System.out.println(out);
    out = bread.readLine();
    DataOutputStream outSt = new DataOutputStream(retProc.getOutputStream() );
    outSt.writeChars(args[1]);
    outSt.flush();
    } catch (Exception ie) {
    ie.printStackTrace();
    Thanks in advance,
    Jeff

    I got my answer !
    No need to reply

  • How to run Unix command with Pipe ( | )?

    Dear Friends,
    I have to execute the below unix command through java program.
    *ps -ewwo pid,args | grep -E "abc.sh|xyz.jar" | gawk '{ print $1 }' | wc -l*
    My code to execute this command is,
    Runtime run = Runtime.getRuntime();
    File workDir = new File("/root/sat");
    String psCmd = "ps -ewwo pid,args | grep -E \"abc.sh|xyz.jar \" | gawk '{ print $1 }' | wc -l";
    Process process = run.exec(psCmd, null, workDir);
              String line;
              int i = process.waitFor() ;
              if(i == 0) {
              BufferedReader buf = new BufferedReader( new InputStreamReader( process.getInputStream() ) ) ;
              while ( ( line = buf.readLine() ) != null )
                   System.out.println("Line - ["+line+"]") ;
              } else {
                   BufferedReader stdErr = new BufferedReader(new InputStreamReader(process.getErrorStream()));
                   // read the output from the command
                   while ((line = stdErr.readLine()) != null) {
                   System.out.println(line);
                   }When i execute this command, i'm getting output as,
    ERROR: Garbage option.
    When i analyse the above error, i found that, the PIPE ( | ) command is not supported through java.
    Could anyone please help me how to execute the above unix command (with | ) in java?
    Thanks in advance,
    Sathish

    The pipe has to be interpreted by a shell so you need
    String[] psCmd =
        "sh",
        "-c"
        "ps -ewwo pid,args | grep -E \"abc.sh|xyz.jar \" | gawk '{ print $1 }' | wc -l"
    Process process = run.exec(psCmd, null, workDir);You should also read, re-read and then implement the recommendations in the 4 sections of http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html .

Maybe you are looking for

  • Partition Map Schemes: HFS+ and FAT32 partitions with OSX and Windows

    OK so I know this question has been practically beaten to death, but I keep finding conflicting information. I am using a 2011 MacBook Pro, on which I will set up Windows through Boot Camp. I recently purchased a 750 GB WD external hard drive to use

  • How to view *.eml files in Lotus Notes as native application?

    Using Desktop Integration for Lotus Notes, and using Contribution Folders via Notes: I can drop-and-drag an e-mail from lotus notes inbox to the contribution folder (in Notes) ok. I can view the *.eml file in Contribution Folder (Notes and Explorer),

  • I downloaded a trial of Dreamweaver CS6 CC - Missing Elements

    The search bar which should be located at the top right-hand side of page is missing, so are the predefined workspaces such as 'classic' and 'developer'. I have just started hosting & developing and was thinking i would invest in the entire CS6 suite

  • Macbook Pro won't sleep when lid shuts or hit sleep

    Hey Everyone, So after the latest update my Macbook pro no longer immediately sleeps after shutting the lid. It also won't sleep when 'sleep' is hit in the apple menu. It's actually really annoying as I need it for security. Does anyone know how to f

  • HELP!!--my ipod screen is not working!!

    my screen appears to be burnt out. what makes it all so weird is that i can still listen to music and go to the menus. but part of the screen is covered in black. and the other part that is unreadable is very dark but has a lot of colors around it. i