3

I'd like to achieve this: 1) When user (anybody) logs in to tty1, then some specific command(s) will run automatically. 2) When user (anybody) logs in to other tty, then no command(s) will run automatically.

For example: When I log in to tty1, free command will run. I put the commands into .profile file, but it applies to all tty. Is there any solution how to make this possible? Thank you

Ravexina
  • 55,668
  • 25
  • 164
  • 183
WantToLearn
  • 33
  • 1
  • 5

1 Answers1

4

Use a simple condition to determine which tty you are logging into:

if [[ "$(tty)" == "/dev/tty1" ]]
 then
  # do whatever you want here
fi

also if you want to your command get run for all users, instead of .profile put it into /etc/profile.

Ravexina
  • 55,668
  • 25
  • 164
  • 183