0

I am running a script through root which will do login to all the registered users and will execute few commands(example: list down all the folders in users directory), collect their reports and copy it in root login.

My command looks like this

for i in `cat userlist`; do echo $i; su $i ; ls ; exit; done > folderList

The problem with this command is after doing a su to user it changes the shell and the script waits till it receives a exit from that shell

1 Answer 1

1

try:

su - $user -c whoami

for executing a command as user in a subshell, which is terminated automatically when program ends.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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