su option is not fetching the password


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users su option is not fetching the password
# 1  
Old 08-28-2012
su option is not fetching the password

Hi,

Please find the below code.
Code:
function ABC
{
    echo "Enter Element Name:"
       read ename
       echo "Enter Element Source path:"
       read spath
       echo "Enter Element Destination path:"
       read dpath
       echo "cp -p $spath/$ename $dpath/$ename"
       echo "chmod 774 $dpath/$ename"
}
echo      "Do you want to initiate the process ${bold}(Y/N?)${offbold}"
read inp
if [ $inp == "Y" -o $inp == "y" ] ;
then
............................
............................
............................
echo " Does this involves any other files? ${bold}(Y/N?)${offbold}"
read inp
    if [ $inp == "Y" -o $inp == "y" ] ;
    then
   
    echo "***************************** "
    echo " Enter the abcuser password "
    echo "***************************** "
      (
    while [ $inp == "Y" -o $inp == "y" ] ;
       do
      ABC
    echo "Do you have any other elements?${bold}(Y/N?)${offbold}"
       read inp
      done
      ) | su abcuser
    fi
  echo "Program has been executed."
fi

If i execute it, i am getting password prompt for switching into abcuser. But it is not fetching the password and moving to next step.

Getting response like below:


Code:
*****************************
 Enter the abcuser password
*****************************
Password:





su: Sorry
Program has been executed

Please help me to fix this issue.

Regards,
ggggSmilie


Moderator's Comments:
Mod Comment Please use code tags next time for your code and data.

Last edited by zaxxon; 08-28-2012 at 04:03 AM.. Reason: code tags
# 2  
Old 08-28-2012
Hello, could you put set -x and launch script again.
# 3  
Old 08-28-2012
Please find the output which has been executed in debug mode.

Does this involves any other files? (Y/N?)

Code:
+ read inp
y
+ [ y == Y -o y == y ]
+ echo *****************************
*****************************
+ echo  Enter the abcuser password
 Enter the abcuser password
+ echo *****************************
*****************************
+ su abcuser
+ [ y == Y -o y == y ]
+ echo Enter Element Name:
+ read ename
Password: + echo Enter Element Source path:
+ read spath
+ echo Enter Element Destination path:
+ read dpath
+ echo cp -p /dsf/cfsabc fdf/cfsabc
+ echo chmod 774 fdf/cfsabc
+ echo Do you have any other elements?(Y/N?)
+ read inp
+ [ y == Y -o y == y ]
+ echo Enter Element Name:
+ read ename
+ echo Enter Element Source path:
+ read spath
+ echo Enter Element Destination path:
+ read dpath
+ echo cp -p /dsf/cfsegf fdf/cfsegf
+ echo chmod 774 fdf/cfsegf
+ echo Do you have any other elements?(Y/N?)
+ read inp
+ [ n == Y -o n == y ]




su: Sorry
+ echo program has been executed.

Its taking password as element name cfsabc like its moving on for next inputs.


Moderator's Comments:
Mod Comment Please view this code tag video for how to use code tags when posting code and data.

Last edited by vbe; 08-28-2012 at 11:13 AM..
# 4  
Old 08-28-2012
Look and figure out what is happening:
Code:
ant:/home/vbe $ ./test01
hello
su test01
This script  is shell PID:  29792
Enter passwd
Password: 
ant:/home/vbe $ echo $$
29793
ant:/home/vbe $ exit
hihi back to $$ : 29792
done

How do you expect to pass information from process 29792 to 29793 ?
# 5  
Old 08-28-2012
Then Please let me know how i can update my script.Smilie
# 6  
Old 08-28-2012
Either using expect utility or by using files descriptors I suppose...
su command has no options for passwd so it will always prompt... I tried with heredocs without success (but didnt pass much time either...) there is a no very elegant nor secure way if you know which user you want to allow to "su", its using rlogin and a .rhosts file...
like that you will not have any passwd to enter...
you should write your script in such a way all you enter in interative is to generate a newscript that you pass with the su command or rlogin e.g. for su:
Code:
 su <newuser> -c ~/newscript

