0

Please find sample code

Sample test.ksh :

Below is the code that I have used to run on two users, however when run the script it ust executes the first command and i.e sx su command and stops executing further

#!/bin/ksh 

sx su - user1    
cat testfile.txt    
exit  

sx su - user2    
cd /bin    
ls -lrta
4
  • Please use right formatting to make your question more clear. Did you get any error when you execute this code? Commented Mar 17, 2020 at 13:54
  • I didn't get any error, the script just stopped executing further after switching to user 1 Commented Mar 17, 2020 at 14:01
  • 2
    you realized that exit means exit? Code is working as written. You'll have to either remove the call to exit or make it conditional, ie if [ $? != 0 ] ; then exit ; fi (or similar). Good luck. Commented Mar 17, 2020 at 15:35
  • Hello @shelter, for me to switch to user 2 from user 1, I have to come out of user 1. There is no access granted for user1 to su to user 2. Commented Mar 19, 2020 at 7:47

1 Answer 1

1

You can try something like (as root!)

#!/bin/ksh 

su - user1 -c "cat testfile.txt"    
su - user2 -c "cd /bin; ls -lrta"
Sign up to request clarification or add additional context in comments.

1 Comment

Hi romea, Thanks mate but I don't have root access.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.