Running a command in Linux

Hi expert,

I wrote this java class, it works on Windows, but not Linux.

Seems not to run the code you have any idea why?

(1) you provide a userlogin
(2) check if the userlogin file exists
(3) otherwise it create a file whose name and content would be the userlogin.

for example, you provide 'John', and it will create/home/oracle/JOHN that contains the string 'JOHN '.


Thank you

import java.io.*;

public class RemoteScript {
     static String mDirectoryPath = "/home/oracle/";
     static String mCompleted = "COMPLETED";
     static String mError = "ERROR";
     
     private static boolean checkFile(String pFileName) {
          File f = new File(pFileName);
          return (f.exists() ? true : false);
     }
     
     private static boolean execute(String pInstruction) {
          boolean oResult=false;
          int exitVal = -1;
          try {
               Runtime rt = Runtime.getRuntime();
               Process proc = rt.exec(pInstruction);
               BufferedReader br = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
               String line;
               while ((line = br.readLine()) != null) {
                    System.out.println(line);
               }
               exitVal = proc.waitFor();
               if(exitVal==0)
                    oResult=true;
               } catch (Throwable t) {
                    t.printStackTrace();
               }
          return oResult;
     }
     
     public static String createUser(String pLogin) {
          String oFileName = mDirectoryPath + pLogin.toUpperCase();
          if (!checkFile(oFileName)) {
               String oInstruction = "/bin/echo " + pLogin.toUpperCase() + " > "+ oFileName;
               execute(oInstruction);
               if (checkFile(oFileName)){
                    return mCompleted;
               }
               else{
                    return mError + ".NT";
               }
          } else
               return mError + ".EX";
     }
     
     public static void main(String[] args) {
          createUser("SAMPLEUSER");
     }
}
Published by: sabre150 on February 21, 2012 17:06
Moderator action: {code} tags added

I don't understand how this code can work under windows but...

You have a fundamental misunderstanding. Under Linux the ">" operator must be interpreted by a shell. This means that you must use the version of the table of Runtime.exec () and make your order

           String[] oInstruction = {"bash", "-c","/bin/echo " + pLogin.toUpperCase() + " > " + oFileName};

Replace your execute() method to get the signature

   private static boolean execute(String[] pInstruction)

You manage also not "stderr" process flow at all. You should read http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html and apply ALL the recommendations. Otherwise you can cause a significant loss of hair.

P.S. I used 'bash' but you are free to use any shell you want, but make sure you read the appropriate shell manual page.

Published by: sabre150 on February 21, 2012 17:23

Tags: Java

Similar Questions

  • Run the emca in linux shell script command

    Hello everyone,
    I would like to launch emca to create dbconsole in my Production database, so I have to run this command in the script, because this command causes the base of data either in passive mode.
    my gaze of script like:
    #/ bin/sh
    Su - oraprod-c"sh /oraprod/db/tech_st/10.2.0/bin/emca - config dbcontrol db-rest create" > > /backora/log.log "

    but the problem is how to interact with this command (provide the parameters of database SID, Port of the database, sys password...)

    And the MAIL_SERVER_NAME too. But using "" can do the trick.

    Eric

  • Run the command in the comments - vRO options?

    Hi, I am currently using vRo to run a script simple powercli with 'invoke-vmscript"to run a command at a prompt linux once it is supplied of vRA (it changes the hosts file). I'm looking for another method to do this, if someone could share their experience please.

    I thought to SSH could help, but I am dependent on having an IP address or the host name when I run the workflow. That is not the case that I need to wait for it to start, get address DHCP and save DNS.

    Does anyone have any suggestions how I could achieve? The PowerCLI works because I can do the name of the computer that went from vRA. However, the script does not work very cleanly and I would find that an alternative with vRO is possible.

    Thanks in advance for any advice

    Steve

    No problem

    Yes, you can easily run these commands with the vRO workflow.

    When you log on to your linux VM you can use the command "which" where the "command/program' is you want to run, so

    "what echo" showing you the executable you call is "/ bin/echo", while passwd is on centos for example "/ usr/bin/passwd.

    Tim

  • Error running start_collector command

    Hi all

    I get this error when starting manifold DBAUD with the command start_collector avctl

    [oracle@auditvaultsrv ~] $ avctl start_collector collname - DBAUD_Collector - SrcName orcl
    Starting manifold...
    Error running start_collector command
    Internal error
    [oracle@auditvaultsrv ~] $


    I tried my level better thought solution the forum without clear solution
    I installed Audit Vault Server under Linux and set up in Oracle Data Source in the Windows collection Agent.
    The agent works well. The problem is when I start fundraisers.

    Here are the contents of the avca.log file
    *******************************************************
    02/09/13 07:36:15 command, - collname, DBAUD_Collector - start_collector, SrcName, orcl
    02/09/13 07:36:15 departure collector...
    02/09/13 07:36:18 start_collector command error
    Internal error
    at oracle.av.common.AuditException.toAuditException(AuditException.java:253)
    at oracle.av.management.impl.HttpManagementAdaptor.getData(HttpManagementAdaptor.java:259)
    at oracle.av.management.impl.HttpManagementAdaptor.getData(HttpManagementAdaptor.java:291)
    at oracle.av.management.impl.HttpManagementAdaptor.startCollector(HttpManagementAdaptor.java:434)
    at oracle.av.management.impl.ManagementServiceImpl.startCollector(ManagementServiceImpl.java:651)
    at oracle.av.management.impl.ManagementServiceImpl.startCollector(ManagementServiceImpl.java:696)
    at oracle.av.management.impl.ManagementServiceImpl.startCollector(ManagementServiceImpl.java:707)
    at oracle.av.avca.control.StartCollectorTask.executeTask(StartCollectorTask.java:82)
    at oracle.av.avca.backend.BaseTask.execute(BaseTask.java:104)
    at oracle.av.avca.Avctl.startCTL(Avctl.java:180)
    at oracle.av.avca.Avctl.main(Avctl.java:213)
    Nested exception:
    java.sql.SQLException: ORA-12578: TNS:wallet open failed
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0 (Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:501)
    at oracle.av.common.AuditException.toAuditException(AuditException.java:250)
    at oracle.av.management.impl.HttpManagementAdaptor.getData(HttpManagementAdaptor.java:259)
    at oracle.av.management.impl.HttpManagementAdaptor.getData(HttpManagementAdaptor.java:291)
    at oracle.av.management.impl.HttpManagementAdaptor.startCollector(HttpManagementAdaptor.java:434)
    at oracle.av.management.impl.ManagementServiceImpl.startCollector(ManagementServiceImpl.java:651)
    at oracle.av.management.impl.ManagementServiceImpl.startCollector(ManagementServiceImpl.java:696)
    at oracle.av.management.impl.ManagementServiceImpl.startCollector(ManagementServiceImpl.java:707)
    at oracle.av.avca.control.StartCollectorTask.executeTask(StartCollectorTask.java:82)
    at oracle.av.avca.backend.BaseTask.execute(BaseTask.java:104)
    at oracle.av.avca.Avctl.startCTL(Avctl.java:180)
    at oracle.av.avca.Avctl.main(Avctl.java:213)


    I do not know how to solve this ORA-12578: open TNS:wallet has not appeared in the newspaper. I hope that this will make the command works
    Any kind of help will be appreciated

    Concerning


    Sadik

    Finally, I got the solution on this site Oracle Audit Vault | Iain Barr

    This problem is solved by granting full control to the administrators for each of the 2 files in the folder $ORACLE_HOME\network\admin\avwallet : cwallet.sso and ewallet.p12. These grants must be made at any time from the setup avorcldb command (or the equivalent for other databases) is running

  • I can't use the oracle11g adrci to run a command

    TITLE:
    -------------------------------------------------------------------------------------------------
    I can't use the oracle11g adrci to run a command

    ENV:
    -------------------------------------------------------------------------------------------------
    oracle11g production (version 11.2.0.1.0 version of Red Hat Enterprise Linux AS 4 x86_64)

    The snapshot command
    -------------------------------------------------------------------------------------------------
    adrci > view home
    Houses of ADR:
    diag/rdbms/orcl/orcl
    adrci > see command
    DIA-48101: error occurred when attempting to read a file [block] [opt/oracle/diag/rdbms/orcl/orcl/metadata/ADR_CONTROL.ams] [0]
    DIA-27072: Message not found 27072. product = RDBMS. installation = DIA
    Linux error: 22: invalid argument
    Additional information: 4
    Additional information: 1
    Additional information:-1

    adrci > problem

    Home of ADR = / opt/oracle/diag/rdbms/orcl/orcl:
    *************************************************************************
    0 rows read

    adrci > view report hm_run hm_run_1
    DIA-48101: error occurred when attempting to read a file [block] [opt/oracle/diag/rdbms/orcl/orcl/metadata/HM_RUN.ams] [0]
    DIA-27072: Message not found 27072. product = RDBMS. installation = DIA
    Linux error: 22: invalid argument
    Additional information: 4
    Additional information: 1
    Additional information:-1

    Published by: user649619 on January 23, 2010 04:46

    user649619 wrote:
    TITLE:
    -------------------------------------------------------------------------------------------------
    I can't use the oracle11g adrci to run a command

    ENV:
    -------------------------------------------------------------------------------------------------
    oracle11g production (Release Red Hat Enterprise Linux AS release 4 x86_64 11.2.0.1.0)

    The snapshot command
    -------------------------------------------------------------------------------------------------
    adrci > view home
    Houses of ADR:
    diag/rdbms/orcl/orcl
    adrci > show control
    DIA-48101: error occurred when attempting to read a file [block] [opt/oracle/diag/rdbms/orcl/orcl/metadata/ADR_CONTROL.ams] [0]
    DIA-27072: Message not found 27072. product = RDBMS. installation = DIA
    Linux error: 22: invalid argument
    Additional information: 4
    Additional information: 1
    Additional information:-1

    adrci > show problem

    Home of ADR = / opt/oracle/diag/rdbms/orcl/orcl:
    *************************************************************************
    0 rows read

    adrci > show report hm_run hm_run_1
    DIA-48101: error occurred when attempting to read a file [block] [opt/oracle/diag/rdbms/orcl/orcl/metadata/HM_RUN.ams] [0]
    DIA-27072: Message not found 27072. product = RDBMS. installation = DIA
    Linux error: 22: invalid argument
    Additional information: 4
    Additional information: 1
    Additional information:-1

    Published by: user649619 on January 23, 2010 04:46

    DIA-48101: error occurred when attempting to read a file [%s] [s] [%s]
    Cause: There was an error when you try to play a file with file ADR interface.
    Action: Check the arguments specified in the playback interface.

    >

    HTH
    Aman...

  • How to start the Audit Vault (Please run this command at the Vault review officer)

    Hi all.
    I just finished to complete a facility audit Vault on a dev linux system and all processes were available.

    In any case I had to restart my linux machine, but no process started automatically :(

    I'm reading how to start 'something'... by the use of the (e13841.pdf) Administrator's Guide...
    but without results...
    I don't know (I want to say I still have not found in the doc) sequences correct to start and stop services... when start the database... If there is a command to automatically audit Vault start the database...

    I tried...
    [oracle@auditvault ~] $ avctl show_oc4j_status
    AVCTL began
    Please run this command at the verification officer Vault.
    Leaving the control Audit Vault
    [oracle@auditvault ~] $ avctl start_oc4j
    AVCTL began
    Please run this command at the verification officer Vault.
    Leaving the control Audit Vault

    Thanks for your help

    Here are some actions you need to perform:

    Audit Vault Server you installed in your machine in ORACLE_HOME1
    You have installed Audit Vault Agent in your machine in ORACLE_HOME2

    1 / your database from ORACLE_HOME1

    export ORACLE_SID = yoursid
    sqlplus / as sysdba<>
    startup
    output
    EXPRESSIONS OF FOLKLORE

    2 / the AV from ORACLE_HOME1 Server

    avctl start_av

    3 / the agent runtime from ORACLE_HOME2 AV

    avctl start_oc4j

    4 / your agent from ORACLE_HOME1

    avctl start_agent - nom_agent

    At this point, you should be able to start any collector that you created previously. Be in command line mode, ORACLE_HOME1, or through the web console...

    Yves

    Published by: yves77 on May 14, 2009 19:21

  • Run the command in Start menu show sites and other files that I opened.

    I was typing letters in the menu run from the start menu ("Start" > "run" > "a, b, c, d, e, f, g, etc...) and I noticed that the Web sites I visited were stored there. This information is accessible by hackers or other intruders unwanted? I was checking to see if I could find my e: drive using the command run from the start menu when I noticed similar entries in the recent documents folder from the start menu. I forgot this shortcut in the past and by chance came across it accidentally. How to delete these lists. I've seen websites that need my e-mail and password. even if she had a lot of jibberish, some words were read by me at a superficial glance. What is a security breach? example: if I type only (a), then all files and websites beginning with a are displayed

    Hi Marc,

    Welcome to the Microsoft Community Forums.

    According to the description, it seems that you are facing problems in removing the story from the beginning, run the command. I'll be happy to help you in this problem.

    -What operating system is installed on your computer?

    Windows saves a history of the names of files, programs, and locations that you type in the Run dialog box. You can delete this history, which you can do if you use a public or shared computer.

    I suggest you follow the steps in the link to clear the history run in the start menu and check if it helps.

    Clear history run on the start menu

    http://Windows.Microsoft.com/en-us/Windows7/clear-the-run-history-on-the-start-menu

    I hope it helps. If you have any questions about Windows in the future, please let us know. We will be happy to help you.

  • Task Manager, regedit, run and command prompt are all disabled on my computer.

    Task Manager, regedit, run and command prompt are all disabled on my computer.  Is it possible to fix it because it allows to launch on a network?

    Hello
     
    (1) have tried to start in Safe Mode, Mode safe with network...?
    (2) remember to make changes to the computer before the question?
     
    See the methods mentioned below and check if that helps.
     
    Method 1:
     
    Scan your computer for Microsoft Safety Scanner, it will help us to get rid of viruses, spyware and other malicious software.

    The Microsoft Security Scanner is a downloadable security tool for free which allows analysis at the application and helps remove viruses, spyware and other malware. It works with your current antivirus software.

    http://www.Microsoft.com/security/scanner/en-us/default.aspx

    Note: The Microsoft Safety Scanner ends 10 days after being downloaded. To restart a scan with the latest definitions of anti-malware, download and run the Microsoft Safety Scanner again.

    Note: The data files that are infected must be cleaned only by removing the file completely, which means that there is a risk of data loss.

     
    Method 2:
     
    See also:
    Hope this information helps.
  • How do you do the command prompt window stay open after running a command?

    OK, I feel stupid asking this, because I knew the answer before. I learn Visual C++ programming. The book I learn to write C++ and past then in details on the writing of the GUI from Visual C++ part. The book that I market me through compilation and to make an exe file in a cpp file, and then he said: go to the directory in Explorer and double click on the exe file. I do, and the command prompt appears a quick second before closing down. The example in the book shows the output, and the writer obviously has his guest configured to pause after executing an exe file.

    I just set up my guest to do the same thing, so I can at least see the results. I know that running the exe I wrote, but I would like to see the output for less than a second.

    I don't know how you code this. But if it's like a normal batch or whatever it is command line related.

    Follow these steps to use a switch defined by the user at the end of the script.

    To pause a file of DOS commands under Windows XP, continue to the next command, you can use the PAUSE command. Make request to the user with the text:

    Press any key to continue. . .

    Then the batch file is waiting for the user to press a button. However, if you want to pause a batch file and display anything? Simply redirect the results to no one as follows:

    pause > null

    Given that it is perhaps not very useful (how will the user know they need to press a key to continue the batch file?) you display a different prompt. Issue a command with your desired guest ECHO, and then issue the break preceding > no command.

    For example, to pause a batch file of Windows XP with the prompt "Press ENTER to run the command", use the following commands:

    echo press ENTER to run the command
    pause > null
    MCP. MCDST. LVL 80

  • Is it possible to run the command script with user account administrator rights?

    Is it possible to run the command script with administrator user account rights means please tell me how to...

    I need to run it in windows 7 professional service pack 1.

    There are a few myths that won't go away, for example

    • You can perform administrative tasks when you are working from a command prompt.
    • A script (batch file, VBScript, PowerShell) gives you administrative rights.

    There is no substance to a myth. Your account has administrator privileges, or it does not. There is no backdoor.

  • Runs the command "regsvr32 quartz.dll" shows 0 x 80040154 error and the laptop webcam does not work

    Runs the command "regsvr32 quartz.dll" shows 0 x 80040154 error and the laptop webcam does not work

    Hello

    Thank you for your response.

    I appreciate that you have attached a screenshot of the problem.

    Have you tried troubleshooting of hardware and devices running?

    Please refer to the suggestions of Naman R responded on 1 April 2011 and check if that helps.
    http://answers.Microsoft.com/en-us/Windows/Forum/Windows_7-windows_programs/DllRegisterServer-failed-with-error-code-0x8002801/403ee0d0-895B-E011-8dfc-68b599b31bf5

    Note: Serious problems can occur if you modify the registry incorrectly. Therefore, make sure that you proceed with caution. For added protection, back up the registry before you edit it. Then you can restore the registry if a problem occurs. For more information about how to back up and restore the registry, click on the number below to view the article in the Microsoft Knowledge Base:
    http://Windows.Microsoft.com/en-us/Windows/back-up-registry

    I hope this helps.

    Thank you

  • Installed dictionary software (babylon 8), but I saw this message: "error 0 runs the command setup32.exe. How to solve this problem?

    Original title: error setup32.exe

    Hello. Thank you for your reading this question.

    I was installing a software dictionary (babylon 8), but I saw this message: "error 0 runs the command setup32.exe. Can you help me to solve this problem?

    Moved Windows 7 installation, set at level and activate Forum.

    Hello

    I changed the windows of my laptop and the problem has been resolved.

    Thank you very much.

  • Runs the command msiexec/v carry out any action in Windows 7?

    Is any action run the command msiexec/v in a command window in Windows 7 64 bit?

    Is the command msiexec/v identical to msiexec.exe/v?

    That means / V for the msiexec command do?

    I was not aware that the cmd was available in win7, but returned to winxp

    http://support.Microsoft.com/kb/314881

  • How to disable the prompt 'more' when you run the command 'See logging' CLI

    Hello. I would like to know if there is a command that I can run to disable paging on my SF302 switch.

    Thus, for example, when I run the command 'See logging' on the CLI, I care about her return all results rather than ask me hit the SPACEBAR or enter.

    Is there a way to do this?

    Thanks in advance for your time and your consideration.

    J.L.

    command is

    terminal datadump

    -Tom
    Please evaluate the useful messages

  • How to run the command in Windows 7?

    Original title: HOW can I PUT to the TOP of THE COMMAND WINDOW TO INSTALL a PROGRAM IN WINDOWS 7 a LITTLE WI... UNDER XP, I WENT TO RUN AND OPEN NOCK THEN HE TYPED IN THE COMMAND

    INXP I COULD BRING UP THE LITTLE TH WINDOW TYPE IN THE INSTALLATION PROGRAM. EXE TO INSTALL THE PROGRAM I CAN T FIND THAT IN WINOWS 7

    As long as you are trying to run a 16-bit program on 64-bit Windows, then try either Windows key + R or click Start (or press the Windows key), and then simply type (or paste it into your order for the text box search programs and files ), then press on .

    If you think you really need to run window, you can add it by customizing the Start Menu. Right-click the Start button, and then select Properties. Click the Customize button at the top right.


    Figure 1.0 - Customize Start Menu dialog

    Scroll down about three quarters of the way down the list of options and place a check next to run the command. Click OK to save your changes and OK to save the Properties dialog box again.

    The familiar run command should be back on your Start menu in the menu on the right pane. The window run keep a history of previous orders drop.

    • "Have you tried it turned off then on again? '-'The IT Crowd' Roy (Emmy award-winning British comedy)

Maybe you are looking for