with rlogin:
Code:
ant:/home/vbe $ remsh ant -l jju -n date
Tue Aug 28 17:44:38 METDST 2012

# 7  
Old 08-28-2012
Another way would be using the sudo utility, which can be configured to allow one user to do one specific thing as another user. This would be better than installing a third-party brute-forcing utility to inject insecure plaintext passwords into an otherwise secure login system.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Forum Support Area for Unregistered Users & Account Problems

Password sent via reset password email is 'weak' and won't allow me to change my password

I was unable to login and so used the "Forgotten Password' process. I was sent a NEWLY-PROVIDED password and a link through which my password could be changed. The NEWLY-PROVIDED password allowed me to login. Following the provided link I attempted to update my password to one of my own... (1 Reply)
Discussion started by: Rich Marton
1 Replies

2. Shell Programming and Scripting

Fetching timestamps from the logs.

Dear Experts, I need some help to get the time stamps from the Unix logs. Basically I am want to analyze which step is taking more time. Please give me some inputs. Thanks a lot for your help. I have got different codes for each for phase as we can see in the logs 00002 – UPDT Starting... (5 Replies)
Discussion started by: srikanth38
5 Replies

3. Shell Programming and Scripting

Notable to use password option in zip command

zip -P abc -r FBE_SalesRepAccount_20170913125741.zip FBE_SalesRepAccount_20170913125741.txt zip error: Invalid command arguments (encryption not supported) zip -v Copyright (C) 1990-1999 Info-ZIP Type 'zip "-L"' for software license. This is Zip 2.3 (November 29th 1999), by Info-ZIP.... (1 Reply)
Discussion started by: alokjyotibal
1 Replies

4. Solaris

Unrecognized option: sparc-sun-Solaris2.10/bin/as: unrecognized option `-m32'

Hi, I installed some packages required by an app built with python. But when I try python setup.py install, I get the following error: /opt/csw/lib/gcc/sparc-sun-solaris2.10/5.2.0/../../../../sparc-sun-solaris2.10/bin/as: unrecognized option `-m32' Could anyone tell me what's wrong... (4 Replies)
Discussion started by: Kimkun
4 Replies

5. Shell Programming and Scripting

Fetching data from file

Hi All, I'm facing issue while using script. Chk_Etl_Status=`cat /dstage/questnet/qnetdv/input/Etl_Status.dat|cut -d"," -f1` echo Chk_Etl_Status=$Chk_Etl_Status above result is giving me sometime value as 1 and sometime error message as Chk_Etl_Status= dsjoblaunch.sh: test: Specify a... (5 Replies)
Discussion started by: Amit786
5 Replies

6. Shell Programming and Scripting

Fetching the string using different patterns

HI, Please help me with the following problem: I have an xml file with the following lines <NameValuePair> <name>SharedResources/JDBC/Admin/password</name> <value>rjmadmin</value> </NameValuePair> <NameValuePair> ... (4 Replies)
Discussion started by: tejastrikez
4 Replies

7. Shell Programming and Scripting

recently introduced to the newer option for find...does an older option exist?

To find all the files in your home directory that have been edited in some way since the last tar file, use this command: find . -newer backup.tar.gz Is anyone familiar with an older solution? looking to identify files older then 15mins across several directories. thanks, manny (2 Replies)
Discussion started by: mr_manny
2 Replies

8. Shell Programming and Scripting

option followed by : taking next option if argument missing with getopts

Hi all, I am parsing command line options using getopts. The problem is that mandatory argument options following ":" is taking next option as argument if it is not followed by any argument. Below is the script: while getopts :hd:t:s:l:p:f: opt do case "$opt" in -h|-\?)... (2 Replies)
Discussion started by: gurukottur
2 Replies

9. UNIX for Dummies Questions & Answers

No Password - - Setuid Only Option in Solaris 10

In Solaris 9, when I built users, there was an option for No Password -- Setuid Only. Now that I'm using Solaris 10, I no longer can find that option. Is there an equivalent option of No Password --Setuid Only in Solaris 10? Thanks, LeonD (1 Reply)
Discussion started by: leond
1 Replies
Login or Register to Ask a Question