Operating System - HP-UX
1753725 Members
4621 Online
108799 Solutions
New Discussion юеВ

Re: script to add second email addr to .forward file

 
SOLVED
Go to solution
Guy Humphreys
Valued Contributor

script to add second email addr to .forward file

Hi everyone,

I am a bit of a scripting newbie and wondered if someone could help me with a simple script I need to write.

I need to add a second email address into everyone's .forward file on a HP-UX 10.20 box we have (approx 300 users)

at the moment all they have is their email address joe.bloggs@ourcomp.com I would like to add in a second line:

joe.bloggs@ourothercomp.com after the first line.

I have figured out the logic, read in the current .forward, cut the username out, add the @domainname onto it and paste this back in. But have no idea what the syntax/best way of doing this is.

Many thanks in anticipation

Guy
'If it ain't broke, don't fix it!'
6 REPLIES 6
RAC_1
Honored Contributor

Re: script to add second email addr to .forward file

user=`awk -F "@" '{print $1}'`
echo $user@ourothercomp >> ./.forward

Anil
There is no substitute to HARDWORK
Victor Fridyev
Honored Contributor

Re: script to add second email addr to .forward file

Hi

Try something like this:
#!/usr/bin/sh
find /home -=name .forward | while read FNM; do
user=$(awk -F@ '{print $1}' $FNM)
echo "$user@ourothercomp.com" >> $FNM
done


Entities are not to be multiplied beyond necessity - RTFM
Victor Fridyev
Honored Contributor
Solution

Re: script to add second email addr to .forward file

Oops, sorry
#!/usr/bin/sh
find /home -name .forward | while read FNM; do
user=$(awk -F@ '{print $1}' $FNM)
echo "$user@ourothercomp.com" >> $FNM
done
Entities are not to be multiplied beyond necessity - RTFM
Abdul Rahiman
Esteemed Contributor

Re: script to add second email addr to .forward file

Try this,

ls /home/*/.forward | while read file
do
name=`cat $line | awk -F"@" '{print $1}'`
echo "$name@othercompany.com" >> $file
done
No unix, no fun
harry d brown jr
Honored Contributor

Re: script to add second email addr to .forward file

#!/usr/bin/perl
#
open(listofforwards,"find /home -type f -name '.forward'|");
while() {
$flname=$_;
$val=`cat $flname`;
chomp $val;
($fld1,$fld2) = split(/@/,$val);
$fld1 =~ s/$/\@YOUR_OTHER_DOMAIN/;
$doit=`echo $val > $flname`;
$doit=`echo $fld1 >> $flname`;
}

This assumes that there is ONLY one line in .forward

live free or die
harry
Live Free or Die
Guy Humphreys
Valued Contributor

Re: script to add second email addr to .forward file

Thanks to all for your VERY quick responses, I am always impressed with how quick the ITRC community replies to messages.

I went with Victor's second solution as it seemed the most comprehensible to me, thanks though to all that replied

Cheers
Guy
'If it ain't broke, don't fix it!'