Ksh script - Design ? - Search file and set variables

Hi -

I'm trying to think of a clever way to write a shell script (trying to stay w/ ksh as that's what I know the best...) that will resolve the following problem:

Problem - On a daily basis I have to email folks who are on-call to remind them. I was hoping to script this out so I could have a file w/ a pattern similiar to:

fileX -
Oct 3:jerry:mark
Oct 4:tim:stan

fileY - jerry:jerry@foo.com
mark:mark@foo.com
tim:tim@foo.com
peter:stan@foo.com

My first idea is to have the script
Set a varaible for the date using something like - 'date |nawk '{print $2 &3}'
Grep fileX searching for date variable - then set variableA with the first name and variableB with the second name for that date - not sure how to do this
Then take variableA and look for a match in fileY - This will set another varialbe - variableZ
Finally, run a mailto command using varialbe Z

Take this script and add it to cron to run daily.

If it's easier, rather than using their names in the file, I can set it up w/ their email addresses - that shouldn't be too much extra work to do.

Any suggestions are greatly appreciated.

Regards,
littlefrog

IFS=':
'
set -- $(grep "$(date +%b%e)" fileX)
set -- $(egrep "$2|$3" fileY)
mailx -s "You\'re oncall today $(date +%D)" "$2 $4"

I may be missing something.. well.. I'm sure I'm missing something.

I tried the suggestion above and tried several combinations, but I don't seem to be capturing the variables correctly. Can you take a look and see if there is anything obvious. - Thanks

>cat dtscript.ksh
#!/bin/ksh

IFS=`:
`
set -- $(grep "$(date +%b%e)" fileX)
set -- $(egrep "$2|$3" fileY)
echo "You are oncall today $(date +%D)" "$2 $4"
#mailx -s "You're oncall today $(date +%D)" "$2 $4"

>cat fileX
10/04/07:jerry:greg

>cat fileY
jerry:jerry@foo.com
greg:grep@foo.com

>./dtscript.ksh
You are oncall today 10/04/07

Set IFS with single (not back) quotes:

zsh 4.3.4% IFS=`:
bquote> `
zsh 4.3.4% set -- $(grep "$(date +%b%e)" fileX)
zsh 4.3.4% set -- $(egrep "$2|$3" fileY)
zsh 4.3.4% echo "You are oncall today $(date +%D)" "$2 $4"
You are oncall today 10/04/07  
zsh 4.3.4% IFS=':
quote> '
zsh 4.3.4% set -- $(grep "$(date +%b%e)" fileX)
zsh 4.3.4% set -- $(egrep "$2|$3" fileY)
zsh 4.3.4% echo "You are oncall today $(date +%D)" "$2 $4"
You are oncall today 10/04/07 jerry@foo.com grep@foo.com
zsh 4.3.4% 

The date of the input file haven't the same format in your first and last post.
Try (not tested):

IFS=':
'
set -- $(grep "$(date +%m/%d/%y)" fileX)
set -- $(egrep "$2|$3" fileY)
mailx -s "You\'re oncall today $(date +%D)" "$2 $4"

Jean-Pierre.

Yes,
of course, Jean-Pierre is right,
the date format in the file sould match the grep command.

Super Thanks!!!!

Both suggestions helped -

I change the tic from ` to ' and switched the date to the format Month day.

Looks Great

One last question -

My mailx command is not working - mailx works - but when I run the script or the mailx command alone, it seems like it's waiting for another input. For example, if I type: mailx -s "this site is great" foo@bar.com and hit enter, I get a new line return and it just sits there until I hit ctrl+D - at which point the line reads 'CC:' - hit Ctrl+D again and the message gets sent.

I looked through the manpages and a few posts on this site, but that seems like the general syntax for the mailx command.

Thanks

Yes,
you can use something like this:

printf "You're oncall today %s\n"  "$(date +%D)"|mailx -s "Some subject here" "$2 $4"

Yea!!!!!

Works like a charm - Thanks!!

PS: Any recommendations for a good scripting (ksh) book / tool to really learn how to script? I have been reading 'learning the korn shell - oreilly'.

Thanks!

I would suggest:

The Korn Shell (Unix and Linux Program Manual) by Anatole Olczak for the Korn Shell.

Shell Scripting Recipes: A Problem-Solution Approach by Chris F.A. Johnson (he contributes to this forum) for the shell scripting approach in general.