niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Programming » shell
Match pattern in ksh script
Post new topic   Reply to topic Page 1 of 1 [7 Posts] View previous topic :: View next topic
Author Message
lnrntx@gmail.com
*nix forums beginner


Joined: 13 Jun 2006
Posts: 4

PostPosted: Thu Jul 20, 2006 1:48 am    Post subject: Match pattern in ksh script Reply with quote

Hi All,

I have 2 days to figure this out and a week gone by and I havent yet,
so I dont think im going to without help.

I dont even know how to ask the question. But here goes....

I have a file - File A - with userid and Manager email address.

I have to send a report to each manager in File A identifying each
userid listed beside their name as a user on one or all 20 individual
servers. And request a confirmation that these users still require
access to these servers and that they still need to have the same
groups(GIDs).

I need to know how do I tell my script to read File A and run my other
scripts for each Manager, put the output of my scripts into a file for
that manager and when that managers name change in File A to the next
manager, then repeat the steps that were just completed for the
previous manager.

This is File A:

userid Managers Email
jakley joe.jakley@whereever.com

I thought a while loop would work but don't know how to say --

while somemgrname matches itself
do this
then start over when somemgrname changes.

How do I setup a pattern match when I dont know the name of the
pattern, I have 300+ managers to do this for.

I hope this is clear to you all, because its about as clear as mud for
me.

I appreciate any help advice you can give me, and im already looking
for that other job. LOL

LR
Back to top
base60
*nix forums Guru


Joined: 07 Sep 2005
Posts: 322

PostPosted: Thu Jul 20, 2006 2:49 am    Post subject: Re: Match pattern in ksh script Reply with quote

LR wrote:
Quote:
Hi All,

I have 2 days to figure this out and a week gone by and I havent yet,
so I dont think im going to without help.

I dont even know how to ask the question. But here goes....

I have a file - File A - with userid and Manager email address.

I have to send a report to each manager in File A identifying each
userid listed beside their name as a user on one or all 20 individual
servers. And request a confirmation that these users still require
access to these servers and that they still need to have the same
groups(GIDs).

I need to know how do I tell my script to read File A and run my other
scripts for each Manager, put the output of my scripts into a file for
that manager and when that managers name change in File A to the next
manager, then repeat the steps that were just completed for the
previous manager.

This is File A:

userid Managers Email
jakley joe.jakley@whereever.com

I thought a while loop would work but don't know how to say --

while somemgrname matches itself
do this
then start over when somemgrname changes.

How do I setup a pattern match when I dont know the name of the
pattern, I have 300+ managers to do this for.

The description of what you're trying to do is a bit difficult
to follow...

That said, it sounds like you might want to read the description
of an associative array. This feature is available in ksh93 --
usually found as /usr/dt/bin/dtksh

Read the file into an associative array using either the userid
or manager's email address as an index and then process the
array.

Quote:

I hope this is clear to you all, because its about as clear as mud for
me.

I appreciate any help advice you can give me, and im already looking
for that other job. LOL

LR
Back to top
Chris F.A. Johnson
*nix forums Guru


Joined: 20 Feb 2005
Posts: 2268

PostPosted: Thu Jul 20, 2006 3:01 am    Post subject: Re: Match pattern in ksh script Reply with quote

On 2006-07-20, LR wrote:
Quote:
Hi All,

I have 2 days to figure this out and a week gone by and I havent yet,
so I dont think im going to without help.

I dont even know how to ask the question. But here goes....

I have a file - File A - with userid and Manager email address.

I have to send a report to each manager in File A identifying each
userid listed beside their name as a user on one or all 20 individual
servers. And request a confirmation that these users still require
access to these servers and that they still need to have the same
groups(GIDs).

I need to know how do I tell my script to read File A and run my other
scripts for each Manager, put the output of my scripts into a file for
that manager and when that managers name change in File A to the next
manager, then repeat the steps that were just completed for the
previous manager.

What do you mean by "when that managers name change in File A"? Is
somthing modifiying the file? Or do you want to read the file line
by line?

Quote:
This is File A:

userid Managers Email
jakley joe.jakley@whereever.com

I thought a while loop would work but don't know how to say --

while somemgrname matches itself
do this
then start over when somemgrname changes.

How do I setup a pattern match when I dont know the name of the
pattern, I have 300+ managers to do this for.

I hope this is clear to you all, because its about as clear as mud for
me.

If this the sort of thing you are looking for?

{
read line ## discard header line
while read mgr email
do
some_script > "$mgr"
done
} < FileA


--
Chris F.A. Johnson, author <http://cfaj.freeshell.org>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
Back to top
lnrntx@gmail.com
*nix forums beginner


Joined: 13 Jun 2006
Posts: 4

