Results 1 to 6 of 6

Thread: Selecting a user in a shell script

  1. #1
    Join Date
    May 2008
    Posts
    255

    Selecting a user in a shell script

    Hello
    I run a shell script from a java application, but I need to run the command in the script under a specific user (eg testusr), how to do this in the script knowing that the command su can not save the password of the user in the same line, but it requires a password after typing su. So I can use in this case. What I have to do to achieve this? Any help will be highly appreciated. Thank you in advance.
    Last edited by Quattro; 25-12-2009 at 02:02 PM.

  2. #2
    Join Date
    May 2008
    Posts
    4,085

    Re: Selecting a user in a shell script

    Hi
    You can transfer the request password for user "testusr" to execute commands with "sudo" and adding in / etc / sudoers this line.
    Just type the following command in the terminal as a root user.
    Code:
    toto ALL = (ALL) NOPASSWD: / path / to / myscript
    hope this works for you. Any more help needed do post, so that we can help you to resolve your problem.

  3. #3
    Join Date
    May 2008
    Posts
    255

    Re: Selecting a user in a shell script

    Hi
    You can transfer the request password for user "testusr" to execute commands with "sudo" and adding in / etc / sudoers this line.
    But I only have remote access to the machine and only under a username that does not have the right to change. My request was, is there another command for su or sudo. Any other alternative for this. Thanks in advance.

  4. #4
    Join Date
    Nov 2005
    Posts
    3,026

    Re: Selecting a user in a shell script

    Hello
    I am starting with the credentials of the root or root users (in a group, or other file sudoers). you can do
    Code:
    sudo su - oracle
    Practice for the specific environment of a user.
    Code:
    testusr @ root ssh sudo / usr / sbin / someusr 
    (currently forget the sudoers for this user)
    Now your java application must be playable for that user. If you have any more queries, then do post back.

  5. #5
    Dr. V Guest

    Re: Selecting a user in a shell script

    Hello
    testusr @ root ssh sudo / usr / sbin / someusr
    (currently forget the sudoers for this user)
    Except that since he did not have access to the root account on his machine, he can not edit the sudoers file.
    sudo su - oracle
    [/CODE]
    Besides the way, if you are root, you can do simply su - oracle without using sudo.

  6. #6
    Join Date
    Nov 2005
    Posts
    3,026

    Re: Selecting a user in a shell script

    Hi
    Without root access, the only solution is through the cooperation of other users. Either the script is installed in each of them with chown or it is installed under the account running the Java code but in a folder accessible by others and is executable by all users.
    Each user will then have a folder. ssh in which he put into the file authorized_keys public key of the account running the script using Java, including
    from = "IP_SERVER" ssh-ind ... ... IND_PUBLIC_KEY user_running_java@your.server.com [/email]
    the script using Java will then by executing a shell command via ssh:
    Code:
    / usr / bin / ssh-i / home / USER_RUNNING_JAVA / .ssh / id_ind USER_RUNNING_THE_SCRIPT@your.server.com "path_to_script / thescript.sh"
    But even limiting access via ssh key to the server IP, one that can connect to the account under which the Java code will access this account via ssh to all the accounts of users who participate in the system. Hope this information will help you.

Similar Threads

  1. Replies: 4
    Last Post: 20-10-2010, 11:56 AM
  2. shell script SSH not working
    By Lilya in forum Software Development
    Replies: 9
    Last Post: 16-10-2010, 01:53 AM
  3. Shell script with sed
    By Ameeryan in forum Software Development
    Replies: 5
    Last Post: 23-12-2009, 02:29 PM
  4. Shell Script Formatting
    By abhi701 in forum Software Development
    Replies: 1
    Last Post: 04-07-2009, 04:30 PM
  5. Unix Shell Script
    By BlackSunReyes in forum Software Development
    Replies: 3
    Last Post: 12-08-2008, 01:57 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,711,057.44079 seconds with 16 queries