Go Back   TechArena Community > Software > Operating Systems
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , , ,

Sponsored Links



Selecting a user in a shell script

Operating Systems


Reply
 
Thread Tools Search this Thread
  #1  
Old 25-12-2009
Quattro's Avatar
Member
 
Join Date: May 2008
Posts: 256
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.
Reply With Quote
  #2  
Old 25-12-2009
Solomon's Avatar
Member
 
Join Date: May 2008
Posts: 4,056
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.
Reply With Quote
  #3  
Old 25-12-2009
Quattro's Avatar
Member
 
Join Date: May 2008
Posts: 256
Re: Selecting a user in a shell script

Hi
Quote:
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.
Reply With Quote
  #4  
Old 25-12-2009
jesse's Avatar
Member
 
Join Date: Nov 2005
Posts: 2,965
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.
Reply With Quote
  #5  
Old 25-12-2009
Dr. V
 
Posts: n/a
Re: Selecting a user in a shell script

Hello
Quote:
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.
Quote:
sudo su - oracle
[/code]
Besides the way, if you are root, you can do simply su - oracle without using sudo.
Reply With Quote
  #6  
Old 25-12-2009
jesse's Avatar
Member
 
Join Date: Nov 2005
Posts: 2,965
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
Quote:
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.
Reply With Quote
Reply

  TechArena Community > Software > Operating Systems


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Selecting a user in a shell script"
Thread Thread Starter Forum Replies Last Post
How can I create shell script which find out who the active, current user is? mANICKAVASAN Windows Software 4 20-10-2010 12:56 PM
shell script SSH not working Lilya Software Development 9 16-10-2010 02:53 AM
Shell script with sed Ameeryan Software Development 5 23-12-2009 02:29 PM
Shell Script Formatting abhi701 Software Development 1 04-07-2009 05:30 PM
Unix Shell Script BlackSunReyes Software Development 3 12-08-2008 02:57 PM


All times are GMT +5.5. The time now is 01:21 AM.