General discussion

Locked

Shell script to clear file from homedirs

By julie.schneider ·
Hello,
What's the best way to write a shell script to clear a file (procmail.log) from all users' home directories?
Can I use a shell script or do I need perl?
Thanks in advance.

This conversation is currently closed to new comments.

7 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Shell script to clear file from homedirs

by ryttinch In reply to Shell script to clear fil ...

Try something like the following if you want to just do a quick shell script:

#!/bin/sh

OUTPUTFILE=/tmp/procmail.log.output

for i in `awk -F: '{print $6}' /etc/passwd`
do
rm $i/procmail.log 2>> $OUTPUTFILE
echo $i/procmail.log removed >>$OUTPUTFILE
done


That should do what you're looking for (parsing the /etc/passwd file for the home directories, then deleting the procmail.log file from the home directories that it parses).

Hope this helps,


Chad Rytting

Collapse -

Shell script to clear file from homedirs

by julie.schneider In reply to Shell script to clear fil ...

Poster rated this answer

Collapse -

Shell script to clear file from homedirs

by ken.cunningham In reply to Shell script to clear fil ...

Assuming all your users' home directories are under one particular mount point or similar, the easiest way might be simply to execute a find for the files in question from the directory above the home directories, and execute an rm on those discovered. This should do the trick:

cd <path of directory above home dirs>
find . -name 'procmail.log' -exec rm {} \;

This, of course, assumes that the files should be deleted and not merely truncated! Hope this helps

Collapse -

Shell script to clear file from homedirs

by julie.schneider In reply to Shell script to clear fil ...

Thanks, Ken,
This worked great.

Collapse -

Shell script to clear file from homedirs

by insatiable In reply to Shell script to clear fil ...

You shouldn't need perl. I just posted this on another question, but it can be used in your case, also, modified to hit all user home directories.

This script is from a Unix Guru daily tip. The script will zero out a .log file. I keep it in my directory and just change the log file.

for object in procmail.log
do
> $object
print "$object has been zeroed!"
done

Good luck!
Melissa

Collapse -

Shell script to clear file from homedirs

by julie.schneider In reply to Shell script to clear fil ...

Poster rated this answer

Collapse -

Shell script to clear file from homedirs

by julie.schneider In reply to Shell script to clear fil ...

This question was closed by the author

Back to Linux Forum
7 total posts (Page 1 of 1)  

Related Discussions

Related Forums