Quantcast
Channel: UNIX and Linux Forums
Viewing all articles
Browse latest Browse all 16232

Bashrc File - Conditional Command Execution?

$
0
0
Hello All,

I was wondering if there is a way to execute a command in my ".bashrc" file based on how I logged into the PC?

I was thinking maybe there is a way to check how the user (*myself) logged in, maybe somehow with the who command along with something else, but I'm not sure... I know I could run who and then check to see if there is a remote user logged in, but I didn't see a way of proving that the remote user shown in the who command's output was me or not?

I know I could do this below, but there could also be other user's remotely logged in, or multiple terminals open, etc... So I couldn't just say something like, "If there is an IP Address found in the 'who' commands output, then I'm a remote user...."
Code:

# who
user1 :0          2014-07-08 00:00 (console)
user1 pts/0        2015-02-10 10:47 (:0.0)
user2 pts/1        2015-02-10 12:01 (192.168.123.789)
user1 pts/2        2015-02-10 10:55 (:0.0)
user1 pts/3        2015-02-10 10:56 (:0.0)
user2 pts/4        2015-02-10 12:28 (192.168.123.456)      <--**** THIS IS ME ****

So I guess, is there anyway to tell that user2 in the output above is myself? Maybe by finding out which pts I'm using..?

Could anyone point me in the right direction on where I should/could start with finding this out..? Any thoughts or suggestions would be greatly appreciated!

Thanks in Advance,
Matt



********** EDIT **********
I think I may have found something in Google'ing around a bit more...
I knew of the "who", "whoami", "w", "users" commands but I had never seen the "who am i" command (*with Spaces) which printed the following:
Code:

# who am i
user2    pts/4        2015-02-10 12:28  (192.168.123.456)

So I guess I'll see if I can give this a try...

Viewing all articles
Browse latest Browse all 16232

Trending Articles