Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script output to file

Status
Not open for further replies.

Stinney

IS-IT--Management
Nov 29, 2004
2,029
US

I use the command: finger `sort /etc/passwd | cut -f1 -d":"` | grep -i log > /userlist.txt

This outputs to the file userlists.txt information as follows:

Login name: XXXXXXXX
Never logged in.
Login name: XXXXXXXX
Last login Mon Mar 7, 2011 on pts/31 from
Login name: XXXXXXX
Last login Mon Aug 12 08:40 on pts/6 from XXX.XXX.XXX.XXX
Login name: XXXXXXXX
Last login Wed Sep 4 21:28 on pts/4 from XXX.XXX.XXX.XXX

I want to put this into a script that I can execute instead of having to enter the command every time (or copy and paste it)

However, when I put this in a script and execute it, it only provides and output of the sorted passwd file on the screen and doesn't write to the file.

So I get this on the screen and nothing else:

root 0 root 0 Super-User
root2 0 root 0 Super-User
daemon 1 other 1
bin 2 bin 2
sys 3 sys 3
adm 4 adm 4 Admin

etc, etc, etc.....

How can I get the command to run correctly and output to the file in a script?

- Stinney
"Scire ubi aliquid invenire possis, ea demum maxima pars eruditionis est"

"To know where to find anything is, after all, the greatest part of education"

 

Define an alias and just type the command:

Code:
alias ulst="sort /etc/passwd |cut -d':' -f1|xargs finger|grep '^Log' >./userlist.txt"
[3eyes]



----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 

Sweeeeeet. Thanks!

- Stinney
"Scire ubi aliquid invenire possis, ea demum maxima pars eruditionis est"

"To know where to find anything is, after all, the greatest part of education"

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top