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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unix Variable not working with: who |wc -l

Status
Not open for further replies.

ZiggyS1

Programmer
Oct 6, 2008
97
CA
Ok... I don't know much about Unix, but I'm trying to do some basic things and learn at the same time....

So below I made up these lines, I can append to the file with this, but I want it on one line, so when the file is run it will log the user count and stamp the date beside it.

who |wc -l >> /home/user1/UserLog3.txt

'date' >> /home/user1/UserLog3.txt


I tried dozens of variations, but can't get anything to work...

This is just one, my brain is hurting so I don't want to relive any of the others lol.

Var1=who |wc -l
Var2='date'
Var3=$Var1$Var2
echo $Var3 >> /home/user1/UserLog3.txt


I know I am mainly hung up on this part...

Var1=who |wc -l and also need some sort of a
"Cat" ?


Thanks

Ziggy


 
Var1=[!]`[/!]who |wc -l[!]`[/!]
Var2=[!]`[/!]date[!]`[/!]
Var3=$Var1$Var2
echo $Var3 >> /home/user1/UserLog3.txt

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PhV,

I'll check tomorrow, I could have sworn I tried the quotes around the WHO also and it returned the literal... but maybe that was double quotes.
 
Hi

ZiggyS1 said:
I could have sworn I tried the quotes around the WHO also and it returned the literal...
That is why PHV not used quotes. Those are backticks. Additionally see "substitution" in your shell's man page.
man bash said:
Command Substitution
Command substitution allows the output of a command to replace the com-
mand name. There are two forms:

$(command)
or
`command`
man mksh said:
Substitution

[gray](...)[/gray]; command substitutions take the form $(command) or (dep-
recated) `command`; [gray](...)[/gray]

Feherke.
 
Thanks again... PHV & Feherke

I have it working now, never used the backtick for anything before.

Just another related question... I'm experimenting with who and finger ...is there a way to identify which system they are connected to? Like the system name, or IP? I need to filter out only users on a specific system.

Eg this gives me the user count: who |wc -l of all systems in use, it's ok if instead of Count the users list

eg just using finger will list the full user name but it gets cut off....if I use finger -l I see the same info for name in the field ....In real life: because in that field we have the name of the other system at the end of the users name.

just point me in the right direction, I'm not looking to make you do all the work.

Thanks

Ziggy
 
I found that the w command will tell me the directory so I can work with that
 
Wow, compared to yesterday...I'm making good progress, the hamster is running full speed....this is what I was after and I think it works great.


App1=`w | grep "/mis/Syst1/pvx/pvx" | wc -l`
Var2=`date`
App2=`w | grep "/w/dlc/bin/_Data" | wc -l`


echo "App1- "$App1" - App2 - "$App2" - Users - "$Var2 >> /home/zig/UserLog
10b.txt



gives me this out put ( appends to file)....

App1 - 52 - App2 - 12 - Users - Tue Apr 6 13:04:03 EDT 2010
App1 - 52 - App2 - 12 - Users - Tue Apr 6 13:04:57 EDT 2010
App1 - 52 - App2 - 12 - Users - Tue Apr 6 13:05:02 EDT 2010
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top