Problem running shell command

hi
i am just trying to run a simple msdos command
public class TestImage{
    public static void main(String args[]){
     try{
         Process p=Runtime.getRuntime().exec("echo");
     catch(IOException e){
         System.out.println(e);
}and i get this error message
java.io.IOException: CreateProcess: echo error=0
can someone explain me what's wrong
thanks

i ve tried it and the dos shell crashed
import java.io.*;
import java.awt.*;
public class TestImage{
    public static void main(String args[]){
     String output = null;
     BufferedReader input = null;
     String cmd[] = { "command.com", "/c", "echo", "%CLASSPATH% " };
     try {   
         Process process = Runtime.getRuntime().exec(cmd);   
         input = new BufferedReader(new InputStreamReader(process.getInputStream()));   
         while ((output = input.readLine()) != null) {
          System.out.println(output);
     } catch (java.io.IOException ioe) {
         ioe.printStackTrace();

Similar Messages

  • Run shell commands using java program

    Hi guys,
    I am trying to run shell commands like cd /something and ./command with arguments as follows, but getting an exception that ./command not found.Instead of changing directory using "cd" command I am passing directory as an argument in rt,exec().
    String []cmd={"./command","arg1", "arg2", "arg3"};
    File file= new File("/path");
    try{
    Runtime rt = Runtime.getRuntime();
    Process proc = rt.exec(cmd,null,file);
    proc.waitFor();
    System.out.println(proc.exitValue())
    BufferedReader buf = new BufferedReader(new InputStreamReader(proc.getInputStream()));
    catch(Exception e)
    {e.printStackTrace();
    So can anyone please tell me what is wrong with this approach? or is there any better way to do this?
    Thanks,
    Hardik

    warnerja wrote:
    What gives you the idea that the process to execute is called "./command"? If this is in Windows, it is "cmd.exe" for example.It does not have to be cmd.exe in Windows. Any executable or .bat file can be executed as long as one either specifies the full path or the executable is in a directory that is in the PATH.
    On *nix the file has to have the executable bit set and one either specifies the full path or the executable must be in a directory that is in the PATH . If the executable is a script then if there is a hash-bang (#!) at the start of the first line then the rest of the line is taken as the interpreter  to use. For example #!/bin/bash or #!/usr/bin/perl .
    One both window and *nix one can exec() an interpreter directly and then pass the commands into the process stdin. The advantage of doing this is that one can change the environment in one line and it  remains in effect for subsequent line. A simple example of this for bash on Linux is
    import java.io.OutputStreamWriter;
    import java.io.Writer;
    public class ExecInputThroughStdin
        public static void main(String args[]) throws Exception
            final Process process = Runtime.getRuntime().exec("bash");
            new Thread(new PipeInputStreamToOutputStreamRunnable(process.getErrorStream(), System.err)).start();
            new Thread(new PipeInputStreamToOutputStreamRunnable(process.getInputStream(), System.out)).start();
            final Writer stdin = new OutputStreamWriter(process.getOutputStream());
            stdin.write("xemacs&\n");
            stdin.write("cd ~/work\n");
            stdin.write("dir\n");
            stdin.write("ls\n");
            stdin.write("gobbldygook\n"); // Forces output to stderr
            stdin.write("echo $PATH\n");
            stdin.write("pwd\n");
            stdin.write("df -k\n");
            stdin.write("ifconfig\n");
            stdin.write("echo $CWD\n");
            stdin.write("dir\n");
            stdin.write("cd ~/work/jlib\n");
            stdin.write("dir\n");
            stdin.write("cat /etc/bash.bashrc\n");
            stdin.close();
            final int exitVal = process.waitFor();
            System.out.println("Exit value: " + exitVal);
    }One can use the same approach with Windows using cmd.exe but then one must be aware of the syntactic differences between commands running in .bat file and command run from the command line. Reading 'help cmd' s essential here.
    The class PipeInputStreamToOutputStreamRunnable in the above example just copies an InputStream to an OutputStream and I use
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    public class PipeInputStreamToOutputStreamRunnable implements Runnable
        public PipeInputStreamToOutputStreamRunnable(InputStream is, OutputStream os)
            is_ = is;
            os_ = os;
        public void run()
            try
                final byte[] buffer = new byte[1024];
                for (int count = 0; (count = is_.read(buffer)) >= 0;)
                    os_.write(buffer, 0, count);
            } catch (IOException e)
                e.printStackTrace();
        private final InputStream is_;
        private final OutputStream os_;
    }

  • Running Shell Commands (not Executable) in Unix from Java

    What are my options to run shell commands from Java?
    My goal is to change my existing shell environment variables to some new ones provided by .anotherProfile.
    Using an executable from Java is not an option because it does not work i.e. ( exec(". /home/.profile") ) brings up errors.
    Someone has suggested that I start a child shell with that profile and work from there, but I'm unfamiliar with that sort of syntax and programming in general.
    Any good help equals duke dollars :)

    Well there are some possibilities. In the original thread you mentioned that you wanted the shell script to be executed to change some enviroment parameters of the shell the JVM is executing in.
    If so, and you are able to rewrite the profile so you can parse it manually. Then you can change some environment setting by writing the JNI wrappers for the getenv and setenv system calls. (Check your man pages)
    That will change the environment. I am just wondering what good it will do for you? What's use of sourcing the profile in a JVM?

  • [Solved] stumpwm: how to get rid of newline using run-shell-command

    Hi all,
    in order to set up my mode-line for stumpwm, I've been using the commad
    run-shell-command such as in:
    (setf *screen-mode-line-format*
    (list
    '(:eval (run-shell-command "date" t))
    '(:eval (run-shell-command "date" t))))
    However, each instance of run-shell-command creates an unnecessary
    newline (so that my mode line contains two lines without necessity).
    Do you know how I can get rid of this newline?
    Thanks!
    Last edited by falsum (2011-05-23 07:12:27)

    jiyuu wrote:
    I didn't test it but the function you want is 'string-trim' or 'string-right-trim'.
    You use it like this:
    (string-trim '(#\Newline) my-string)
    So in your case:
    (setf *screen-mode-line-format*
    (list
    '(:eval (string-trim '(#\Newline)
    (run-shell-command "date" t)))
    '(:eval (run-shell-command "date" t))))
    That works perfectly well. Thanks a lot jiyuu!!

  • Running shell commands in pre-post session commands

    Hi Nikita: It depends on what kind of OS your Secure Agent is running on. If you're running your Secure Agent on Windows, you can enter DOS commands into these fields which may include SQL scripts using batch files. Similarly, if you're running your Secure Agent on Linux you can enter shell commands which may include SQL scripts using shell scripts. You should be able to find some examples of these commands from other Informatica Cloud users by searching the Community. Hope this helps,Josh

    Hi all,I am new to informatica, can anyone please explain me how should i run shell commands in pre/post session commands?and what type of shell scripting is usually needed for the informatica jobs? Thank you

  • BPEL with inline JAVA to run shell command

    I'm quite happy I figured this out.
    Issues I discovered include JDeveloper wants to rearrange the order of the inline java to be placed after the Return_Output Assign which should be placed after it.
    I could only discover this by looking at the BPEL source as graphicly it was still
    displayed in the expected order.
    Also I had issues in the past with not being able to reference the input and output message variables from inline Java so I bypassed that headache and provide ordinary variables for Java to interact with and simply XML Copy operations to
    populate and use those variables.
    If you are trying to build this yourself from scratch you will have to edit the BPEL source to have the java import lines as there is no drag and drop functionality for that.
    For testing , from the BPEL console
    shell = /bin/bash
    shellOpts = -c
    cmd = ls /home/soa
    cmdArgs
    cmdArgs didn't work when populated instead they worked when included in cmd.
    Also tried
    shell = /usr/bin/perl
    shellOpts = -e
    cmd = print "Hello World";
    cmdArgs
    Both returned expected text output.
    Fun!!
    This was built as a synchronous BPEL process...
    <?xml version = "1.0" encoding = "UTF-8" ?>
    <!--
    Oracle JDeveloper BPEL Designer
    Created: Mon Feb 18 10:38:58 PST 2008
    Author: rtaylor
    Purpose: Synchronous BPEL Process
    -->
    <process name="Call_Script"
    targetNamespace="http://xmlns.oracle.com/Call_Script"
    xmlns="http://schemas.xmlsoap.org/ws/2003/03/business-process/"
    xmlns:bpws="http://schemas.xmlsoap.org/ws/2003/03/business-process/"
    xmlns:xp20="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.Xpath20"
    xmlns:ldap="http://schemas.oracle.com/xpath/extension/ldap"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:bpelx="http://schemas.oracle.com/bpel/extension"
    xmlns:client="http://xmlns.oracle.com/Call_Script"
    xmlns:ora="http://schemas.oracle.com/xpath/extension"
    xmlns:orcl="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.ExtFunc">
    <!--
    PARTNERLINKS
    List of services participating in this BPEL process
    -->
    <partnerLinks>
    <!--
    The 'client' role represents the requester of this service. It is
    used for callback. The location and correlation information associated
    with the client role are automatically set using WS-Addressing.
    -->
    <partnerLink name="client" partnerLinkType="client:Call_Script"
    myRole="Call_ScriptProvider"/>
    </partnerLinks>
    <!--
    VARIABLES
    List of messages and XML documents used within this BPEL process
    -->
    <variables>
    <!-- Reference to the message passed as input during initiation -->
    <!-- Reference to the message that will be returned to the requester-->
    <variable name="inputVariable"
    messageType="client:Call_ScriptRequestMessage"/>
    <variable name="outputVariable"
    messageType="client:Call_ScriptResponseMessage"/>
    <variable name="shell" type="xsd:string"/>
    <variable name="shellOpts" type="xsd:string"/>
    <variable name="cmd" type="xsd:string"/>
    <variable name="cmdArgs" type="xsd:string"/>
    <variable name="commandOutput_external" type="xsd:string"/>
    </variables>
    <!--
    ORCHESTRATION LOGIC
    Set of activities coordinating the flow of messages across the
    services integrated within this business process
    -->
    <sequence name="main">
    <!-- Receive input from requestor. (Note: This maps to operation defined in Call_Script.wsdl) -->
    <receive name="receiveInput" partnerLink="client"
    portType="client:Call_Script" operation="process"
    variable="inputVariable" createInstance="yes"/>
    <!-- Generate reply to synchronous request -->
    <assign name="Assign_Script">
    <copy>
    <from variable="inputVariable" part="payload"
    query="/client:Call_ScriptProcessRequest/client:shell"/>
    <to variable="shell"/>
    </copy>
    <copy>
    <from variable="inputVariable" part="payload"
    query="/client:Call_ScriptProcessRequest/client:shellOpts"/>
    <to variable="shellOpts"/>
    </copy>
    <copy>
    <from variable="inputVariable" part="payload"
    query="/client:Call_ScriptProcessRequest/client:cmd"/>
    <to variable="cmd"/>
    </copy>
    <copy>
    <from variable="inputVariable" part="payload"
    query="/client:Call_ScriptProcessRequest/client:cmdArgs"/>
    <to variable="cmdArgs"/>
    </copy>
    <copy>
    <from expression='"Initialize"'/>
    <to variable="commandOutput_external"/>
    </copy>
    </assign>
    <bpelx:exec import="java.io.InputStreamReader"/>
    <bpelx:exec import="java.io.BufferedReader"/>
    <bpelx:exec import="java.io.IOException"/>
    <bpelx:exec name="Call_Script" language="java" version="1.3">
    <![CDATA[/*Write your java code below e.g.                     
         System.out.println("Hello, World");                    
    addAuditTrailEntry("Initializing Strings");             
    String shell = (String)getVariableData("shell");                   
    String shellOpts = (String)getVariableData("shellOpts");                   
    String cmd = (String)getVariableData("cmd");                   
    String cmdArgs = (String)getVariableData("cmdArgs");                   
    String[] cmdString = { shell, shellOpts, cmd, cmdArgs };
    addAuditTrailEntry("Command String = " + cmdString[0] + " " + cmdString[1] +
    " " + cmdString[2] + " " + cmdString[3]);
    int[] retCode = {1};
    String commandOutput = null;
    try {                      
    Process p = Runtime.getRuntime().exec(cmdString);
    BufferedReader pOutput =
    new BufferedReader(new InputStreamReader(p.getInputStream()));
    String line;
    StringBuffer tmpCommandOutput = new StringBuffer();
    try
    while ((line = pOutput.readLine()) != null)
    tmpCommandOutput.append(line).append("\n");
    commandOutput = tmpCommandOutput.toString();
    addAuditTrailEntry("commandOutput: " + commandOutput);
    setVariableData("commandOutput_external",commandOutput);
    catch (IOException e) {            
    addAuditTrailEntry("had problem with string buffer: " + e);
    p.waitFor(); retCode[0] = p.exitValue(); pOutput.close();
    catch (IOException e) {            
    addAuditTrailEntry("had problem running command: " + e);
    catch (InterruptedException e) { addAuditTrailEntry(e); }
    catch (Exception e) { addAuditTrailEntry(e); }]]>
    </bpelx:exec>
    <bpelx:exec import="java.io.FileInputStream"/>
    <assign name="Return_Output">
    <copy>
    <from variable="commandOutput_external"/>
    <to variable="outputVariable" part="payload"
    query="/client:Call_ScriptProcessResponse/client:commandOutput"/>
    </copy>
    </assign>
    <reply name="replyOutput" partnerLink="client" portType="client:Call_Script"
    operation="process" variable="outputVariable"/>
    </sequence>
    </process>

    Try this....
    Process p = Runtime.getRuntime().exec("sh");
    java.io.BufferedWriter bw = new java.io.BufferedWriter(new java.io.OutputStreamWriter(p.getOutputStream()));
    bw.write("script1");
    bw.flush();
    bw.close();

  • Problem running sudo command in script

    Hello,
    I try to run this script.
    #!/bin/bash
    sudo /bin/cat /dev/input/event1 >> /home/tom/.log/log.bin &
    The sudoers entry
    %users ALL= NOPASSWD: /bin/cat /dev/input/event1 >> /home/tom/.log/log.bin
    I get the following error!
    $ Passwort: sudo: pam_authenticate: Kommunikationsfehler
    Kommunikationsfehler = eng: communication error
    What's wrong with that?
    Thank you!
    clementis

    Sorry, for being not precise.
    I created the alias in .bashrc in my $home directory. In sudoers all users are allowed to key in this command without a passwort entry.
    I know how to autostart in xfce and so created an autostart entry but unfortunatly it doesn't work for my "special" command.
    What I did:
    1. I wrote a script (first post) and tried to autostart it in xfce. For that command I created an entry in sudoers in order to avoid enter root passwort. The script didn't start.
    Then...
    2. I created an autostart entry (deleted the first one - see point 1) and entered the whole command (cat .../event1 >> $home...) in the xfce autostart input window. The idea was to run the command directly and not through a script. But it didn't work.
    Therefore I tried to run alter the command to "bash cat .../event1 >> $home ...." Didn't work either.
    3. I also deleted the autostart entry no 2. and created the alias in .bashrc in my home directory. Now created a new autostart entry trying to start the alias. Didn't work.
    I also tried to set the Terminal option in the file $home/.config/autostart/log.desktop to "true".
    So it looked like this:
    [Desktop Entry]
    Encoding=UTF-8
    Version=0.9.4
    Type=Application
    Name=log
    Comment=event1
    Exec= sudo cat /dev/input/event1 >> /home/tom/.cblog/log.bin &
    StartupNotify=false
    Terminal=true
    Hidden=false
    The alias for example works well if I enter it in xterm.
    So, I don't know why it isn't working! :-(
    Thank you for any help
    Clementis

  • Problem with shell commands and scripts from an Applescript Application

    Hi-
    I am fairly new to OSX software development. I am trying to build an application that creates a reverse SSH tunnel to my computer and starts OSXvnc. The idea is that my Mom or anyone else who needs help can connect to me without having to tinker with their firewalls.
    There are plenty of resources on how to do this, and I have found them. What I have a problem with is the following.
    I am building this application in Xcode as an Applescript application, because Applescript and shell scripting are the only forms of programming I know. I use an expect script to connect through SSH, and a "do shell script" for the raw OSXvnc-server application to allow screen sharing.
    The problem is that when I click on the button to launch OSXvnc-server or the button to launch SSH, the application freezes until the process it spawns is killed or finishes. For example, I can set SSH to timeout after 60 seconds of no connection, and then the Applescript application responds again. I even tried using the ssh -f command to fork the process, but that doesn't seem to help.
    I am also using "try" around each of the items.
    What am I doing wrong? How can I make the buttons in my app launch SSH and OSXvnc-server without hanging the application while it waits for them to finish?
    Thanks so much!

    See here for an explanation of the syntax.
    (20960)

  • Mutt: run shell command on folder change?

    hello all,
    i am using folder hooks in mutt and i have a program that counts my new mails and sends me a notification. i want to run this program every time i change folders.
    any suggestions how i could do this? backtics didn't work for me (maybe i was doing it wrong) because they only ran when mutt started.
    right now i have a macro bound to the command, but this is not ideal.
    thanks in advance for all help.

    Just tried a few things, this seems to work for me:
    macro index <f3> <change-folder>/home/owain/Maildir<enter><shell-escape>notify-send\ foo<enter>
    macro browser <f3> <change-folder>/home/owain/Maildir<enter><shell-escape>notify-send\ foo<enter>

  • Running shell command from Java, but from Windows Schedule Task?

    I have a simple java program that will start a dos based program. The java program works great when I run it, but when I run it from the Windows Task Scheduler, the dox box that should pop up, does not. It is running because I can see it in the task manager but I can not see the command window.
    Any ideas how to show the command window from a java application that is ran from Windows Task Scheduler?
    Example program below. Runs fine by itself, should get a dos popup that issues the directory command, run it from the scheduler and it does not show the dos box. You can however see it in the Processes as CMD.exe.
    import java.io.IOException;
    public class Test {
          * @param args
         public static void main(String[] args) {
              try {
                   Runtime.getRuntime().exec("cmd /k start dir");
              } catch (IOException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
    }Now the my real program is quite a bit more complicated. It actually goes out and checks the status of an Oracle Database, if all the tablespaces are online, then the middle tier application is allowed to start. The middle tier application is started by my java application, and is comes up with a dos console which shows status and users connected to the database.

    Jag,
    Actually, the question of whether it works for me seems to depend on the version of the OS (or Oracle). On RedHat Linux (Oracle 8.1.6) it didn't work at all, but on Solaris (Oracle 9.0.2) it did. Here's the output from that run:
    SQL> /
    output of the command run:
    init.ora
    initDBPart9i.DBPSun01.ora
    initdw.ora
    lkDBPART9I
    orapw
    orapwDBPart9i
    spfileDBPart9i.ora
    Done
    PL/SQL procedure successfully completed.
    But, I did need to change a line of your code to this:
    Process p = Runtime.getRuntime().exec("/usr/bin/ls");
    your original was:
    Process p = Runtime.getRuntime().exec("ls");
    You might consider, if possible, use of some of the Java File classes instead of ls, as this might make things more predictable for you. There were some examples in oramag.com a few months ago, but they were pretty simple (you might not need them).
    Hope this helps,
    -Dan
    http://www.compuware.com/products/devpartner/db/oracle_debug.htm
    Debug PL/SQL and Java in the Oracle Database

  • Problem sending shell command

    I have a file from a software vendor that I need to send to all my clients that will remove all the vendor's files. It is a .command file and says it is a TerminalShellScript. I used ARD to copy the file to the clients' Shared folder. I then used the Send UNIX command to send the following
    sh script /Users/Shared/FileName.command
    I get an error back that ARD cannot execute the binary file. What am I doing wrong?
    Also, once the file runs on the client, I believe it will ask for the admin password. Is there a way to prompt the computer to do this or am I going to need to take control of each computer to do this?
    Thanks!

    Have you tried copying the contents of your .command file into the big text box in the Send UNIX Command window? I would recommend you run it as the "root" user if the script is doing anything that needs additional privileges (you can't send a password to a "sudo" call in a "Send UNIX Command" job, so just use "root" and it won't prompt for a password).

  • Shell commands in applescript noob

    Hi all this is my first post in these forums and I come seeking help with a certain script I'm writing for my current college job. The purpose of the script is to install creative cloud from a server and this is as far as I've got. First I can get as far as setting the correct directory in the server by doing:
    do script "cd /Volumes/applications/Mac/'Adobe Creative Cloud'/'Enterprise - enduser'/Build"
    now when I press run the terminal screen pops up just fine with no errors in the right directory. However I've been reading up that to do other commands in the same shell I must do do shell script. When doing this however terminal doesn't do...anything. The reason why I was trying this is because my next command would be initiating the install which is the command:
    "installer -verbose -pkg 'enterprise_Install.pkg' -target /" with adminitrator privilages
    Now my question is how would formulate this within applescript? Thanks.

    do shell script "cd /Volumes/applications/Mac/'Adobe Creative Cloud'/'Enterprise - enduser'/Build ;  installer -verbose -pkg 'enterprise_Install.pkg' -target / with administrator privilages"
    You got the double quote in the wrong place.
    do shell script "cd /Volumes/applications/Mac/'Adobe Creative Cloud'/'Enterprise - enduser'/Build ;  installer -verbose -pkg 'enterprise_Install.pkg' -target / " with administrator privilages
    It is easier to diagnose problems with debug information. I suggest adding log statements to your script to see what is going on.  Here is an example.
        Author: rccharles
        For testing, run in the Script Editor.
          1) Click on the Event Log tab to see the output from the log statement
          2) Click on Run
        For running shell commands see:
        http://developer.apple.com/mac/library/technotes/tn2002/tn2065.html
    on run
        -- Write a message into the event log.
        log "  --- Starting on " & ((current date) as string) & " --- "
        --  debug lines
        set unixDesktopPath to POSIX path of "/System/Library/User Template/"
        log "unixDesktopPath = " & unixDesktopPath
        set quotedUnixDesktopPath to quoted form of unixDesktopPath
        log "quoted form is " & quotedUnixDesktopPath
        try
            set fromUnix to do shell script "sudo ls -l  " & quotedUnixDesktopPath with administrator privileges
            display dialog "ls -l of " & quotedUnixDesktopPath & return & fromUnix
        on error errMsg
            log "ls -l error..." & errMsg
        end try
    end run

  • Applescript for running sudo commands in terminal

    I'm a newbie when it comes to Applescript and was wondering if someone could help with a basic request. I need to write a small script to do the following:
    1. Launch terminal
    2. Run the 'Sudo -s' command
    3. Enter the administrator password (in plain text)
    and then
    4. run some sudo commands like "sudo defaults write /Library/Preferences/com.apple.loginwindow HiddenUsersList -array-add administrator"
    I actually WANT the administrator password to be in the script in plain text even though I understand the security risks (I will literally be the only person to ever see the script). I've trawled forums all over but can't seem to find what I am looking for and cannot get it working by patching together the various commands I have found. Thanks in advance for any help you can give!
    Sean

    I've included two examples.  The preferred way & the hacker way.
    with administrator
    It is easier to diagnose problems with debug information. I suggest adding log statements to your script to see what is going on.  Here is an example.
        Author: rccharles
        For testing, run in the Script Editor.
          1) Click on the Event Log tab to see the output from the log statement
          2) Click on Run
        For running shell commands see:
        http://developer.apple.com/mac/library/technotes/tn2002/tn2065.html
    on run
        -- Write a message into the event log.
        log "  --- Starting on " & ((current date) as string) & " --- "
        --  debug lines
        set unixDesktopPath to POSIX path of "/System/Library/User Template/"
        log "unixDesktopPath = " & unixDesktopPath
        set quotedUnixDesktopPath to quoted form of unixDesktopPath
        log "quoted form is " & quotedUnixDesktopPath
        try
            set fromUnix to do shell script "sudo ls -l  " & quotedUnixDesktopPath with administrator privileges
            display dialog "ls -l of " & quotedUnixDesktopPath & return & fromUnix
        on error errMsg
            log "ls -l error..." & errMsg
        end try
    end run
    This version has an inline password.
    Notice the echo 'password' |
    The single quotes are no accident.
    It is easier to diagnose problems with debug information. I suggest adding log statements to your script to see what is going on.  Here is an example.
        Author: rccharles
        For testing, run in the Script Editor.
          1) Click on the Event Log tab to see the output from the log statement
          2) Click on Run
        For running shell commands see:
        http://developer.apple.com/mac/library/technotes/tn2002/tn2065.html
    on run
        -- Write a message into the event log.
        log "  --- Starting on " & ((current date) as string) & " --- "
        --  debug lines
        set unixDesktopPath to POSIX path of "/System/Library/User Template/"
        log "unixDesktopPath = " & unixDesktopPath
        set quotedUnixDesktopPath to quoted form of unixDesktopPath
        log "quoted form is " & quotedUnixDesktopPath
        try
            set fromUnix to do shell script "echo 'password' | sudo ls -l  " & quotedUnixDesktopPath
            display dialog "ls -l of " & quotedUnixDesktopPath & return & fromUnix
        on error errMsg
            log "ls -l error..." & errMsg
        end try
    end run

  • Shell command authorization

    Hi all
    I am having a problem with Shell Command Authorization. I have a user setup who I only want to be able to display the config, this is for automated config archival on an hourly basis.
    I have configuered the device with the following aaa commands:
    aaa new-model
    aaa group server tacacs+ ACS
    aaa authentication login default group ACS
    aaa authentication login NOAUTH none
    aaa authorization config-commands
    aaa authorization exec default group tacacs+ group ACS
    aaa authorization exec NOAUTH none
    aaa authorization commands 15 default group ACS
    aaa authorization commands 15 NOAUTH none
    aaa accounting commands 15 default start-stop group ACS
    The static account I have configured logs in ok and can show config etc. Access to conf t is disabled which is good but for some reason he can do any show command instead of just show run which is all I have allowed in the Shell command authorization.
    Unmatched commands is set to deny and permit unmatched arguements is unchecked.
    ACS is 3.3(2) and the switch I am testing is running 12.1(9)EA1
    Any ideas?

    Most "show" command are level 1 commands. You can verify this by logging in as a normal user, issue a "sho priv" to ensure you're at level 1, and then type "sho ip route", "sho ver", etc, you'll see that all of them work fine.
    Your AAA commands only tell the switch to authorize level 15 commands, so when you do a "sho ver" or the like this command will not be sent off to the ACS server for authorization.
    If you add the following:
    aaa authorization commands 1 default group ACS
    then that shoud fix it, but be careful because it's easy to lock yourself out of being able to get into enable mode (add "enable" into your command set too).
    You should also have noticed that all those "show" commands weren't being accounted either, because you have also only enabled accounting for level 15 commands.

  • Shell Commands not found error when running application

    Hello,
    Im using MonoDevelop IDE in my Mac, before it used to work fine but after few days, now when I'm opening the application nothing happens., i checked the Console  for the log and it says this
    May  9 21:29:39 Sri-Vishnu-Totakuras-MacBook-Pro [0x0-0x52052].com.ximian.monodevelop[1510]: /Applications/MonoDevelop.app/Contents/MacOS/monodevelop: line 17: dirname: command not found 
    May  9 21:29:39 Sri-Vishnu-Totakuras-MacBook-Pro [0x0-0x52052].com.ximian.monodevelop[1510]: /Applications/MonoDevelop.app/Contents/MacOS/monodevelop: line 31: //mono-version-check: No such file or directory
    May  9 21:29:39 Sri-Vishnu-Totakuras-MacBook-Pro com.apple.launchd.peruser.501[599] ([0x0-0x52052].com.ximian.monodevelop[1510]): Exited with code: 1
    I thought may be some error with the "dirname" command, so i commented it in the code and gave the path of directory myself and then the console shows up like this.
    May  9 21:34:12 Sri-Vishnu-Totakuras-MacBook-Pro [0x0-0x56056].com.ximian.monodevelop[1532]: /Applications/MonoDevelop.app/Contents/MacOS//mono-version-check: line 19: grep: command not found 
    May  9 21:34:12 Sri-Vishnu-Totakuras-MacBook-Pro [0x0-0x56056].com.ximian.monodevelop[1532]: /Applications/MonoDevelop.app/Contents/MacOS//mono-version-check: line 19: cut: command not found
    May  9 21:34:12 Sri-Vishnu-Totakuras-MacBook-Pro [0x0-0x56056].com.ximian.monodevelop[1532]: /Applications/MonoDevelop.app/Contents/MacOS//mono-version-check: line 20: cut: command not found
    May  9 21:34:12 Sri-Vishnu-Totakuras-MacBook-Pro [0x0-0x56056].com.ximian.monodevelop[1532]: /Applications/MonoDevelop.app/Contents/MacOS//mono-version-check: line 21: cut: command not found
    May  9 21:34:12 Sri-Vishnu-Totakuras-MacBook-Pro [0x0-0x56056].com.ximian.monodevelop[1532]: /Applications/MonoDevelop.app/Contents/MacOS//mono-version-check: line 22: cut: command not found
    May  9 21:34:12 Sri-Vishnu-Totakuras-MacBook-Pro [0x0-0x56056].com.ximian.monodevelop[1532]: /Applications/MonoDevelop.app/Contents/MacOS//mono-version-check: line 31: osascript: command not found
    May  9 21:34:12 Sri-Vishnu-Totakuras-MacBook-Pro [0x0-0x56056].com.ximian.monodevelop[1532]: Cannot launch MonoDevelop
    May  9 21:34:12 Sri-Vishnu-Totakuras-MacBook-Pro [0x0-0x56056].com.ximian.monodevelop[1532]: MonoDevelop requires the Mono Framework version 2.10.4 or later.
    May  9 21:34:12 Sri-Vishnu-Totakuras-MacBook-Pro com.apple.launchd.peruser.501[599] ([0x0-0x56056].com.ximian.monodevelop[1532]): Exited with code: 1
    I opened the contents of the application and run the shell script for opening aplication there it worked very fine and application started working.. But if i open application directly through launchpad or finder it doesnt show up and console
    I tried running those commands in the terminal directly there they work.. But dunno whats wrong in here. and even if try to open the application through the terminal it all opens fine.. what could be the possible problem, is it with my mac..?

    i finally figured out the problem.. it is with the environmental variables.  the path for all those commands like "grep" is not being set for the GUI applications.  that is why i got that error. 
    for those GUI applications which require path, we have to set path in the file /etc/launchd.conf  the environmental variables set in here are used by the gui applications and those which are launched through spotlight.
    that file may bot be present in most of the macs. No problem even if not present,we can create one and use.
    so  type in terminal
              $ sudo vi /etc/launchd.conf     
    and in the editor add these lines
              setenv PATH = /new/path
    and save.  Note: replace /new/path with the path which you need to have for the commands used in the script.
    remeber that you need to restart your mac for applications to use these environmental variables.

Maybe you are looking for