0

I would like to create a script that would list all owners of all the sub directories then check each ID if I have access to sesu to the IDs.

**$**ls -lrth /apps/wldomains | grep '^d' | awk '{ print $3 }'
userid1
userid2
userid3
userid4
.
.
.

**$**sesu - userid1
Please enter your password:
**userid1@SERVER:$**sesu - userid2
Please enter your password:
**userid2@SERVER:$**sesu - userid3
.
.
.
.

2 Answers2

2

use printf feature of awk, then pipe to ksh.

ls -lrth /apps/wldomains | awk '$1 ~/^d/ { printf "sesu %s\n", $3 }'

should generate

sesu userid1
sesu userid2
sesu userid3
sesu userid4

simply add | ksh when OK

ls -lrth /apps/wldomains | awk '$1 ~/^d/ { printf "sesu %s\n", $3 }'| ksh
  • I also compacted grep | awk in awk
Archemar
  • 31,554
1

Without parsing ls:

find /apps/wldomains -type d -exec stat -c %U {} \; | sort -u | xargs -n 1 sesu -
  • find /apps/wldomains -type d will find all directories under /apps/wldomains (including /apps/wldomains itself).

  • stat -c %U will output the user name of the owner of the found directory.

  • sort -u will take these user names and sort them into a list of distinct user names.

  • xargs -n 1 sesu - will take this list and execute sesu - for each of them.

On Solaris, install the GNU coreutils package and use gstat in place of stat.

Kusalananda
  • 333,661