LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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, 04:49 AM   #1
ust
Senior Member
 
Registered: Mar 2003
Location: fasdf
Distribution: Debian / Suse /RHEL
Posts: 1,130

Rep: Reputation: 30
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, 06:33 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
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, 07:52 PM   #3
ust
Senior Member
 
Registered: Mar 2003
Location: fasdf
Distribution: Debian / Suse /RHEL
Posts: 1,130

Original Poster
Rep: Reputation: 30
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, 09:19 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,241

Rep: Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325
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, 10:00 PM   #5
ust
Senior Member
 
Registered: Mar 2003
Location: fasdf
Distribution: Debian / Suse /RHEL
Posts: 1,130

Original Poster
Rep: Reputation: 30
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, 10:27 PM   #6
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 02: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 09:17 AM
[SOLVED] dpkg fatal error unable to open files list file Stale NFS file handle cmr26 Linux - Software 5 09-06-2009 05:10 PM
how to pick random file name from a list of filenames in a text file. pdklinux79 Linux - Newbie 9 06-20-2008 03: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 10:47 AM


All times are GMT -5. The time now is 08:23 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration