How can I execute a command automagically on Startup?
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How can I execute a command automagically on Startup?
Hi, I have a command to use my XP-PEN graphic tablet properly, but I do not know how to execute the command startup. I'm using Ubuntu 18.04 LTS
there is the command
Create a cron job that will wait for 30 seconds (30 seconds to allow system to finish coming up) after system startup and then will execute the script on the system.
Put your command into a file called postboot.sh in your home directory. You will need to know the full path name to xinput.
To get that enter which xinput
Hi, I have a command to use my XP-PEN graphic tablet properly, but I do not know how to execute the command startup. I'm using Ubuntu 18.04 LTS
there is the command
Since you have the command, you have 95% of what you need already. Put that command into a file of any name you choose (like "XPPenStart", for example), and run "chmod 755 XPPenStart". I'd strongly suggest you put the full path to xinput into the file, such as "/usr/bin/xinput". Save that file in your home directory.
So when you add an application to autostart, just put in your path to the script like "/home/username/XPPenStart".
While the rc.local will work, since this is something that depends on your X session being up and running, it may give you unpredictable results...and I'd not use cron at all, since that would start VERY early, and will depend on you setting up your regular user to be allowed to use cron (it may be already, but it may NOT be as well).
The other way I would recommend only if you have the experience but it is perhaps the most reliable, though the hardest, way. Ubuntu uses systemd. If you can write or find a unit file for the program and know when (after, before, what else needs to be running) you want it to run then you can put the unit file in /etc/systemd/system and enable it. Enabling a unit file is part of systemd. Then it will start as part of the boot process (or try to) regardless of whether you are logged in. I won't give further details because, although you need to know this exists, I don't recommend messing with systemd until you have a good bit of experience or have done a lot more research. If you want to start learning about systemd, just 'man systemd'. It will give you further man pages to refer to if you are brave enough or enjoy hitting yourself on the head with a hammer because it feels so good when you quit. Sorry, my bias is showing.
Actually crontab -e isn't difficult to use. Since you are running this as a user
there should be no issues.
Otakuch,
Create a cron job that will wait for 60 seconds (60 seconds to allow system to finish coming up) after system startup and then will execute the script on the system.
Put your command into a file called postboot.sh in your home directory. You will need to know the full path name to xinput.
To get that enter which xinput
Actually crontab -e isn't difficult to use. Since you are running this as a user there should be no issues.
Never said it wasn't easy to use; I said it wasn't the tool for this particular job, and there could be issues since there are times a 'regular user' *IS NOT ALLOWED* to run cron jobs, and it will have to be enabled, putting extra steps into things when they're just not needed. The Ubuntu desktop already *HAS* a way to auto-execute a script upon a user sign-in, so I can't see a reason NOT to use the existing framework, rather than hit-or-miss with cron to start an X-related app.
Quote:
Otakuch,
Create a cron job that will wait for 60 seconds (60 seconds to allow system to finish coming up) after system startup and then will execute the script on the system.
Put your command into a file called postboot.sh in your home directory. You will need to know the full path name to xinput. To get that enter which xinput
Great; and it'll be wonderful, IF the system comes up within 60 seconds..barring any issues with BTRFS indexing, a forced fsck, etc. And doing a chmod on the file negates the use of the "sh" in the cron line.
Again, cron is not the right tool for this job; the command the OP gave is for an *X RELATED APPLICATION*, and cron is NOT. agillator also brings up systemd, which can be used as well, but their warnings of difficult-to-use are VERY valid.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.