psh su question


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users psh su question
# 1  
Old 02-17-2010
Question psh su question

hi ,
Im involved in developing a prototype for a automation intiative . this is my scenario , in my shell script (sh ) .
I have 'psh su - sadmin' ( sadmin is a non root system account )

My script abc.sh does the following

Code:
#!/bin/sh
pwdfile =/users/home/sadmin/pwd.txt ( contains the password for my account ) 
 
 psh su - sadmin
< cat $pwdfile 
 
/users/siebelserver/siebsrvr
./stop_server all
 
do something
/users/siebelserver/siebsrvr
./start_server all

------
Problem what im facing is when i run my script as myself the script sucessfully does a psh to sadmin but doesnt proceed after that ..it just waits after doing a sucessfull psh su - sadmin . so i have to exit from that shell prompt and then script runs the rest of statements as "myself " and
any idea what im doing wrong ..and how i can make the script run the rest of statements as user "sadmin" and not as me .
I even tried a bizarre way of adding lines to the pwd.txt thinking that the program was waiting after the password read ..but still it didnt work either.

Last edited by pludi; 02-17-2010 at 09:31 AM.. Reason: code tags, please...
# 2  
Old 02-17-2010
Code:
#!/bin/sh
# You can't just put a comment anywhere and expect the
# script to still work.  At least put a # before them.
#  ( contains the password for my account ) 
gaping_security_hole=/users/home/sadmin/hackers_dont_read_this_file_pretty_please.txt

# 1) < > are for files, not processes.  'cat < "$pwdfile"' may have been what
#     you meant, I'm not sure.
# 2) Your redirection wasn't even on the same line, so couldn't have worked.
#     That's probably why it was hanging.
# 3) You don't need to use cat here.
# 4) su isn't supposed to work that way.  It's designed not to accept
#     hardcoded passwords for security reasons.  You should NOT be keeping
#     plaintext passwords around for any reason.
# 5) Even if you manage to cudgel su into reading the password from file
#     somehow, it won't execute the statements following it.  It runs
#     separately, it doesn't extend the permissions of your existing script.
#
#     Usually, you either run su interactively, or feed it a command to run.
#     Don't embed su in script files, use su to call a script file.
su - sadmin -c "/path/to/script/file" < "$gaping_security_hole"

# ...or better yet, use sudo.  It can be configured very exactly.  Your
# sysadmin can tell it to let you, and only you, to run this and only this 
# command, as that and only that user, with no password.
sudo -u sadmin /path/to/script/file

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Ls -l question

Hi, When doing ls -l, is it right to assume that all files with the date and time on it are files that are created/modified on the current year? Is there any way to display the creation/modified date of a file that are not created/modified in the current year? (4 Replies)
Discussion started by: newbie_01
4 Replies

2. Shell Programming and Scripting

A question

Hi, I'm new to unix and got struck here.Can any one help me out.My question is .. is the command if ; then echo "do some stuff" fi correct? Thanks in advance abhijeet (18 Replies)
Discussion started by: Abhijeet_Atti
18 Replies

3. Programming

C++ little question

Hi, I am doing a C++ self-study and I got stuck with this problem. I want to have a code that asks the suer to enter two numbers and then it lists the numbers between these two numbers. It has also to print a message if these two numbers are equal. Here is what I wrote: #include <iostream>... (11 Replies)
Discussion started by: faizlo
11 Replies

4. UNIX for Dummies Questions & Answers

Help me these Question??

1. How the Unix system identify the Other User to access for file permission? 2. What command we use to convert the extension of a file name? 3. What command use to convert other editing file to Unix based text file? Please answer of these Question???Its necessary for me?? (3 Replies)
Discussion started by: pradipta_pks
3 Replies

5. UNIX for Dummies Questions & Answers

Question

I need to write a script file that will tell me the largest number in a group of numbers. ANy help is greatly appreciated (2 Replies)
Discussion started by: twan
2 Replies

6. Shell Programming and Scripting

vi question

hello! i am very new to this, so please bear with me. i used red hat linux to creat a little two page website for school, which was really just an exercise in absolute and relative paths. so, now, its all done, and i want to play with it some more, but i think there may be a problem with vi. i... (3 Replies)
Discussion started by: jojodancer
3 Replies

7. Shell Programming and Scripting

question

how do i write a script that'll open what i entered and scan it for a certain line of text. for example, i enter a filename (that exists) and in that file i want to scan a certain word that'll show how much of that word appears throughout the file. (2 Replies)
Discussion started by: mrhenry
2 Replies

8. Shell Programming and Scripting

first question

Dears, Actually i am facing a problem in a UNIX script: I want to convert a column output file to a rows e.g: from 1234 2345 3456 to 1234 2345 3456 any help please???? Thanks (2 Replies)
Discussion started by: tontal
2 Replies

9. UNIX for Dummies Questions & Answers

Next Question:

what is the function of swap in linux why i have to create apsolutely a particion for the swap when i install (i installed lnx4win mandrake and made an automat. disk particion and the install program one of my disk partitions that was 3gb devidet in 4 one native 700mb swap 600mb and the others i... (1 Reply)
Discussion started by: user666
1 Replies
Login or Register to Ask a Question