Best way to auto-run a cmd in term @ root login? [solved]

All Gurus once were Newbies
Forum rules
There are no such things as "stupid" questions. However if you think your question is a bit stupid, then this is the right place for you to post it. Please stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions prefer the other forums within the support section.
Before you post please read how to get help
Post Reply
lazarus
Level 3
Level 3
Posts: 153
Joined: Mon Jul 02, 2018 11:36 pm
Location: Oberon, OZ

Best way to auto-run a cmd in term @ root login? [solved]

Post by lazarus »

LM 18.3 Cinnamon x64

What I'd like to do is, whenever I log in to the admin account, display the results of

Code: Select all

cat /proc/mdstat
in a terminal automatically. Just a quick'n'easy way to check the status of my RAIDs. Then I can close the terminal and move on to what I logged in for.

But the more I've thought about it the more different ways there seems to be of doing it, some more complicated than others. It has been a long day and now I'm trying to think through porridge.

Ideally it'd only run after login as root, via either GUI or SSH to a plain shell, not any other users.

So... suggestions for best approach for implementation?
Last edited by lazarus on Mon Dec 17, 2018 2:03 am, edited 2 times in total.
- Andy

I may be weird but I'm saving up to become eccentric.
User avatar
xenopeek
Level 24
Level 24
Posts: 24921
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands

Re: Best way to auto-run a cmd in term @ root login?

Post by xenopeek »

You can probably just put that command in /root/.bashrc file, at the end. While the .bashrc file is the startup file for interactive shells (when you open a terminal from GUI, or use su to switch user) and the .profile or .bash_profile file is actually the startup file for login shells (when you login on virtual console as root, or use sudo -i to switch user), normally the .profile file also loads the .bashrc file. So by putting the command in .bashrc file you've captured all cases and for any interactive shell, whether login shell or not, that command will be run.
Image
lazarus
Level 3
Level 3
Posts: 153
Joined: Mon Jul 02, 2018 11:36 pm
Location: Oberon, OZ

Re: Best way to auto-run a cmd in term @ root login?

Post by lazarus »

Thanks.

Not quite what I thought I was looking for, but is certainly simple and serves the same purpose admirably. :)
- Andy

I may be weird but I'm saving up to become eccentric.
Post Reply

Return to “Newbie Questions”