Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.user > #258371

Re: How to run a command / script on startup automatically in linux?

From Greg Wooledge <greg@wooledge.org>
Newsgroups linux.debian.user
Subject Re: How to run a command / script on startup automatically in linux?
Date 2023-05-15 19:50 +0200
Message-ID <GvKuB-97vG-3@gated-at.bofh.it> (permalink)
References <GvKkV-97s9-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Mon, May 15, 2023 at 10:44:37PM +0530, Susmita/Rajib wrote:
> 
> I saved a file at "/etc/systemd/system/" named "rc-local.service" with
> the following lines:
> ------------------------------------------------

There's no need to do that.  Debian already ships an rc-local.service.

All you need to do is create an /etc/rc.local file, make it executable,
and make sure it's a valid shell script (with a shebang and all that).

> I also added the line in the file /etc/rc.local:
> mousepad

Make sure /etc/rc.local is executable, and has a #!/bin/sh header line.

Beyond that, I am not familiar with "mousepad".  It doesn't sound like
the kind of program that can be run as a background service daemon.
What does it actually do?  Does it interact with X11 in some way?  If
it does, then this is not the place to launch it.

> But the program doesn't launch at startup. Where I am going wrong?
> Does it fail to start because the command is run before the GUI starts
> up?

If it's GUI-related, then yes.  You can't do this from rc.local.

> I don't want to use cron by editing crontab -e. I tried @reboot
> mousepad, but doesn't work.

If it's GUI-related, you can't do it from crontab either.

A GUI-related program has to be run after you launch your GUI session.
Traditionally, this is accomplished by adding it to your .xsession file,
if you wrote your own .xsession file.  But most Desktop Environment
users don't do that.  They don't have a personal .xsession file at all.

Debian created another file called .xsessionrc which you can use instead,
even if your don't use an .xsession file.

So, here's what I'd suggest:

1) Get rid of your /etc/systemd/system/rc-local.service file.  It's not
   needed, and will just cause confusion.

2) Create a ~/.xsessionrc file containing the commands you want to run
   while starting your X session.

3) Double-check that this "mousepad" command can be run in the way you're
   running it.  Does it self-background?  If not, then you need to put
   an ampersand after it:

   mousepad &

See also: https://wiki.debian.org/Xsession

Back to linux.debian.user | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

How to run a command / script on startup automatically in linux? "Susmita/Rajib" <bkpsusmitaa@gmail.com> - 2023-05-15 19:40 +0200
  Re: How to run a command / script on startup automatically in linux? Greg Wooledge <greg@wooledge.org> - 2023-05-15 19:50 +0200
    Re: How to run a command / script on startup automatically in  linux? Charles Curley <charlescurley@charlescurley.com> - 2023-05-15 20:50 +0200
      Re: How to run a command / script on startup automatically in linux? Greg Wooledge <greg@wooledge.org> - 2023-05-15 21:00 +0200
        Re: How to run a command / script on startup automatically in linux? <tomas@tuxteam.de> - 2023-05-16 06:30 +0200
    Re: How to run a command / script on startup automatically in linux? Vincent Lefevre <vincent@vinc17.net> - 2023-05-15 21:40 +0200
      Re: How to run a command / script on startup automatically in linux? Greg Wooledge <greg@wooledge.org> - 2023-05-15 22:00 +0200
        Re: How to run a command / script on startup automatically in linux? Vincent Lefevre <vincent@vinc17.net> - 2023-05-15 23:10 +0200
          Editing /etc/rc.local [was: How to run a command / script on startup  automatically in linux?] <tomas@tuxteam.de> - 2023-05-16 06:40 +0200
            Re: Editing /etc/rc.local [was: How to run a command / script on  startup automatically in linux?] Vincent Lefevre <vincent@vinc17.net> - 2023-05-16 11:50 +0200
  Re: How to run a command / script on startup automatically in  linux? Charles Curley <charlescurley@charlescurley.com> - 2023-05-15 20:00 +0200
    Re: How to run a command / script on startup automatically in linux? Max Nikulin <manikulin@gmail.com> - 2023-05-16 04:40 +0200
      Re: How to run a command / script on startup automatically in linux? Max Nikulin <manikulin@gmail.com> - 2023-05-16 09:10 +0200
  Re: How to run a command / script on startup automatically in linux? Christoph Brinkhaus <c.brinkhaus@t-online.de> - 2023-05-15 20:10 +0200
  Re: How to run a command / script on startup automatically in linux? <tomas@tuxteam.de> - 2023-05-15 20:30 +0200
    Re: How to run a command / script on startup automatically in  linux? Charles Curley <charlescurley@charlescurley.com> - 2023-05-15 20:50 +0200
    Re: How to run a command / script on startup automatically in  linux? Joe <joe@jretrading.com> - 2023-05-15 21:40 +0200
  Re: How to run a command / script on startup automatically in linux? "Susmita/Rajib" <bkpsusmitaa@gmail.com> - 2023-05-16 07:50 +0200
    Re: How to run a command / script on startup automatically in linux? Vincent Lefevre <vincent@vinc17.net> - 2023-05-16 12:10 +0200
    Re: How to run a command / script on startup automatically in linux? Greg Wooledge <greg@wooledge.org> - 2023-05-16 13:20 +0200
    Re: How to run a command / script on startup automatically in linux? "Susmita/Rajib" <bkpsusmitaa@gmail.com> - 2023-05-16 14:10 +0200
      Re: How to run a command / script on startup automatically in linux? "Susmita/Rajib" <bkpsusmitaa@gmail.com> - 2023-05-18 08:10 +0200

csiph-web