Re: for loop and sed

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: Craig White
Date:  
To: nathan, Main PLUG discussion list
Subject: Re: for loop and sed
On Thu, 2006-09-07 at 16:06 -0700, Nathan England wrote:
> I have about 50 users in /home
> I want to create a cron job for each user that will run sa-learn on a spam
> file. I have it properly setup for my user, but I want to copy that to each
> other user, then use sed to replace my user name in each file with the proper
> user name.
>
> I did this
>
> for user in '/bin/ls /home'; do
> cp /var/spool/cron/nengland /var/spool/cron/$user
> sed -i 's/nengland/$user/' $user
> chown $user $user
> done
>
> While it worked, instead of replacing nengland with the username, it literally
> replaced it with '$user'

----
why run all of those cron jobs separately?

# cat spam
#!/bin/sh
LEARN="/usr/bin/sa-learn"
HOME_FOLDER="/home/users"
MAIL="mail"
USERS="/root/scripts/users-spam-check"
SHELL="/bin/sh"
SPAM="SPAM-learn"
HAM="SPAM-not"

for i in `cat $USERS`; \
do su - $i -s $SHELL -c "$LEARN --mbox --spam
$HOME_FOLDER/$i/$MAIL/$SPAM"; \
su - $i -s $SHELL -c "$LEARN --mbox --ham $HOME_FOLDER/$i/$MAIL/$HAM"; \
cat /dev/null > $HOME_FOLDER/$i/$MAIL/$SPAM; \
cat /dev/null > $HOME_FOLDER/$i/$MAIL/$HAM; \
done

Craig

---------------------------------------------------
PLUG-discuss mailing list -
To subscribe, unsubscribe, or to change you mail settings:
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss