I have taken all active user list and passing it to below code
Code:
for i in $(cat sample.out)
do
finger ${usr}> report.txt
done
I got below O/P
Code:
Login Name TTY Idle When Where
de4s1 john console 111d Fri 03:00
efr56 Marry pts/105 1:32 Thu 11:07 remnjk26er3
er3v3 Scott pts/74 18 Thu 12:20 remnjk26er3
mki2d Patty pts/102 17 Thu 12:22 remnjk26er3
But is I harcode the finger command like
Code:
for i in $(cat sample.out)
do
finger erdbn > report.txt
done
getting below O/P
Code:
Login name: erdbn In real life:
Directory: /export/home/erdbn remnjk26er3
Shell: /bin/ksh
On since Feb 20 12:30:09 on pts/4 from 1 minute 55 seconds Idle Time
Mail last read Sat Feb 1 15:25:28 2014
No Plan.
Moderator's Comments:
This posting was originally posted as a follow up to a related thread. A new thread was created because this is a new issue.
Last edited by Don Cragun; 02-19-2014 at 11:06 PM..
Reason: Explain creation of new thread.
I have taken all active user list and passing it to below code
Code:
for i in $(cat sample.out)
do
finger ${usr}> report.txt
done
I got below O/P
Code:
Login Name TTY Idle When Where
de4s1 john console 111d Fri 03:00
efr56 Marry pts/105 1:32 Thu 11:07 remnjk26er3
er3v3 Scott pts/74 18 Thu 12:20 remnjk26er3
mki2d Patty pts/102 17 Thu 12:22 remnjk26er3
But is I harcode the finger command like
Code:
for i in $(cat sample.out)
do
finger erdbn > report.txt
done
getting below O/P
Code:
Login name: erdbn In real life:
Directory: /export/home/erdbn remnjk26er3
Shell: /bin/ksh
On since Feb 20 12:30:09 on pts/4 from 1 minute 55 seconds Idle Time
Mail last read Sat Feb 1 15:25:28 2014
No Plan.
Moderator's Comments:
This posting was originally posted as a follow up to a related thread. A new thread was created because this is a new issue.
Was usr an exported variable in the shell that invoked your script? I assume that it was not; so you effectively have a loop that runs the command:
Code:
finger > report.txt
one time for every word in the file sample.out. Each time you invoke this command, the contents of the file report.txt is overwritten. As a wild guess, I would think that the following might come closer to providing the output you were trying to produce:
Code:
> report.txt # Clear output file.
while read -r usr
do finger "$usr" >> report.txt # Add finger report for the user name read from sample.out.
done < sample.out
Last edited by Don Cragun; 02-19-2014 at 11:24 PM..
Reason: Add color to show relationship between read variable name and the argument to finger.
This User Gave Thanks to Don Cragun For This Post:
> report.txt
while read -r usr
do finger "$usr" >> report.txt
done < sample.out
and:
Code:
while read -r `${usr}`
do
finger `${usr}`>> report.txt
done < sample.out
Reading into a variable name (usr) and reading into a variable named by the output of the command substitution of the expansion of a variable name (`${usr}`) are two COMPLETELY different things.
Passing the expansion of a variable name as an argument ("${usr}") and passing the output of the command substitution of the expansion of a variable name (`${usr}`) are two COMPLETELY different things.
Single quotes, back quotes, and double quotes all have meaning to the shell; and they all mean different things. Back quotes and double quotes ARE NOT INTERCHANGEABLE! Please try running the script I suggested (without changing it) and see if the results are different.
And, no, that is not what your script was doing. Your originally posted script executed the command:
Code:
finger > report.txt
once for each word in sample.out. (It sets the variable i to a different word in sample.out each time through the loop, but after setting the variable i, you never referenced it. It never set the variable usr, so the expansion of that variable ($usr) expanded to nothing.)
This User Gave Thanks to Don Cragun For This Post:
Login name: chaos , In real life: ???
Login name: rfr01 , In real life: ???
Login name: cke05 , In real life: ???
Login name: dma83 , In real life: ???
Login name: fmo01 , In real life: ???
Login name: jby05 , In real life: ???
---------- Post updated 02-20-14 at 12:28 AM ---------- Previous update was 02-19-14 at 11:59 PM ----------
I got it what blunder I done. Now its reading correctly. Thanks for your help.
Login name: chaos , In real life: ???
Login name: rfr01 , In real life: ???
Login name: cke05 , In real life: ???
Login name: dma83 , In real life: ???
Login name: fmo01 , In real life: ???
Login name: jby05 , In real life: ???
The trace output shown above does not match the contents of report.txt shown above! (The login names shown in the output do not match the arguments passed to finger in the trace.)
But, it is obvious that your input file contains data with lines in the following format:
Code:
<login-ID><space><comma>
rather than lines with the format:
Code:
<login-ID>
which was what I expected when you said you had an active user list.
Change the:
Code:
while read -r usr
in the script to:
Code:
while read -r usr junk
and then try running the script again.
This User Gave Thanks to Don Cragun For This Post:
Actually when I taken the active users I passes the O/P with comma
Code:
34frb,
se3r4,
34d2w,
that was the cause for the error. I corrected it. Thanks
---------- Post updated at 01:18 AM ---------- Previous update was at 01:08 AM ----------
Hi Don,
I have text file like
Code:
Login name: jro02 In real life: ???
Login name: gco45 In real life: ???
Login name: gma05 In real life: ???
Login name: abe96 In real life: Directory: /export/home/abe96 Shell: /bin/ksh
Last login Fri Feb 14 2014 11:16 on pts/56 from redbftyu45No unread mail
No Plan.
Login name: kna51 In real life: Directory: /export/home/kna51 Shell: /bin/ksh
Last login Wed Aug 7, 2013 on pts/111
No unread mail
No Plan.
Login name: 34e34 In real life: Directory: /export/home/34e34 Shell: /bin/ksh
On since Feb 20 2014 12:19:08 on pts/24 from revbf43dbhtty4 hours 5 minutes Idle Time
Login name: ttr17 In real life: ???
Login name: van03 In real life: ???
Login name: 4rtge In real life:Directory: /export/home/4rtge Shell: /bin/ksh
On since Feb 20 2014 11:26:13 on pts/11 from revbf43dbhtty33 minutes Idle Time
No unread mail
if you see above the file contains both recent active user (2014 logged on date) and last year logon date user
so I want to only take their last logon details
so I have written below command
Code:
if [grep 'Login name:' report.txt};
then
count from Login name line till +2 (Lastlogin or Onsince) > newfile.txt
else
dont pass to newfile.txt
Here I want to know how I can increment line from Login name: then goto next two line.
Hi
Does anyone know if there is anyway of doing the finger command for all user id's in my enviroment. What I need to obtain is the full names of all users on the system.
I know if i do the finger command with no arguments it will list users currently logged in, but i need all users...
... (2 Replies)
Two things : On the first place i am really desperate, on the second i am about to throw my laptop away to the recycle bin in a while.
Ok now that i expressed my feeling let me describe you this mad situation.
Code:
print $1;
("finger -m " $1 "| head -1") | getline userinfo
print... (6 Replies)
I want to know the correct version of how i should use the finger command in this example below.(os is debian lenny)
(nymserver.pl is located in /home/nymserv directory.)
the two versions are :
(in/etc/inetd.conf)
finger stream tcp nowait nymuser /usr/nym/nymserv nymserv... (3 Replies)
Is there any possible way to get rid of the header when I do finger ?
I want to get rid of
Login Name Tty Idle Login Time Office Office Phone
as the header.
Please let me know how to do it. (2 Replies)
Hi,
iam using sunsolaris.
when you type finger command -- it dispalys information about local and remote users.
but here it shows as can't stat /dev/gold:8664
can anybody help what is the solution for this error.
previously the output came.
thanks,
shan (1 Reply)
Hello all,
Here is what I am trying to do. If a user exist, then send an echo "EXIST" or else "DOES NOT EXIST". (under HP-UX)
Kind of:
#!/usr/bin/sh
USER=mylogin
finger $USER
if $? = 0
then
echo "EXIST""
else
echo "DOES NOT EXIST"
fi (10 Replies)
Hey, I was wondering If anybody knew of a way to make a log of all users who type the command finger username when username is my own.
I would like to see who is keeping track of me :)
Thanks (3 Replies)
is there a way to show information on all the users on your system? when i use 'finger' is only shows users names and info who are currently on the system. is there a way to show all accounts? thanx! (5 Replies)
Hi, I've been using unix at college for a few weeks now and I have come up against a few stumbling blocks:
- Most unix commands seem to work w/ regexps - the computers I and my group are allowed to logon to are all itsunXX where XX is a number. if I can {finger @itsun88} to find out that I and... (1 Reply)