![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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. |
|
||||
|
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. |
|
||||
|
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 |
|
||||
|
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 |
|
|||||
|
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. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|