Finding unique UIDs under a directory

This is a sequel to "Migrating network storage device to Solaris x86". I pulled off Linux ext3 formatted HDD from Thecus NAS and put it in Solaris box. Since Solaris currently cannot write to ext3, I need to replicate the whole tree to another file system.

# pwd
/mnt/bipshare <-- read only mounted
# grep bipshare /etc/mnttab
127.0.0.1:/ /mnt/bipshare nfs ro,port=45999,public,vers=2,proto=udp,xattr,dev=4800009 1195607036
I don't know how to see UIDs,GIDs in Thecus admin Web UI. Thecus is just a small Linux so  it should have /etc/passwd file somewhere. But I couldn't find it anywhere on disk. So, I now need to list all UIDs which own file/directory under /mnt/bipshare. It would have been easy with ufs. But for ext3, the magic command 'quot' doesn't work.

# quot -f /dev/dsk/c3d0p2
/dev/rdsk/c3d0p2:
llseek: Invalid argument

So, I wrote a quick and dirty awk script. It writes out whatever the first file/dir it finds for each  UID.

# cat uniqueUID.awk
BEGIN {i=0;}
{
for(j=0;j<i;j++)
if(uid[j] == $5) break;
if (j == i) {
uid[i] = $5;
line[i] = $0;
i ++;
}
}
END{for(j=0;j<i;j++) print line[j];}
# find /mnt/bipshare/ -ls | awk -f uniqueUID.awk > uniqueUID.out
# head -4 uniqueUID.out
33554432 4 drwxr-xr-x 19 root root 4096 May 2 2006 /mnt/bipshare/
25200129 8 drwxrwx--- 43 1001 bipadmin 4096 Jun 15 1970 /mnt/bipshare/Marketing
41977345 472 -rwxrwx--- 1 1008 support 473088 Dec 10 2004 /mnt/bipshare/Marketing/2003-200406_webDownload All.xls
21004800 36 -rwxrwx--- 1 1014 support 30445 Apr 17 1970 /mnt/bipshare/Marketing/06_Event/Event_2006/SSS_Speakers.sxc


Now, create users.

bash-3.00# awk '{print $5}' uniqueUID.out | while read line; do useradd -u $line user$line;done

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

The views expressed on this blog are my own and do not necessarily reflect the views of Oracle.

Search

Archives
« February 2015
SunMonTueWedThuFriSat
1
2
3
4
6
7
8
10
11
12
14
15
16
20
21
22
24
25
26
27
28
       
       
Today