mass .procmailrc change

i need to add the following line to all users .procmailrc file
:0c
! username@alternate_domain.com

Is there a way to insert their username in the above and then add the line to .procmailrc in each users folder?

Theres got to be a way to do this with a script.
Any help would be great.
havesum2Asked:
Who is Participating?
 
tty2Connect With a Mentor Commented:
You didn't change current directory to users $HOME in the beginning

cd /home/t/tty2

"md" is an alias for "mkdir" in my system, always forget about this. But you may drop this line, due to "mkdir -p ..." below.
0
 
tty2Commented:
cd /home
for i in *; do find $i -name .procmailrc -exec echo ":0c" >> '{}' \; -exec echo "! $i@alternate_domain.com" >> '{}' \; ; done
0
 
havesum2Author Commented:
didnt seem to change anything
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
tty2Commented:
Files ".procmailc" was found at all? Check

cd /home
for i in *; do find $i -name .procmailrc; done

If yes, these ".procmailrc" are writable? Check

echo ":0c" >> <some_dir_in_home>/.promailrc

Are you doing this as root?
0
 
havesum2Author Commented:
cd /home
for i in *; do find $i -name .procmailrc; done

gives me
1/1234/.procmailrc
1/11111/.procmailrc
2/2bbyd/.procmailrc

running entire script does nothing
running as root
0
 
tty2Commented:
Try another version:

for i in *; do find $i -name .procmailrc -exec sh -c "echo -e \":0c\n! $i@alternate_domain.com\" >> '{}'" \; ; done

One remark: usually .procmailrc is located at user's homedir, which is, usually, is located in "/home", and its name is the same as login. Thus, "$i@alternate_domain.com" will be writen to .procmail as "<dirname>@alternate_domain.com".
Is it what you expect?
0
 
havesum2Author Commented:
my user structure is
/home/t/tty2
0
 
tty2Commented:
Then change directory to /home/t/tty2 before running the script:

cd /home/t/tty2
for i in *; do find $i -name .procmailrc -exec sh -c "echo -e \":0c\n! $i@alternate_domain.com\" >> '{}'" \; ; done
0
 
havesum2Author Commented:
i need to do this for 660 users
0
 
tty2Commented:
Create a copy of directory structure with empty files ".procmailrc" for testing.

cd /home/t/tty2
md /tmp/test
find -type d -exec mkdir -p /tmp/test/'{}' \;
find -name .procmailrc -exec touch /tmp/test/'{}' \;
cd /tmp/test
for i in *; do find $i -name .procmailrc -exec sh -c "echo -e \":0c\n! $i@alternate_domain.com\" >> '{}'" \; ; done
0
 
havesum2Author Commented:
i really appreciate the help
after running the above this is what i get.

mail:/home/a/allen#
mail:/home/a/allen#
mail:/home/a/allen#
mail:/home/a/allen#
mail:/home/a/allen#
mail:/home/a/allen# md /tmp/test
-bash: md: command not found
mail:/home/a/allen# find -type d -exec mkdir -p /tmp/test/'{}' \;
find -name .procmailrc -exec touch /tmp/test/'{}' \;
cd /tmp/test
for i in *; do find $i -name .procmailrc -exec sh -c "echo -e \":0c\n! $i@alternate_domain.com\" >> '{}'" \; ; done
mail:/home/a/allen# find -name .procmailrc -exec touch /tmp/test/'{}' \;
mail:/home/a/allen# cd /tmp/test
mail:/tmp/test# for i in *; do find $i -name .procmailrc -exec sh -c "echo -e \":0c\n! $i@alternate_domain.com\" >> '{}'" \; ; done
find: `New': No such file or directory
find: `directory': No such file or directory
mail:/tmp/test# dir
total 40
drwxr-xr-x 10 root root 4096 2010-03-27 14:20 .
drwxrwxrwt  5 root root 4096 2010-03-27 14:18 ..
drwxr-xr-x  3 root root 4096 2010-03-27 14:18 mail
drwxr-xr-x  2 root root 4096 2010-03-27 14:20 New directory
-rw-r--r--  1 root root    0 2010-03-27 14:20 .procmailrc
drwxr-xr-x  2 root root 4096 2010-03-27 14:20 public_html
drwxr-xr-x  2 root root 4096 2010-03-27 14:18 secures
drwxr-xr-x  2 root root 4096 2010-03-27 14:18 .spamassassin
drwxr-xr-x  2 root root 4096 2010-03-27 14:20 timothydb
drwxr-xr-x  2 root root 4096 2010-03-27 14:18 .tmp
drwxr-xr-x  7 root root 4096 2010-03-27 14:20 .usermin
mail:/tmp/test#

0
All Courses

From novice to tech pro — start learning today.