AIX How to run a Shell Script by changing the User


 
Thread Tools Search this Thread
Operating Systems AIX AIX How to run a Shell Script by changing the User
# 1  
Old 07-25-2012
AIX How to run a Shell Script by changing the User

Hi All,

Currently our application is running on the server having AIX 5.3 OS.

What we intend to do is to run a shell script owned by another user and needs to be run as that particular user.

I was trying to create a shell script using the su command before running the actual script (which will be executed from the new script). The su command always prompt for a password. Is there any way we can put that in the shell script so that there is no user prompt.

Also please guide if there is any better methodologies to achieve this.

Thanks

Abhik
# 2  
Old 07-25-2012
Depends on the security policies on your site. One possible solution is to create .rhosts file in the home directory of the secondary user containing only the hostname and username of the calling user, and use:
Code:
# assuming remsh is the Remote Shell on AIX
remsh localhost -l loginname -n scriptname
# or alternatively
su loginname -c "scriptname"

I prefer the su version because it is easier to return control to a script.
# 3  
Old 07-25-2012
If you run this as a non-privileged user, then it will ask for the password. AIX has sudo (what you want to use); you must download and install it if it is not already on your system. Someone here with AIX experience can guide you.

I know UNIX, but every time I give a detailed answer to an AIX question I get something not quite right because AIX is, um, different.
# 4  
Old 07-25-2012
Is there no way where we can pass the password as a parameter as how we are passing the user name?
# 5  
Old 07-25-2012
Quote:
Originally Posted by jim mcnamara
I know UNIX, but every time I give a detailed answer to an AIX question I get something not quite right because AIX is, um, different.
You are doing alright. In fact sudo is one of the few things where AIX is different from "normal AIX", because it is absolutely the same as other systems.

Quote:
Originally Posted by acoomer
Is there no way where we can pass the password as a parameter as how we are passing the user name?
Yes, this is possible. Admins doing this should be tarred and feathered, though. Honestly: you don't want to do this. It is a security hole you can drive a truck through and begs the question: if one user is allowed to know the password of the other user than why can't they share a user-ID anyway?

Keep in mind that shell scripts are plain text - what you write into them can be read with a simple editor. Would you want to put a password simply into a file? You could as well use no password at all instead, no?

Install sudo, which you can download from the IBM AIX Toolbox for Linux Applications as an rpm-package.

Basically you define three things in a sudoers file: a "command alias", which is a list of commands (it can even be one command). Then a "user alias", which is the same for a list of users - it can also be one user. The last thing is a list of things to be allowed: a certain user-alias (the list of users defined there) should be allowed to execute the command-alias (the list of commands) not as themselves but as a certain other user (usually, but not necessarily root).

I hope this helps.

bakunin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script run in a case statement call to run a php file, also Perl

Linux System having all Perl, Python, PHP (and Ruby) installed From a Shell script, can call a Perl, Python, PHP (or Ruby ?) file eg eg a Shell script run in a case statement call to run a php file, also Perl or/and Python file??? Like #!/usr/bin/bash .... .... case $INPUT_STRING... (1 Reply)
Discussion started by: hoyanet
1 Replies

2. Shell Programming and Scripting

Best way to run a shell with different user

Hi , we got autosys for scheduling our jobs. Autosys user logs in to the Linux box and need to execute a shell script. problem here is user requires admin privileges on database to complete the task. Since scheduling is maintained by different team I don't want autosys user to have admin privileges... (1 Reply)
Discussion started by: rush143
1 Replies

3. AIX

List of AIX commands that can be run by ROOT user ONLY

Hello, I am testing sudo and I want to test it. Can anyone please let me know few commands (of course other than shutdown, reboot etc. as I can't reboot the box) on AIX that can be run by ROOT only. Thanks ---------- Post updated at 07:43 PM ---------- Previous update was at 07:38 PM... (5 Replies)
Discussion started by: prvnrk
5 Replies

4. Shell Programming and Scripting

User id who is changing the script.

can we know the user id who changed saved script in cron tab..:D (7 Replies)
Discussion started by: netdbaind
7 Replies

5. Shell Programming and Scripting

Forcing another user to run a shell script (su)

I'm trying to use su (as myuser) to force another user (theuser) to run a shell script (thescript.sh): su theuser -c /home/theuser/thescript.sh However I'm running this from another script, and it is asking for theuser's password. I would rather avoid displaying it in the file (using echo... (2 Replies)
Discussion started by: asdfgg
2 Replies

6. UNIX for Dummies Questions & Answers

Changing the user id or euid of the shell itself

Hi all, Ok, bear with me on this one, I am a bit new to Unix and it might take me a little bit of time to articulate my question. I know that every process has a user id and an effective user id. This seems to include the shell itself, because when I type 'ps', I see 'bash' listed as a... (2 Replies)
Discussion started by: oddthingy
2 Replies

7. Shell Programming and Scripting

Can root user run chmod 000 permission shell script?

Hi, I have a shell script file which is set to access permission 000. When I login as root (sudo su) and try to run this script, I am getting the Permission denied error. I have read somewhere that root admin user can execute any kind of permission script. Then why this behavior? However, I can... (1 Reply)
Discussion started by: royalibrahim
1 Replies

8. Shell Programming and Scripting

How to run cmds after changing to a new env (shell) in a shell script

Hi, I am using HP-UNIX. I have a requirement as below I have to change env twice like: cadenv <env> cadenv <env> ccm start -d /dbpath ccm tar -xvf *.tar ccm rcv .... mv *.tar BACKUP but after I do the first cadenv <env> , I am unable to execute any of the later commands . ... (6 Replies)
Discussion started by: charlei
6 Replies

9. UNIX for Dummies Questions & Answers

shell script run by user or cron job ?

My shell script runs fine both as a cron job and when i issue it. However, I wish to differentiate when it runs as a cron-job so the "echo" statements are not issued (they get mailed to me, which i don't want). I tried checking $USER but since the cron was created in my user that does not... (5 Replies)
Discussion started by: sentinel
5 Replies

10. UNIX for Advanced & Expert Users

Run shell script as different user

I want to start off by saying thanks to everyone here, you're answers and suggestions are always very helpful. I have a shell script which is invoked when an email is received. This shell script extracts any attachments that are sent with this email, and then runs a script which submits these... (8 Replies)
Discussion started by: mskarica
8 Replies
Login or Register to Ask a Question