LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 05-14-2020, 09:46 AM   #1
Otakuch
LQ Newbie
 
Registered: May 2020
Distribution: Gentoo
Posts: 28

Rep: Reputation: Disabled
Question 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
Code:
xinput set-prop "XP-PEN G430S Pen Pen (0)" --type=float "Coordinate Transformation Matrix" 1.155756, 0.000000, 0.000000, 0.000000, 1.529, 0.000000, 0.000000, 0.000000, 1.000000
Thanks in advance
 
Old 05-14-2020, 06:13 PM   #2
elucches
Member
 
Registered: Jan 2011
Posts: 108

Rep: Reputation: 11
Put it in /etc/rc.local.
Using a web search engine will provide you more answers (for example https://linuxtechlab.com/executing-c...pts-at-reboot/).
 
Old 05-14-2020, 06:30 PM   #3
KenUnix
LQ Newbie
 
Registered: Dec 2019
Location: Pennsylvania
Distribution: linuxubuntu
Posts: 28

Rep: Reputation: 6
Otakuch,

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

[path]/xinput set-prop "XP-PEN G430S Pen Pen (0)" --type=float "Coordinate Transformation Matrix" 1.155756, 0.000000, 0.000000, 0.000000, 1.529, 0.000000, 0.000000, 0.000000, 1.000000

To create a cron job, open terminal and run

$ crontab -e

Enter the following line

@reboot ( sleep 30 ; sh /home/[your directory]/postboot.sh )

Save changes and exit.

Test by rebooting system. Hope this helps.

Last edited by KenUnix; 05-14-2020 at 06:44 PM.
 
Old 05-15-2020, 12:17 PM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,634

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by Otakuch View Post
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
Code:
xinput set-prop "XP-PEN G430S Pen Pen (0)" --type=float "Coordinate Transformation Matrix" 1.155756, 0.000000, 0.000000, 0.000000, 1.529, 0.000000, 0.000000, 0.000000, 1.000000
Thanks in advance
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.

Ubuntu already has the ability to auto-start applications when you log in, so that is the most reliable way of doing this:
https://websiteforstudents.com/set-a...u-17-10-18-04/

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).
 
1 members found this post helpful.
Old 05-15-2020, 04:25 PM   #5
agillator
Member
 
Registered: Aug 2016
Distribution: Mint 19.1
Posts: 419

Rep: Reputation: Disabled
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.
 
1 members found this post helpful.
Old 05-15-2020, 04:55 PM   #6
KenUnix
LQ Newbie
 
Registered: Dec 2019
Location: Pennsylvania
Distribution: linuxubuntu
Posts: 28

Rep: Reputation: 6
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

[path]/xinput set-prop "XP-PEN G430S Pen Pen (0)" --type=float "Coordinate Transformation Matrix" 1.155756, 0.000000, 0.000000, 0.000000, 1.529, 0.000000, 0.000000, 0.000000, 1.000000

To create a cron job, open terminal and run

$ crontab -e

Enter the following line

@reboot ( sleep 60 ; sh /home/[your directory]/postboot.sh )

Save changes and exit.


Test by rebooting system. Hope this helps.

If you want to keep a log of what cron did the last boot you can enter it as:

@reboot ( sleep 60 ; sh /home/[your directory]/postboot.sh) 1>/home/[your directory]/log 2>/home/[your directory]/log

This works I use it.
 
Old 05-15-2020, 05:12 PM   #7
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,634

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by KenUnix View Post
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

[path]/xinput set-prop "XP-PEN G430S Pen Pen (0)" --type=float "Coordinate Transformation Matrix" 1.155756, 0.000000, 0.000000, 0.000000, 1.529, 0.000000, 0.000000, 0.000000, 1.000000

To create a cron job, open terminal and run
$ crontab -e

Enter the following line
@reboot ( sleep 60 ; sh /home/[your directory]/postboot.sh )

Save changes and exit. Test by rebooting system. Hope this helps. If you want to keep a log of what cron did the last boot you can enter it as:

@reboot ( sleep 60 ; sh /home/[your directory]/postboot.sh) 1>/home/[your directory]/log 2>/home/[your directory]/log

This works I use it.
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.

::EDIT::
OP, read the LQ Rules; you have apparently started several threads with this same question:
https://www.linuxquestions.org/quest...ts-4175675224/
https://www.linuxquestions.org/quest...ly-4175675255/

...and where you specifically mention cron not working for this (not surprisingly).

Last edited by TB0ne; 05-16-2020 at 08:49 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How can I start a command automagically on Ubuntu 18.04 LTS Otakuch Linux - Newbie 2 05-14-2020 10:50 AM
Execute a command , reboot and then execute another command ganeshp@moris.org Linux - Newbie 3 12-03-2008 12:51 AM
computer switches from static to dhcp address (automagically?) cyberpuerka Linux - Networking 1 09-03-2004 11:29 AM
automagically mount Magneto-Optical Drive? wytiger Fedora 0 07-27-2004 10:56 PM
XMMS has stopped opening pls automagically Steve Cronje Linux - Software 3 05-04-2004 01:07 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:35 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration