Results 1 to 10 of 16
Can someone lead me how to do this. I have a bunch of users having .qmail in their home directory. How can I grep or cat whats inside in each ...
- 01-04-2008 #1Linux Newbie
- Join Date
- Mar 2006
- Posts
- 101
how to grep all users's certain file
Can someone lead me how to do this. I have a bunch of users having .qmail in their home directory. How can I grep or cat whats inside in each of the user's .qmail file? I'm thinking of a bash script with 'for' syntax. Here is the sample:
Now that I got all the list of users, didn't know how to cat/grep the .qmail file in each users. Please advise.#!/bin/bash
users=`cat /etc/passwd | awk -F: '{print $1}'`
for id in $users
do
cd ~$id/ | cat .qmail
done
Thanks!
- 01-04-2008 #2Code:
cat $(IFS=$'\n';printf "%s/.qmail " $(cut -d: -f6 /etc/passwd)) 2>&-
- 01-04-2008 #3
Actually, packets was very, very close to the solution on his own. Just make one tiny adjustment:
Code:#!/bin/bash users=`cat /etc/passwd | awk -F: '{print $1}'` for id in $users do cd ~$id/ cat .qmail done--
Bill
Old age and treachery will overcome youth and skill.
- 01-04-2008 #4
Why bother to cd into the directory?
Code:#!/bin/bash users=`cat /etc/passwd | awk -F: '{print $1}'` for id in $users do cat ~$id/.qmail doneLinux User #453176
- 01-04-2008 #5Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
And using cat is redundant, awk is sufficient:
RegardsCode:#!/bin/bash awk -F: '{print $1}' /etc/passwd | while read id do cat ~$id/.qmail done
- 01-04-2008 #6
You don't have to cd to the directory. There are all sorts of ways to do what he wants to do. I'm guessing that part of his question was "what's wrong with this script?", and I wanted to give him the minumum necessary to fix it, so that he could tell what was wrong with it, and thus learn a bit more about shell scripting.
--
Bill
Old age and treachery will overcome youth and skill.
- 01-04-2008 #7Correct. But when he saidAnd using cat is redundant, awk is sufficient
I'm guessing he wasn't asking, "which tool should I use to examine the data?" I'm guessing that he was asking, "Given a particular tool, how do I access the data?" So my extremely simple fix to his script was what I figure was necessary to send him on his way as a happy camper.How can I grep or cat whats inside--
Bill
Old age and treachery will overcome youth and skill.
- 01-04-2008 #8Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
- 01-04-2008 #9
Oh, I knew that. :)
It's just that the two of us read differently what he wants. Between the two of us, I'm sure if he doesn't have what he wants, he'll speak up.
Such is the magic of electrons and stuff.--
Bill
Old age and treachery will overcome youth and skill.
- 01-05-2008 #10Linux Newbie
- Join Date
- Mar 2006
- Posts
- 101
Sorry for not replying.
I tried all the script but all it says is:
cat: ~nelsonts/.qmail: No such file or directory
My home directory nelsonts has .qmail file with ./Maildir/ in it. The reason why I doing this is I want to get all the users and those users that are not active. I would know fast if I can check inside those .qmail files


Reply With Quote
