LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-16-2012, 03:49 AM   #1
ust
Senior Member
 
Registered: Mar 2003
Location: fasdf
Distribution: Debian / Suse /RHEL
Posts: 1,130

Rep: Reputation: 31
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
" "
" "
 
Old 02-16-2012, 05:33 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
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.
 
Old 02-16-2012, 06:52 PM   #3
ust
Senior Member
 
Registered: Mar 2003
Location: fasdf
Distribution: Debian / Suse /RHEL
Posts: 1,130

Original Poster
Rep: Reputation: 31
Quote:
Originally Posted by colucix View Post
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
 
Old 02-16-2012, 08:19 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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.
 
Old 02-16-2012, 09:00 PM   #5
ust
Senior Member
 
Registered: Mar 2003
Location: fasdf
Distribution: Debian / Suse /RHEL
Posts: 1,130

Original Poster
Rep: Reputation: 31
Quote:
Originally Posted by chrism01 View Post
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
 
Old 02-16-2012, 09:27 PM   #6
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
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.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] splitting of comma separated values file (horizontal) into a list (vertical ) list Donoughue Linux - Newbie 3 10-20-2011 01:18 PM
'E:Malformed line 54 in source list /etc/apt/sources.list (dist parse), E:The list of vsssuccess@gmail.com Linux - Desktop 1 11-17-2010 08:17 AM
[SOLVED] dpkg fatal error unable to open files list file Stale NFS file handle cmr26 Linux - Software 5 09-06-2009 04:10 PM
how to pick random file name from a list of filenames in a text file. pdklinux79 Linux - Newbie 9 06-20-2008 02:46 PM
Need to find if a matching file exist from a list of possible file names wit_273 Linux - General 5 10-25-2007 09:47 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:25 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration