When you need to perform several commands from the other user inside a script this will do the job:
#!/bin/bash - su - user <<HERE ls -al # other commands run by 'user' # ... HEREWhen you need to find out the original owner of the current shell always use
who am i | awk '{print $1}'or
lognameas no other methods are guaranteed (via stackoverflow). Another useful tool is environment variable
$SHLVL: Incremented by one each time an instance of bash is started.It won't show the user but can show the shell 'depth'.
Комментариев нет:
Отправить комментарий