The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Error executing shell command from a perl script voorkey Shell Programming and Scripting 5 03-30-2009 08:48 AM
SED command is not executing within the shell naushad UNIX for Dummies Questions & Answers 1 03-26-2008 04:35 AM
executing dir or ls command via FTP alx Shell Programming and Scripting 5 01-27-2006 06:13 PM
Automatically executing a command robbiegregg UNIX for Dummies Questions & Answers 8 04-06-2005 12:46 PM
Allowing a script to continue executing when a command hangs mkinney Shell Programming and Scripting 5 04-24-2002 02:28 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-30-2005
shailendrat shailendrat is offline
Registered User
  
 

Join Date: Mar 2005
Posts: 6
executing the su command from a script.

Say in unix (AIX) m/c, I am logged in with s1 user and want to start process p1 with user credentials of s2.

This i can do manually in this way:
#su - s2
#enter password for s2> somePassword
$ p1

But all this I have to do through a java program. This I can do by running a script through java program.

In script how i can pass the password.
For ex (Can it be done like this):
su - s2
somePassword


I will be thankful, if anybody can suggest some solution to this problem.

Thanks in advance.
  #2 (permalink)  
Old 03-30-2005
muthukumar muthukumar is offline
Registered User
  
 

Join Date: Feb 2005
Location: Coimbatore, Tamilnadu, India
Posts: 119
There is a possibility to do this as,

1) expect scripting
2) sudo utility

on shell.

With expect script as like as,
#!/usr/local/bin/expect
spawn su -
expect "Password:" { send "passwd\r" }
expect "# " { send "uname -a\r" }
expect "# " { send "pwd\r" }
expect "# " { send "q" }
exit

hth.
  #3 (permalink)  
Old 04-05-2005
shailendrat shailendrat is offline
Registered User
  
 

Join Date: Mar 2005
Posts: 6
Thanks Muthukumar for your help.

I downloaded the expect utility. But if I use expect, I have to ship this utility with my application.
So, is their any easy way to achive this functionality.

Actually, I want to include this feature in my java program. Through java program, i tried reading "passwd" string (using std input/output stream) after the execution of command:
su - shail -c cleartool.
But I was not able to get this string in output stream. It was asking the passwd on the command promp in which i was executing my java program.
What I felt, unix might be starting new process to get the password from user.

Well, you also mentioned about sudo feature. Can you please eloborate on this command. How I have to use sodo for giving password interactivly using script.

Thanks in advance.

With regards....

Shailendra
  #4 (permalink)  
Old 04-05-2005
Just Ice's Avatar
Just Ice Just Ice is offline Forum Advisor  
Lights on, brain off.
  
 

Join Date: Mar 2005
Location: in front of my computer
Posts: 637
if you're only trying to run a process and if you're initial user is root, just ...

Code:
su - s2 -c "p1"

or ... you can have your program query the user for the s2 password prior to proceeding with the rest of the events ...
  #5 (permalink)  
Old 04-05-2005
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
You could use:

su -c <command with args> username

Don't know all options that AIX su supports though.
  #6 (permalink)  
Old 04-05-2005
shailendrat shailendrat is offline
Registered User
  
 

Join Date: Mar 2005
Posts: 6
Error which installing expect

I have to start a new process using su under normal user and not under root.

muthukumar has suggested using expect. I tried to install expect but it was giving following error.

# ./configure.in
./configure.in[8]: Syntax error at line 8 : `(' is not expected.

If anybody can help me.

Thanks in advance.

With regards....

Shailendra
  #7 (permalink)  
Old 04-11-2005
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
Actually, there is an ugly, interesting and not to be used workaround that you can use:

If you are user a and want to run a particular command as user b, you can enable rsh/remsh from localhost for user a to user b.

In user b's home directory, create .rhosts file and add the following entry:

localhost a

where localhost is the hostname and a is the username.

Then you can run whatever command you want using remsh/rsh

Code:
rsh -l b localhost <command to be executed>

Don't use this, but, just thought that this would show you that there are a million ways of getting things done in unix, so don't stop looking.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:43 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0