1748285 Members
4021 Online
108761 Solutions
New Discussion юеВ

Alias file changes

 
SOLVED
Go to solution
Prashant Zanwar_4
Respected Contributor

Alias file changes

I Have got some mail aliases..say 200. These have got some weired entires, like user have messed them with their names or stuff like that.
Usually they have binded their name with root alias. ie.

root: ,..

Few files are right for root mail alias, like they have
root: email ID for my team.

I want to change files with weired entries.

I have collected all files to my local workstation and push them back. Just trying to think best way to modify these entries...

I have backup of these files with me.
and file names are copies as alias.

Please suggest for changes to be carried.

Thanks and regards
Prashant
"Intellect distinguishes between the possible and the impossible; reason distinguishes between the sensible and the senseless. Even the possible can be senseless."
9 REPLIES 9
Mark Greene_1
Honored Contributor

Re: Alias file changes

If I understand your quetion correctly, you'll want to check the man page for the file /etc/aliases and the newaliases command.

mark
the future will be a lot like now, only later
Geoff Wild
Honored Contributor

Re: Alias file changes

Yes, just vi the file, fix/remove entries, then issue the newaliases command and restart sendmail.

Rgds...Geoff

Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
RAC_1
Honored Contributor

Re: Alias file changes

Did you clear the wrong entries??
Once that is done you can push the files with rcp/scp.

for i in $(ls -1|awk -F . '{print $2}')
# This will get the host name list
do
rcp/scp alias.${i} user@${i}:/etc/mail/
rsh/ssh user@${i} "/usr/sbin/newaliases"
done

Anil
There is no substitute to HARDWORK
Prashant Zanwar_4
Respected Contributor

Re: Alias file changes

I want to make the changes to the files. for 200files I dont want to do a vi. Can something I think of which can change this string for me..
Thanks for replies, I appreciate quick turn up..
Prashant
"Intellect distinguishes between the possible and the impossible; reason distinguishes between the sensible and the senseless. Even the possible can be senseless."
Geoff Wild
Honored Contributor

Re: Alias file changes

You can try with sed

You will have to do it for each string...

THis page of one liners may help you:

http://www-h.eng.cam.ac.uk/help/tpl/unix/sed.html

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Prashant Zanwar_4
Respected Contributor

Re: Alias file changes

is it not possible that, whatever is the string, "root: " I can change to one I want.
sed I have got the same page, will probably work on it more.

I can think of putting # at root: line and putting a new line these.
Any other suggestions, using perl.
Even how to acheive what I think using perl..
Pls reply
Thx
Prashant
"Intellect distinguishes between the possible and the impossible; reason distinguishes between the sensible and the senseless. Even the possible can be senseless."
RAC_1
Honored Contributor

Re: Alias file changes

for i in $(ls -1 alias*)
do
mv ${i} ${i}.bak
sed 's/root/\#root/g' ${i}.bak > $i
echo "root : correct entry" >> $i
done

Anil
There is no substitute to HARDWORK
Ralph Grothe
Honored Contributor
Solution

Re: Alias file changes

You can use the Perl in-place-edit switch -i to automatically have backup copies generated.

e.g.

perl -i.bak -pe 's/root/yokel/' aliases.*


Place in the substitute patterns whatever you need.
Madness, thy name is system administration
Prashant Zanwar_4
Respected Contributor

Re: Alias file changes

is there any way that i can append the file with a string, just after some known string in a file, please suggest.

Thanks and regards
Prashant
"Intellect distinguishes between the possible and the impossible; reason distinguishes between the sensible and the senseless. Even the possible can be senseless."