Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exporting sendmail users?

Status
Not open for further replies.

flypoo

MIS
Mar 22, 2005
44
AU
any of you linux gurus know if i can export data from sendmail into a file such as a CSV file?

I have been asked to come up with a solution to update our internal MS address books automatically. I said 'gimme $10000', they said no, so looking for a poor-mans solution.

Cheers
 
what kind of data from sendmail? You mean the user aliases database?

 
Since this post I have created an access database and started manually entering in user info...long way to go yet. Yeah, I guess the aliases or the virtual user table is what I would want to export. Ultimately I would like to export each new user I create into the access database, and delete users from database as I delete them from sendmail. Otherwise some sort of script that I can trigger with cron or something. I have created a web-front that users can use to search the access database.

Thanks

P.S. Any critisism or better ideas of this addressbook idea are welcome. Users use MS Outlook. I would rather not buy one of those third party shared folder servers.
 
It's a very simple database with 1 table and 4 fields. Name, Email, Mobile, Extension.

All I really need to export is the linux username and email address.
 
and what is the format of the email address? linux_user@company.com? or you have virtual users?

Cheers.
 
I think this is what you want

cat virtusertable | awk {'print $1","$2'} > virtualusertable.csv

 
hey thanks for that, but no joy. I see what the command is sposed to do and that is pretty much exactly what I want. This is the output of the command (redhat 7.1)

[root@mail mail]# cat virtusertable | awk {`print $1","$2`} > virtualusertable.csv
bash: print: command not found
Usage: awk [POSIX or GNU style options] -f progfile [--] file ...
Usage: awk [POSIX or GNU style options] [--] 'program' file ...
POSIX options: GNU long options:
-f progfile --file=progfile
-F fs --field-separator=fs
-v var=val --assign=var=val
-m[fr] val
-W compat --compat
-W copyleft --copyleft
-W copyright --copyright
-W dump-variables[=file] --dump-variables[=file]
-W gen-po --gen-po
-W help --help
-W lint[=fatal] --lint[=fatal]
-W lint-old --lint-old
-W non-decimal-data --non-decimal-data
-W profile[=file] --profile[=file]
-W posix --posix
-W re-interval --re-interval
-W source=program-text --source=program-text
-W traditional --traditional
-W usage --usage
-W version --version

To report bugs, see node `Bugs' in `gawk.info', which is
section `Reporting Problems and Bugs' in the printed version.


Have I got the syntax right? I am using `print not 'print. If I use ' then the output is..

[root@mail mail]# cat virtusertable | awk {'print $1","$2'} > virtualusertable.csv
awk: cmd. line:1: print $1","$2
awk: cmd. line:1: ^ parse error


Thanks for your time.
 
try this 2 ways:

[tt]
cat virtusertable | awk '{printf $1","$2}' > virtualusertable.csv

-OR-

cat virtusertable | awk '{printf("%s,%s\n",$1,$2)}' > virtualusertable.csv

[/tt]
 
If the field separator is a space or white character then try this:

cat virtusertable | awk '{print $1,$2}' > virtualusertable.csv

You do not need to the qoutes. If the field separator is something else like a :, such as in /etc/passwd. Then add -F: after the awk command.
 
Thanks heaps everyone. Chacalinc, your second line worked for me. Thanks again.
 
One more question,

How do I get AWK to 'ignore any line before line 26' or 'ignore every line before the line that has the text "users" in field $1"

I have spend hours trying to get it to do this so I don't have to bother you guys, but no luck...

I decided to export /etc/passwd instead of virtusers, which works fine with..

cat /etc/passwd | awk '{printf("%s,%s\n",$5,$1"@domain.com")}' > emails.csv

This gives me a csv file with users full name in first column and the email address in the second column. But I don't want the first 26 lines. Line 26 has the word "users" in field 1. Underneath that is all the users.

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top