Link to home
Start Free TrialLog in
Avatar of mld4165
mld4165Flag for United States of America

asked on

Multiple Samba Servers - Create a report on smb.conf

Greetings,

I have been tasked with gathering the config information on 100's of servers running Samba.

I need to collect shares, comment info, users, read/write, and path to shares.

smbclient command was my first thought but not all systems have it, or are running older versions. So I'm looking to push a script to all servers and collect the results via email.

This command gives me a start.

grep -i '\[*\]\|path\|valid\|read\|write' /etc/samba/smb.conf | grep -v 'global\|readonly\|home'

Output:
# grep -i '\[*\]\|path\|valid\|read\|write' /etc/samba/smb.conf | grep -v 'global\|readonly\|home'

[testshare]
        path = /testshare
        read only = no
        valid users = DOMAIN.COM\user1
        writeable = yes
[testshare1]
        path = /testshare1
        read only = no
        valid users = DOMAIN.COM\user2
        writeable = yes
[testgroup]
        path = /testgroup
        read only = no
        valid users = @DOMAIN.COM\LinuxLogs
        writeable = yes

I would probably like to get the output in a different format.
testshare(/testshare, ro(user1), rw(user2)), testshare1(/testshare, rw(user2)), testgroup(/testgroup, rw(user1, user2));

I know that is a lot, and on top of that I'm not proficient as I would like to be in awk and sed.

Are there tools or scripts that already exist that might perform this task?

Thanks in advance.
Matt
Avatar of mld4165
mld4165
Flag of United States of America image

ASKER

update:

I piped the output of the grep commands to awk '{printf("%s ",$0)}END{print}' and I am getting closer.

The problem now is the output has tabs in between. Example:
[testshare1]        path = /testshare1        read only = no        valid users = DOMAIN.COM\user2              

Any help would be appreciated.
Avatar of mld4165

ASKER

Still getting closer but think I might be going the wrong way.

grep -i '\[*\]\|path\|valid\|read\|write' /etc/samba/smb.conf | grep -v 'global\|readonly\|home' | awk '{ $1=$1; print }' | awk '{printf("%s, ",$0)}END{print}'

This gives me a lot of the information I want, but not the formatting.

BTW: Systems are RedHat 5.x and up.
Avatar of Daniel McAllister
AWK and SED are both excellent tools for reformatting output -- but only if the input follows identifiable patterns (like the tab delineation.

Please provide the output in the tab-delineated format (that has ALL of the data you want), and then post the same data (say, 5 lines of each) in the format that you would like...

I'll try to then help you with a script to take the input (file or stream) and reformat the results.

Dan
Avatar of mld4165

ASKER

Dan,

I'm working on the reply and hope to post up today.

Thanks
Matt
Avatar of mld4165

ASKER

Dan,

I have been trying to get a clean list out of the smb.conf file with mixed results.

$ grep -i '\[*\]\|path\|valid\|read\|write' /root/smb.conf | grep -v 'global\|readonly\|home\|;' | sed -e 's/^[ \t]*//'

Open in new window

Gives us nice output in a list. The commands I was trying earlier worked fine until I ran them against more complicated files.

Here is the list:
[account]
path = /opt/account
valid users = "domain+user1"
read only = "domain+user2"
write list = "domain+user1"
[account_uploads]
path = /opt/account/send
valid users = @"domain+dbagroup", "domain+user1"
write list = @"domain+dbagroup"
[account_downloads]
path = /opt/account/incoming
valid users = "domain+user1", @"domain+dbagroup", "domain+user3"
write list = "domain+user1"
[ftpbackup]
valid users = "domain+linuxadm", "domain+user1"
writeable = no
[cold]
path = /var/cold
read only = no
valid users = "domain+user3", "domain+svc_docmgmt", "domain+linuxadm", "domain+user1" "domain+user2"
write list = "domain+linuxadm", "domain+svc_docmgmt", "domain+user3"

This is how I would like the final output to look. commas will help import into spreadsheet or table.

account(/opt/account, users(domain+user1),ro(domain+user2), rw(domain+user1)),
account_uploads(/opt/account/send, users(domain+dbagroup, domain+user1), rw(domain+dbagroup)),
account_downloads(/opt/account/incoming, users(domain+user1, domain+dbagroup, domain+user3), rw(domain+user1)),
ftpbackup(users(domain+linuxadm, domain+user1),
cold(/var/cold, users(domain+user3, domain+svc_docmgmt, domain+linuxadm, domain+user1, domain+user2), rw(domain+linuxadm, domain+svc_docmgmt, domain+user3))

Please let me know what you think.

thanks
Matt
Avatar of mld4165

ASKER

I cleaned up the search and with the following line I can output s stream of text that uses a colon to separate the fields.
grep -i '\[*\]\|path\|valid\|read\|write' smb.conf | grep -v 'global\|readonly\|home\|"\|;' | sed s/\"//g | awk '{ $1=$1; print }' | awk '{printf("%s, ",$0)}END{print}'

Open in new window

[account], path = /opt/account, valid users = domain+user1, write list = domain+user1, [account_uploads], path = /opt/account/send, valid users = @domain+dbagroup, domain+user1, write list = @domain+dbagroup, [account_downloads], path = /opt/account/incoming, valid users = domain+user1, @domain+dbagroup, domain+user2, write list = domain+user1, [ftpbackup], valid users = domain+linuxsmb, domain+user1, writeable = no, [cold],path = /var/cold, read only = no, valid users = domain+user3, domain+svc_docmgmt, domain+linuxsmb, domain+user1, write list = domain+linuxsmb, domain+svc_docmgmt, domain+user3, write list = domain+linuxsmb, domain+svc_docmgmt, domain+user3
Avatar of mld4165

ASKER

grep -i '\[*\]\|path\|valid\|read\|write' smb.conf | grep -v 'global\|writeable\|readonly\|read only\|homes\|;' | sed s/\"//g | sed 's/\[/Share=/g' | sed 's/\]//g' | sed 's/path = /path=/' | sed 's/valid users = /ro=/' | sed 's/write list = /rw=/' | sed 's/thig-domain+//gI' | awk '{ $1=$1; print }' | awk '{printf("%s, ",$0)}END{print}'

Open in new window


I said earlier that I used a colon to separate data but it is a comma.

The updated line above does some cleanup and makes changes so I'm getting close.

This is the output:
Share=account, path=/opt/account, ro=user1, rw=user1, Share=account_uploads, path=/opt/account/send, ro=@dbagroup, user1, rw=@dbagroup, Share=account_downloads, path=/opt/account/incoming, ro=user1, @dbagroup, user2, rw=user1, Share=ftpbackup, path=/home/ftpbackup, ro=linuxsmb, user1, Share=cold, path=/var/cold, ro=planet, svc_docmgmt, linuxsmb, user1, user3, rw=linuxsmb, svc_docmgmt, planet, rw=linuxsmb, svc_docmgmt, planet

This is what I am shooting for:
Share=account(/opt/account ,ro(user1), rw(user1))
Share=account_uploads(/opt/account/send, ro(dbagroup, user1), rw(dbagroup))
Share=account_downloads(/opt/account/incoming, ro(user1, dbagroup, user2), rw(user1))
Share=ftpbackup(/home/ftpbackup, ro(linuxadm, user1)
Share=cold(/var/cold, ro(ro=planet, svc_docmgmt, linuxsmb, user1, user3), rw=(linuxsmb, svc_docmgmt, planet, rw=linuxsmb, svc_docmgmt, planet))

Any suggestions?

Thanks!
ASKER CERTIFIED SOLUTION
Avatar of mld4165
mld4165
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mld4165

ASKER

I gave myself an A as I had to solve the issue myself.