LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   list file (https://www.linuxquestions.org/questions/linux-newbie-8/list-file-929649/)

ust 02-16-2012 03:49 AM

list file
 
I use Redhat server , I know each user local directory have a .forward file which re-direct the mail , can advise if I would like to list all the .forward file content and the corresponding user id , just like as below , what can i do ? Thanks.

user id .forward
======== ========
user1 user1@domain.com
user2 user2@domain.com
user3 user3@domain.com
" "
" "

colucix 02-16-2012 05:33 AM

If I understand well the main problem is to retrieve the list of users and their home directories, right? The most straightforward method is to parse the /etc/passwd file using awk. For example, suppose the real (not system) users have ID greater than (or equal to) 500:
Code:

# awk -F: '$3 >= 500 {if ((getline email < ($6 "/.forward")) > 0) print $1, email}' /etc/passwd
You can use the printf statement in place of print to customize/columnize the output. If you want to write down the header, add a print(f) statement in the BEGIN section of awk. Hope this helps.

ust 02-16-2012 06:52 PM

Quote:

Originally Posted by colucix (Post 4603930)
If I understand well the main problem is to retrieve the list of users and their home directories, right? The most straightforward method is to parse the /etc/passwd file using awk. For example, suppose the real (not system) users have ID greater than (or equal to) 500:
Code:

# awk -F: '$3 >= 500 {if ((getline email < ($6 "/.forward")) > 0) print $1, email}' /etc/passwd
You can use the printf statement in place of print to customize/columnize the output. If you want to write down the header, add a print(f) statement in the BEGIN section of awk. Hope this helps.

thx reply,

I tried your method , but no output .

what I would like is just to list all user's .forward content .

thx

chrism01 02-16-2012 08:19 PM

Can I just query
Quote:

I know each user local directory have a .forward file
Although its possible, by default these are not setup on most systems.
In fact its been a long time since I've seen one 'in the wild'
It is normal to have /etc/aliases setup, which is more like a system wide .forward.

ust 02-16-2012 09:00 PM

Quote:

Originally Posted by chrism01 (Post 4604569)
Can I just query

Although its possible, by default these are not setup on most systems.
In fact its been a long time since I've seen one 'in the wild'
It is normal to have /etc/aliases setup, which is more like a system wide .forward.

thx reply ,

No need to worry if the .forward or not , I just would like to know the content of .forward file .

Thx

evo2 02-16-2012 09:27 PM

Hi,

quick and dirty. Assumes user home dirs are in /home:
Code:

cat /home/*/.forward
Or if you want to also print out the file name
Code:

for f in /home/*/.forward ; do echo $f; cat $f ;done
A better approach could involve using some thing like "getent passwd"
to determine the users home directory (similar to coulix's method).

HTH,

Evo2.


All times are GMT -5. The time now is 04:07 PM.