LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-29-2004, 03:18 PM   #1
Lun1x
LQ Newbie
 
Registered: Mar 2004
Distribution: Redhat 8.0, SuSE Enterprise Server 8.0
Posts: 9

Rep: Reputation: 0
Korn Shel Script Error


hi guys

i am trying to do something like this

Code:
#!/bin/ksh
# Change to the userid user1
su - user1

#Issue the command to change directory and list files
cd /home/user1/
ls -lrt
exit				#Come out of the user1 to root again
 
#change to user 2

su - user2
cd /home/user1/
ls -lrt
exit				#back to root again


#come out of the script
done				# Is this needed?
however after executing the script (as root, who is the owner of the file) , it seems to only execute the first line.
(changes to user1).
where am i going wrong. The default shell is Korn (ksh) and permissions are right for root to execute.
 
Old 07-29-2004, 03:23 PM   #2
Corona4456
Member
 
Registered: Jul 2004
Distribution: SuSE 9.1
Posts: 66

Rep: Reputation: 15
Well the problem is from my past experience is when you run su. It opens up another shell which means the script is not going to keep executing until you comeback from su therefore your script isn't going to be executed while you are user1. Another way to do this is by using sudo ... type 'man sudo' in console.

Last edited by Corona4456; 07-29-2004 at 03:24 PM.
 
Old 07-29-2004, 03:47 PM   #3
Lun1x
LQ Newbie
 
Registered: Mar 2004
Distribution: Redhat 8.0, SuSE Enterprise Server 8.0
Posts: 9

Original Poster
Rep: Reputation: 0
Corona: Thanks for the reply. Seems sudo is not installed in this AIX box. Is there another way of doing what i am trying to do. Key thing for me is to able to change users on the fly as there are diff commands authorized to diff userids that i wanna do using the same script.
 
Old 07-29-2004, 05:20 PM   #4
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 35
Code:
su - user1  -c   (cd /home/user1/; ls -lrt ; exit)
for each set of commands should work. I don't know AIX, but the command string must be valid Bourne shell syntax. It works on Sun & HPUX.
 
Old 07-29-2004, 05:46 PM   #5
Corona4456
Member
 
Registered: Jul 2004
Distribution: SuSE 9.1
Posts: 66

Rep: Reputation: 15
Quote:
Originally posted by Lun1x
Corona: Thanks for the reply. Seems sudo is not installed in this AIX box. Is there another way of doing what i am trying to do. Key thing for me is to able to change users on the fly as there are diff commands authorized to diff userids that i wanna do using the same script.
Well you can install sudo I'm pretty sure. However,
jim mcnamara's suggestion will work as well
 
Old 07-29-2004, 05:58 PM   #6
Lun1x
LQ Newbie
 
Registered: Mar 2004
Distribution: Redhat 8.0, SuSE Enterprise Server 8.0
Posts: 9

Original Poster
Rep: Reputation: 0
Jim: Thanks. That works.
Corona: i am installing sudo anyways Thanks
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shel script mail send ("/" in mail address) problem anaid Linux - Networking 3 08-23-2005 08:41 AM
shel script resources b123coder Programming 1 06-28-2005 09:02 AM
unix korn shell script that interact with windows java program ann124 Programming 5 11-09-2004 10:14 PM
Korn shell script Muzica Solaris / OpenSolaris 4 09-06-2004 01:47 PM
delete line specified by variable wihin shel script with sed lnchatterbox Linux - Newbie 2 02-23-2004 02:24 PM


All times are GMT -5. The time now is 08:28 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration