[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: How to run automatically a script as soon root login



>> If yes, second dumb question: Coiuld it be ANY script or command?
>> (also running as non-rootuser, like adding "runuser -u myuser
>> command_whatever").

>Root can do this, yes.
Or to be more precise, .bashrc (and any file that's read from it like .bash_aliases) can run anything the bash CLI can run with the same privileges. Of course, anything requiring user input like entering passwords won't work. The same is true for .profile, but with the twist that depending on which shell is reading it, other syntaxes may be possible/required, while .bashrc and similarly named files are pretty much bash-exclusive. So as long as it's something that should run upon login, like setting user-wide environment variables.

> Sorry, dumb question: Depending of the shell, the user is using (let's say, he will use bash), can the script not be added into ~/.bashrc?
.profile is simply more universal. E.g. I'm mounting cloud storage drives through rclone. Since I put the command into .profile, it won't just be run when I log in to the bash shell, but also when I log in to Gnome. I don't think that would be possible with .bashrc.


Best
Richard

Am Mo., 13. Mai 2024 um 18:34 Uhr schrieb <tomas@tuxteam.de>:
On Mon, May 13, 2024 at 06:06:37PM +0200, Hans wrote:
> Am Montag, 13. Mai 2024, 13:24:17 CEST schrieb Greg Wooledge:
> > On Mon, May 13, 2024 at 07:36:07AM +0200, Richard wrote:
> > > .profile
>
> Sorry, dumb question: Depending of the shell, the user is using (let's say, he
> will use bash), can the script not be added into ~/.bashrc?

Yes. Consult your shell's manual. And it will also depend on whether
it is considered to be a "login shell". And on a couple of other
factors.

> If yes, second dumb question: Coiuld it be ANY script or command?
> (also running as non-rootuser, like adding "runuser -u myuser
> command_whatever").

Root can do this, yes.

Cheers
--
t

Reply to: