mapping userid to an email in script

i have about 20 different users submitting a web form that executes a unix script in the background that sets EXECUTIONUSER to their unix id. i would like to use $EXECUTIONUSER to set their email address as EMAILADDR. of course their unix id does not match their email name either. for example:

if [ "$EXECUTIONUSER" = "unixid1" ]; then
EMAILADDR="1user@domain.com"
fi

the above could be done for each user but that seems kind of elementary. any crafty suggestions? thanx in advance.

using *sh, you could use a 'for' loop, but it's gonna loop each item. :frowning:

I suggest you create your own function, that would exit as it matches the right item.
it's a bit like a script: it takes arguments/parameters
it's a bit like a 'for' loop: you have to make it "re-call" itself with shifted args...
this is recursive function. (is it?)

Hi

  1. Create a file in which you map user-id with email ids as shown below:
# cat file
12 abc@unix.com
23 xyz@unix.com
54 efg@unix.com
#
  1. In the code use this file to get the appropriate email id.
#EUSER=12
# EMAIL=`awk '$1=='$EUSER'{print $2}' file`
# echo $EMAIL
abc@unix.com
#

Guru.

1 Like

thanks for the response! this was pretty easy to implement as i already had a file with email addresses in it for the drop down on the web form. so i simply used your suggestion to put the unix id in front of the email address. i then used a variation of your code to set the EMAIL variable. thank again.

EMAIL=`cat file | grep $EUSER | awk '{print $2}'`