![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Shell script to search for text in a file and copy file | imeadows | UNIX for Dummies Questions & Answers | 9 | 1 Week Ago 06:12 PM |
| script to search a file | dr46014 | Shell Programming and Scripting | 1 | 02-28-2008 03:55 AM |
| Passing data from file to variables for script | screwed718 | Shell Programming and Scripting | 2 | 02-14-2008 04:12 AM |
| File search variables | bbbngowc | Shell Programming and Scripting | 19 | 01-23-2008 08:50 AM |
| search for the contents in many file and print that file using shell script | cdfd123 | Shell Programming and Scripting | 3 | 10-07-2007 07:17 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Code:
IFS=': ' set -- $(grep "$(date +%b%e)" fileX) set -- $(egrep "$2|$3" fileY) mailx -s "You\'re oncall today $(date +%D)" "$2 $4" |
|
#3
|
|||
|
|||
|
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 |
|
#4
|
||||
|
||||
|
Set IFS with single (not back) quotes:
Code:
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% |
|
#5
|
||||
|
||||
|
The date of the input file haven't the same format in your first and last post.
Try (not tested): Code:
IFS=': ' set -- $(grep "$(date +%m/%d/%y)" fileX) set -- $(egrep "$2|$3" fileY) mailx -s "You\'re oncall today $(date +%D)" "$2 $4" |
|
#6
|
||||
|
||||
|
Yes,
of course, Jean-Pierre is right, the date format in the file sould match the grep command. |
|
#7
|
|||
|
|||
|
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 |
|||
| Google The UNIX and Linux Forums |