PostPosted: Thu Jul 20, 2006 3:47 am    Post subject: Re: Match pattern in ksh script Reply with quote

Thanks, I think this is what I would need. Because I need to read line
by line to grab all the users for that one manager, gather the data to
another file and then go onto the next manager.

Quote:
From reading File A. I would do the read until jsmiths email would no
longer show up and then I would go onto the next manager and write a

new file with the user info.

jblake jsmith@somewhere.com
sutevens jsmith@somewhere.com
kavens jsmith@somewhere.com

Here is the beginning of a new search ..

egaten nnuman@somewhere.com
trivers nnuman@somewhere.com

beginning of a new search...

tjakob krystaly@somewhere.com
.....

But I still dont understand how I am telling the script to execute cmds
per mgrs name?

Thank you for explaining !!!

Chris F.A. Johnson wrote:
Quote:
On 2006-07-20, LR wrote:
Hi All,

I have 2 days to figure this out and a week gone by and I havent yet,
so I dont think im going to without help.

I dont even know how to ask the question. But here goes....

I have a file - File A - with userid and Manager email address.

I have to send a report to each manager in File A identifying each
userid listed beside their name as a user on one or all 20 individual
servers. And request a confirmation that these users still require
access to these servers and that they still need to have the same
groups(GIDs).

I need to know how do I tell my script to read File A and run my other
scripts for each Manager, put the output of my scripts into a file for
that manager and when that managers name change in File A to the next
manager, then repeat the steps that were just completed for the
previous manager.

What do you mean by "when that managers name change in File A"? Is
somthing modifiying the file? Or do you want to read the file line
by line?

This is File A:

userid Managers Email
jakley joe.jakley@whereever.com

I thought a while loop would work but don't know how to say --

while somemgrname matches itself
do this
then start over when somemgrname changes.

How do I setup a pattern match when I dont know the name of the
pattern, I have 300+ managers to do this for.

I hope this is clear to you all, because its about as clear as mud for
me.

If this the sort of thing you are looking for?

{
read line ## discard header line
while read mgr email
do
some_script > "$mgr"
done
} < FileA


--
Chris F.A. Johnson, author <http://cfaj.freeshell.org
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
Back to top
lnrntx@gmail.com
*nix forums beginner


Joined: 13 Jun 2006
Posts: 4

PostPosted: Thu Jul 20, 2006 3:54 am    Post subject: Re: Match pattern in ksh script Reply with quote

I knew my message would be difficult to read, its difficult for me to
express myself when Im confused.

I will have to read more on the associative arrays. But initially it
looks like I would have to define every mgr as a variable in order to
use the associative array. Is this true?

Thank you for explaining further on this!!!!

LR

base60 wrote:
Quote:
LR wrote:
Hi All,

I have 2 days to figure this out and a week gone by and I havent yet,
so I dont think im going to without help.

I dont even know how to ask the question. But here goes....

I have a file - File A - with userid and Manager email address.

I have to send a report to each manager in File A identifying each
userid listed beside their name as a user on one or all 20 individual
servers. And request a confirmation that these users still require
access to these servers and that they still need to have the same
groups(GIDs).

I need to know how do I tell my script to read File A and run my other
scripts for each Manager, put the output of my scripts into a file for
that manager and when that managers name change in File A to the next
manager, then repeat the steps that were just completed for the
previous manager.

This is File A:

userid Managers Email
jakley joe.jakley@whereever.com

I thought a while loop would work but don't know how to say --

while somemgrname matches itself
do this
then start over when somemgrname changes.

How do I setup a pattern match when I dont know the name of the
pattern, I have 300+ managers to do this for.

The description of what you're trying to do is a bit difficult
to follow...

That said, it sounds like you might want to read the description
of an associative array. This feature is available in ksh93 --
usually found as /usr/dt/bin/dtksh

Read the file into an associative array using either the userid
or manager's email address as an index and then process the
array.


I hope this is clear to you all, because its about as clear as mud for
me.

I appreciate any help advice you can give me, and im already looking
for that other job. LOL

LR
Back to top
Chris F.A. Johnson
*nix forums Guru


Joined: 20 Feb 2005
Posts: 2268

PostPosted: Thu Jul 20, 2006 4:10 am    Post subject: Re: Match pattern in ksh script Reply with quote

On 2006-07-20, LR wrote:
Quote:
Chris F.A. Johnson wrote:
On 2006-07-20, LR wrote:
Hi All,

I have 2 days to figure this out and a week gone by and I havent yet,
so I dont think im going to without help.

I dont even know how to ask the question. But here goes....

I have a file - File A - with userid and Manager email address.

I have to send a report to each manager in File A identifying each
userid listed beside their name as a user on one or all 20 individual
servers. And request a confirmation that these users still require
access to these servers and that they still need to have the same
groups(GIDs).

