Results 1 to 6 of 6
Hi to all.I have this script:
#!/bin/bash
awk -F: '{print $1 "\t" $6}'</etc/passwd
and I want to modify it so that it will print only the login names and the ...
- 07-01-2008 #1Just Joined!
- Join Date
- Jun 2008
- Posts
- 25
Need help with a script..
Hi to all.I have this script:
and I want to modify it so that it will print only the login names and the home directories of the users that are currently logged in the system.#!/bin/bash
awk -F: '{print $1 "\t" $6}'</etc/passwd
Thanks in advance..
- 07-01-2008 #2Linux Guru
- Join Date
- Nov 2004
- Posts
- 6,110
You might want to combine this with the who command. The who command will tell you who is online now. So something that would parse the logged on users then check them against /etc/passwd
That's just rough syntax, you will need to test that yourself. The logged in variable is set as the first token from each line returned by the who command, i.e. the username. This is then grep'd in /etc/passwd and your awk filter is then applied.Code:for loggedin in $(who |awk '{print $1}' do grep $loggedin /etc/passwd |awk -F:'{print $1 "\t"$6}' done
- 07-01-2008 #3Just Joined!
- Join Date
- Jun 2008
- Posts
- 25
Yeap.That's exactly what I need.But now all I need is help with the syntax.
Please..
- 07-01-2008 #4Linux User
- Join Date
- Aug 2006
- Posts
- 458
just awk
Code:awk -F":" 'BEGIN{ "who -q" | getline line} { user[$1]=$6 } END { n=split(line,l," ") for(p=1; p<=n; p++ ) { print l[p],user[l[p]] } }' /etc/passwd
- 07-01-2008 #5Just Joined!
- Join Date
- Jun 2008
- Posts
- 25
Thanks my friend.It works like a charm.It is exactly what I need.
- 07-01-2008 #6Linux Guru
- Join Date
- Nov 2004
- Posts
- 6,110


Reply With Quote
