Execute process (shell script) under different user

Hi,
is it possible to use the ProcessBuilder oder .exec()-method to execute a shell script under a JVM-different user? I need to start shell scripts for different system users and I don't want to use SUDO or a wrapper script to switch to the required user. I would like to define the user at java level. Is this possible?
Best regards,
Thomas

looking for something like this too.
currently i am relying on a script in which i have to set the user as:
"su username -c java_program"
the problem with this approach is that if youre not running as root, then su asks for a password, thereby halting execution. (tried input redirects and here-docs, (some popular linux tricks), they did not work)
so you have to be root for the script option to work.
if anyone can suggest a more "java based" way of executing a process as a different user , thatll be awesome.

Similar Messages

  • DSC powershell xwindowsprocess to execute batch file under different user account

    DSC powershell run under "NT AUTHORITY\SYSTEM".
    I am trying to execute a batch file under different user account using xwindowsprocess in DSC resource kit.
    I created a custom dsc resource with 3 parameters namely Exepath, Arguments, Credential.
    I received those parameter values in settargetresource method.
    CallPInvoke
    [Source.NativeMethods]::CreateProcessAsUser(("$ExePath "+$Arguments), $Credential.GetNetworkCredential().Domain, $Credential.GetNetworkCredential().UserName, $Credential.GetNetworkCredential().Password)
    I tested it by invoking a batch file and writing username under which it executes to a text file.
    After executing, the output text file still contains the "Systemname$".

    Configuration Sample_xService_ServiceWithCredential
    param
    [string[]]
    $nodeName = 'localhost',
    [System.String]
    $Name,
    [System.String]
    [ValidateSet("Automatic", "Manual", "Disabled")]
    $StartupType="Automatic",
    [System.String]
    [ValidateSet("LocalSystem", "LocalService", "NetworkService")]
    $BuiltInAccount="LocalSystem",
    [System.Management.Automation.PSCredential]
    $Credential,
    [System.String]
    [ValidateSet("Running", "Stopped")]
    $State="Running",
    [System.String]
    [ValidateSet("Present", "Absent")]
    $Ensure="Present",
    [System.String]
    $Path,
    [System.String]
    $DisplayName,
    [System.String]
    $Description,
    [System.String[]]
    $Dependencies
    Import-DscResource -Name MSFT_xServiceResource -ModuleName xPSDesiredStateConfiguration
    Node $nodeName
    xService service
    Name = $Name
    DisplayName = $DisplayName
    Ensure = $Ensure
    Path = $Path
    StartupType = $StartupType
    Credential = $credential
    $Config = @{
    Allnodes = @(
    Nodename = "localhost"
    PSDSCAllowPlainTextPassword = $true
    #Sample Scenarios
    $credential = Get-Credential
    Sample_xService_ServiceWithCredential -ConfigurationData $Config -Name "Sample Service" -DisplayName "Sample Display Name" -Ensure "Present" -Path "C:\DSC\TestService.exe" -StartupType Automatic -Credential $credential
    ¯\_(ツ)_/¯

  • Executing a shell script from a java program

    Hi,
    I'm facing a problem while executing a shell script from a jsp page.
    I'm using exec() function.
    It's working fine for single statement scripts.But if the script consists of any database processing and some other processing statements,it's not returning the correct exit status of the process.
    Will u please help me in this.
    If there is any other ways to execute a shell script from a jsp page other than Runtime.exec().If so let me know.
    Thanks in advance.

    I think this shud workMaybe - but it is wrong! Why do you create aReader
    and then read bytes which are turned into a String
    without worrying about whether or not the bytes area
    String and without worrying about the character
    encoding if the bytes do represent characters and
    without worrying about how many bytes wereactually
    read.
    Also, both you and the OP should read, digest and
    follow the advice given in
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-
    traps.htmlI dont care if it is wrong. This code works for me.
    We are here to solve problems not to find which post
    is wrong.It is wrong! You are posting bad advice that is very wrong! It may work for you but it is wrong in general! WRONG WRONG WRONG.
    If you have a solution then post it I did post a solution! The reference I gave will explain to you and the OP exactly how it should be done.
    rather then
    posting rude comments.I was not rude! I was explaining just some of what was wrong!

  • Executing a shell script from a jsp page

    Hi,
    I'm facing a problem while executing a shell script from a jsp page.
    I'm using Runtime.exec() function.
    It's working fine for single statement scripts.But if the script consists of any database processing and some other processing statements,it's not returning the correct exit status of the process.
    Will u please help me in this.
    If there is any other ways to execute a shell script from a jsp page other than Runtime.exec() like RMI etc,.If so let me know.
    Thanks in advance.

    Hello,
    It's hard to help you but what you can do is listening to the outputs of your script, you should read the output stream and error stream and send them to the default console.
    Check this excellent article : http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html?page=4
    Best regards,
    Olivier.

  • Error while executing unix shell script from java program

    Hi All,
    I am trying to execute unix shell script from a java program using Runtime.execute() method by passing script name and additional arguments.
    Code snippet :
    Java Class :
    try{
         String fileName ="test.ksh";
         String argValue ="satish"; // value passed to the script
         String exeParam = "/usr/bin/ksh "+fileName+" "+argValue;
         Process proc = Runtime.getRuntime().exec(exeParam);
         int exitValue = proc.waitFor();
         sop("Exit Value  is : "+exitValue);
    catch(Exception e)
    e.printStackTrace();
    }Test.ksh
      export -- application realated paths..
      nohup  abc.exe 1> test.log 2>&1;
      $1
      exit.By running the above java class , i am getting exit Value: 139 and log file test.log of 0 bytes.
    when i am running the same command (/usr/bin/ksh test.ksh satish) manually, it's calling abc.exe file successfully
    and able generate the logs properly.
    Pls let us know where exactly i am stuck..
    Thanks in advance,
    Regards,
    Satish

    Hi Sabre,
    As per the guidelines provided by the article, i had done below changes..
    InputStream is = null;
    InputStreamReader iStreamReader = null;
    BufferedReader bReader = null;
    String line = null;
    try{
    String fileName ="test.ksh";
    String argValue ="satish"; // value passed to the script
    String exeParam = "/usr/bin/ksh "+fileName+" "+argValue;
    Process proc = Runtime.getRuntime().exec(exeParam);
    is = proc.getErrorStream();
    iStreamReader = new InputStreamReader(is);
    bReader = new BufferedReader(iStreamReader);
    System.out.println("<ERROR>");
    while((line = bReader.readLine()) != null)
    System.out.println("Error is : "+line);
    System.out.println("</ERROR>");
    int exitValue = proc.waitFor();
    sop("Exit Value is : "+exitValue);
    catch(Exception e)
    e.printStackTrace();
    Now , it's showing something like..
    <ERROR>
    </ERROR>

  • Is it possible to execute same eCATT  script in different SAP versions

    is it possible to execute same eCATT  script in different SAP versions?
    Regards,
    Sunil sankar B.
    [email protected]

    Yes. In the ecatt script you have the option under ATTRIBUTES --> VERISONING DATA you can restrict it to different software components and different releases.

  • Node Manager starting managed servers under different users

    Hi all,
    I have multiple domains running on the same server.
    Is it possible to get node manager to start managed servers from different domains under different users?
    Default is the user under which node manager was started originally.
    Thanks
    Arnaud

    Oracle documentation is still in confussion state for Unix platform nodemanager.
    NodeManager Admin Guide had chapter 3 for General configuration of nodemanger. Chapter 5 is for script based nodemanager.
    In chapter 5 there is clear way defined for " Starting a node manger for Unix machine".
    chapter 3 is mess there is clear-cut direction to reach the remote startup of servers.
    Why we have so many types of nodemanager for connect. howbout start them?
    Can someone expert in Oracle WebLogic please respond to this.
    *Nodemanagers are NOT meant for multiuser development env.
    They are defined for production env and for HA, FailOver.*
    Edited by: PavanBhavanishekhar on Jan 6, 2010 9:10 PM

  • Terminal is trying to auto-execute a shell script

    I can no longer use Terminal because every time I try to start it, it automatically runs a shell script I used to have on my desktop and then immediately says "[Process Completed]." I'm not sure how exactly I got it to do this... as far as I know all I did was execute the shell script by associating it with Terminal and double clicking it... but now I can't create a new shell without it automatically attempting to execute it. Please help!
    Thanks,
    Michael

    nevermind... found this http://www.starglider.net/MacOS_X/Terminal-ExecutionString.html
    Apparently I'm not the only one who's made this incredibly aggravating mistake

  • Executing a shell script with DBMS_SCHEDULER

    Hi,
    when I execute a shell script with DBMS_SCHEDULER this doesn't works correctly
    BEGIN
    DBMS_SCHEDULER.create_job
    job_name => 'job_AR',
    job_type => 'EXECUTABLE',
    job_action => '/home/crm/crmdw/AR/start_execution.sh',
    enabled => TRUE,
    start_date => systimestamp,
    repeat_interval => 'FREQ=MINUTELY;INTERVAL=15',
    comments => 'Test Job AR'
    END;Inside the shell script there is a code who call a Hierarchy of process,
    if I executed it manually or with a cron, it works perfectly
    but when I execute it with the job that I've described before it's executes
    all process at same time and it doesn't work.
    What can I do to fix the issue,
    any Ideas?
    Thanks in advanced...

    #!/usr/bin/ksh
    #test_dbms_scheduler.ksh
    echo $1
    echo "I am in Unix"
    exit 0
    chmod 755 test_dbms_scheduler.ksh
    Create or replace procedure test_dbms_scheduler
    as
    v_text varchar2(255) := 'Parameter passed from Oracle to Unix';
    Begin
    dbms_output.put_line("I am in Procedure");
    dbms_scheduler.create_job
    (job_name=>'test_dbms_scheduler',
    job_action=>'/usr/bin/test_dbms_scheduler.ksh',
    number_of_arguments=>1,
    job_type=>'executable',
    start_date => SYSDATE,
    repeat_interval => 'FREQ=SECONDLY; INTERVAL=1',
    enabled=>false,
    auto_drop => TRUE,
    comments=> 'Run shell-script test_dbms_scheduler.ksh');
    dbms_scheduler.set_job_argument_value(job_name =>'test_dbms_scheduler', argument_position => 1, argument_value => v_text);
    dbms_scheduler.enable('test_dbms_scheduler');
    dbms_output.put_line("I am back in Procedure");
    Exception
    when others then
    dbms_output.put_line(sqlcode||sqlerrm);
    end;
    set serveroutput on
    exec test_dbms_scheduler;

  • Executing Unix shell scripts with DBMS_SCHEDULER

    I have the following Unix shell script create_backup_file.sh:
    #!/usr/bin/ksh
    /usr/bin/ssh [email protected] /usr/bin/touch/app_home/home/trotestbat/scripts/TRO_batch_complete_`date +%d-%m-%Y-%H%M`
    If I execute this from the command prompt it creates the file on the remote server.
    I've used dbms_scheduler to try and execute this from Oracle:
    BEGIN
    SYS.DBMS_SCHEDULER.CREATE_PROGRAM
    program_name => 'CREATE_TRO_BACKUP_FILE'
    ,program_type => 'EXECUTABLE'
    ,program_action => '/APP/TORPEDO/DTE/SCRIPTS/create_backup_file_tro.sh'
    ,number_of_arguments => 0
    ,enabled => TRUE
    ,comments => NULL
    SYS.DBMS_SCHEDULER.CREATE_JOB
    job_name => 'DTE.TESTAGAIN'
    ,start_date => TO_TIMESTAMP_TZ('2010/05/17 16:09:24.710789 +01:00','yyyy/mm/dd
    hh24:mi:ss.ff tzh:tzm')
    ,repeat_interval => NULL
    ,end_date => NULL
    ,program_name => 'DTE.CREATE_TRO_BACKUP_FILE'
    ,comments => NULL
    END;
    The problem I have is that scheduler executes the shell script and creates the file but it never completes the job. The status of the job is permanently 'RUNNING'. Why is the scheduler not returning a completed status?

    the "infinite" script is usually caused by a prompt (script pauses for a user input).
    Please keep in mind that executing script via scheduler is not the same as manually via prompt.
    1. the script runs as ORACLE user ID (or whatever you specified using DBMS_SCHEDULER.create_credential or/and "$ORACLE_HOME/rdbms/admin/externaljob.ora")
    2. the environment variables are probably not the same.
    My wild guess is that you never ran SSH using "oracle" UID and thus it prompts for permission to add the remote computer’s fingerprint to the user’s ~/.ssh/known_hosts file - since it is a script, it just hangs and waits for input.
    Did you try to login to unix box as oracle uid and run the script manually?

  • CSS 11500 - Keepalive script to remotely execute a shell script on a server

    Hi!
    I've been trying to connect the dots but so far I've got nothing close to what I need - based on Cisco's documentation.
    I was wondering if it was possible for the CSS switch to connect to a server in order to execute a shell script such as "/opt/whatever/script.sh", which would return a specific value like "OK". Anything different than OK would mean a dead service, and the affected service would be taken out of business (no load balancing play).
    Could someone confirm whether it can be done?
    Many thanks!!
    Leo

    Leo,
    you could try to use CSS script to telnet to the server, and execute the command.
    But that would be ugly.
    What you should do, is put your script inside a cgi webpage and let the CSS call the webpage.
    Your webserver will then run the script that you want and return to result inside and HTML page to the CSS which can then decide on the status of the server.
    If you do not have a web server, you should create a small tcp server to listen to CSS request and again send the result of the script back to css.
    Gilles.

  • Privilege problem on DBMS_SCHEDULER  execute linux shell script

    Hello, everybody,
    I'm a beginner on oracle development , recently , I use DBMS_SCHEDULER to execute linux shell script so that I can transmit files to another ftp server . The problem is , I can't use ordinary user to execute this shell ,but must use sys user , or the procedure will show error : Permission Denied;
    I can't change the files' privillege that need to transmit.
    I had tried these method,but no use:
    1. grant all privillege to user;
    2. change the privillege of shell and it's direcotry;
    3. use full path in shell;
    I hope someone could help me solve this problem , thank you!
    the error code :
    STANDARD_ERROR="ftp: local: test20121221173852: Permission denied
    ftp: local: test20121221173953: Permission denied
    ftp: local: test20121221174052: Permission denied
    ftp: local: test20121221174153: Permission denied"

    My /tmp/test.ksh trying to find database status.
    . ~oracle/.profile > /dev/null
    db_status=`eval sqlplus -s 'system/passwd@DEV' << EOF
    set pagesize 0 feedback off verify off heading off echo off
    select status from v\\$instance;
    exit
    EOF`
    echo $db_status > /tmp/db_status_out

  • Problem with background job using SUBMIT under different user

    Hi All,
    I am submitting a background job under different user name. I am submitting this job by using JOB_OPEN , SUBMIT report and JOB_CLOSE. But submit statement is returning sy-subrc 8, becuase of this the job_close is failed. Can you please help me to solve this problem.
    Thanks in advance.
    Tjgupta

    Hi,
    The user is having all authorizations. is there any difference with user types?
    This user is having  user type " as communication data".
    Thanks,
    Tjgupta

  • Can you use home share where there are 2 itunes on the same computer but under different user profiles?

    Can you use 'Home Share' where there are 2 itunes on the same computer, but under different user profiles?

    check out method one from this support article -> How to use multiple iPods, iPads, or iPhones with one computer

  • What is better a shell script or a user exit?

    Hi experts!
    I need to change the owner of a file when I send it to XI sever.
    I talk with the administrator of the system to change the owner with a shell script but he tell me that is better if I use a user exit. But my question is: What is better? The shell script or the user exit?

    hi,
    >>>>I talk with the administrator of the system to change the owner with a shell script but he tell me that is better if I use a user exit
    maybe because the admin does not do the user exits ?
    you can do it with XI but you'll have to create it
    via a proxy for example (as standard file adapter does
    not support this) 
    on the other hand the file adapter supports invoking
    system commands (so you can start a shell script)
    I'm not directly answering your question
    I'm just telling you what you'll have to do
    to build your solution in both cases
    Regards,
    michal
    <a href="/people/michal.krawczyk2/blog/2005/06/28/xipi-faq-frequently-asked-questions"><b>XI / PI FAQ - Frequently Asked Questions</b></a>

Maybe you are looking for

  • Can't create a new SQL Azure Standard Tier db

    I'm having an issue creating a new sql azure standard tier db. Here's the basic steps I've done to migrate a web tier db. Register for the sql preview programme https://account.windowsazure.com/PreviewFeatures Perform a db export to blob storage use

  • CONVT_CODEPAGE errror

    I have a program which generates a flat file to be FTPed to another Unix Server from SAP. In this file if there are Non-English characters then they are not being interpreted properly at Unix Level. For Example : There is a MATNR in MARA as 'FORFAIT

  • Cant access itunes store app on iphone 4s

    Having restored iphone to new iphone to get rid off 10gb off 'other' i have now discovered i cant access the itune store on my phone. ive tried re-setting the settings in general, have tried clearing cookies, tried logging out of apple id and back in

  • All my save as PDF selections have suffix appended

    Selecting tools and selecting save as PDF cause a PDF file to be created OK, but each file follows the following format. Filename.PDF.part It requires a rename to eliminate the .part portion. Thanks I am using a hisence nvidia with a tetra 3 processo

  • I want to delete all my apps

    Hi I have itunes on a mac and the kids have 408 apps on my computer. Of which things like 4 different types/copies of a battery status are clearly not needed. I want to blitz them all and just delete the lot. However, they both have purchased items t