I need to know how do I tell my script to read File A and run my other
scripts for each Manager, put the output of my scripts into a file for
that manager and when that managers name change in File A to the next
manager, then repeat the steps that were just completed for the
previous manager.

What do you mean by "when that managers name change in File A"? Is
somthing modifiying the file? Or do you want to read the file line
by line?

This is File A:

userid Managers Email
jakley joe.jakley@whereever.com

I thought a while loop would work but don't know how to say --

while somemgrname matches itself
do this
then start over when somemgrname changes.

How do I setup a pattern match when I dont know the name of the
pattern, I have 300+ managers to do this for.

I hope this is clear to you all, because its about as clear as mud for
me.

If this the sort of thing you are looking for?

{
read line ## discard header line
while read mgr email
do
some_script > "$mgr"
done
} < FileA

[please don't top post]

Quote:
Thanks, I think this is what I would need. Because I need to read line
by line to grab all the users for that one manager, gather the data to
another file and then go onto the next manager.

From reading File A. I would do the read until jsmiths email would no
longer show up and then I would go onto the next manager and write a
new file with the user info.

jblake jsmith@somewhere.com
sutevens jsmith@somewhere.com
kavens jsmith@somewhere.com

Here is the beginning of a new search ..

egaten nnuman@somewhere.com
trivers nnuman@somewhere.com

beginning of a new search...

tjakob krystaly@somewhere.com
....

But I still dont understand how I am telling the script to execute cmds
per mgrs name?

{
read line ## discard header line
while read user mgr_email
do
some_script "$user" >> "$mgr_email"
done
} < FileA


--
Chris F.A. Johnson, author <http://cfaj.freeshell.org>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
Back to top
Jon LaBadie
*nix forums beginner


Joined: 06 May 2006
Posts: 46

PostPosted: Thu Jul 20, 2006 4:56 am    Post subject: Re: Match pattern in ksh script Reply with quote

LR wrote:
Quote:
Thanks, I think this is what I would need. Because I need to read line
by line to grab all the users for that one manager, gather the data to
another file and then go onto the next manager.

From reading File A. I would do the read until jsmiths email would no
longer show up and then I would go onto the next manager and write a
new file with the user info.

jblake jsmith@somewhere.com
sutevens jsmith@somewhere.com
kavens jsmith@somewhere.com

Here is the beginning of a new search ..

egaten nnuman@somewhere.com
trivers nnuman@somewhere.com

beginning of a new search...

tjakob krystaly@somewhere.com
....

But I still dont understand how I am telling the script to execute cmds
per mgrs name?

Thank you for explaining !!!


Clarification for me first.

If I understand the need, for manager jsmith, you want to do some other
code about jblake, then sutevens, then kavens. The results of these
actions on the three users will be collected, massaged, and then sent
to manager jsmith. After that you will forget all the collected results
and start a new collection about user egaten and trivers, sending their
results to nnuman.

Assuming I have this correct, it is best handled (IMO) if your File A
is sorted by the managers email address to group all of each managers
records together.

The records can then be run through a loop that says "anytime the manager
changes, send the building report to the previous manager and start over".

An incomplete sample:

while read user ManagerEmail
do
if [[ $PreviousManagerEmail != $ManagerEmail ]]
then
# Manager changed, time to send a report and start the next one
# First check if this is the first line.
if [[ $PreviousManagerEmail != "" ]]
then
# maybe something to finish off the report
mailx -s "<some subject>" $PreviousManagerEmail < $ManagerReport
fi
# Setup for next report
PreviousManagerEmail=$ManagerEmail
ManagerName=${ManagerEmail%@*}
ManagerReport=<path_to_directory_for_reports>/${ManagerName}_Report
fi

# process one user
# your code >> $ManagerReport
done < File A

Of course, if I misunderstood the need, ignore the above Smile
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [7 Posts] View previous topic :: View next topic
The time now is Thu Nov 20, 2008 11:51 pm | All times are GMT
navigation Forum index » Programming » shell
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts does squid 2.6 support setting cache_peer port in redirec... Victor Tsang Squid 0 Fri Jul 21, 2006 8:16 am
No new posts mail script eeb4u@hotmail.com shell 3 Fri Jul 21, 2006 5:50 am
No new posts A simple bash script JPB Suse 2 Fri Jul 21, 2006 2:19 am
No new posts Getting started in PXPerl, i.e how to run a script? Markus Hänchen Perl 5 Thu Jul 20, 2006 2:12 pm
No new posts Match lines, group and sum FriesAOLE shell 2 Thu Jul 20, 2006 7:40 am

Mobile Phones | Advertising | Free Ajax Scripts | Charity | Free Advertising
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.2529s ][ Queries: 16 (0.1167s) ][ GZIP on - Debug on ]