i need to run an xinput something something command on startup. the command itself works. when i create the crontab file (as @reboot xinput or @reboot root xinput set-blah-bla and alot of numbers) it says “installing crontab”, so i assume that everything is fine.
however, on startup the command doesn’t seem to be executed. and if i do syntax check in crontab it says
“-”:2: premature EOF
Invalid crontab file. Syntax issues were found.
It will be a lot easier for people to help if you post the exact contents of the crontab file. When you do that, please use the ‘preformatted text’ option in the post editor to ensure that the content does not get mangled.
i’m not sure if this is the exact contents of the file i end up with, but that’s what i see in the editor and with crontab -l: @reboot xinput set-button-map 14 8 2 3 4 5 6 7 1 9 10 11 12 13 14 15 16 17 18 19 20
ps: or the same, but with @reboot root xinput etc.
Well, this is slighly off the topic, but I don’t think running xinput as the root user during startup of the system is going to have the effect that you desire. It needs to be run inside an X session as the user for whom the changes should take effect, which really means it needs to be run during X startup when you log in and start a graphical session. cron can’t do that for you.
So, realistically it is possible that there is no syntax error at all, and that cron is attempting to run your specified command, but that it doesn’t produce the result that you wanted so it appears that it was not run
so, since we’re on offtopic topic now, what would be the simplest course of action if i need this command to be run on every x startup when i log in and start a graphical session? can i make some sort of script file and feed it to autostart app/setting/tool?
ps: i am extremely new to linux, so there’s that and hence the questioning.
A command running under cron control should be a pure text-mode command, it has it’s standard input from nothing, /dev/null, and writes to e-mail when possible. The xinput interacts with the X-server, so is not suitable for cron use.
One of the most difficult things in Linux is to find a place where to plugin a command for auto-execute, there are so many locations. Sometimes it’s a script, sometimes as .desktop file.
A place you might try to put your xinput script is in /etc/X11/xinit/xinitrc.d, there is a number of scripts with name starting with number and ending with “.sh”.
The scripts are launched after X login, but I cannot promise that this is really the right place. And first try it from foreground in a X-terminal session!
yep. thing is several articles on scripts in linux failed to mention this shebang thing as a must. and even though some do mention it right away i only found it as some poor soul such as myself saying that it helped him in some way.
The use of the shabang is limited to scripts since command line things are done using the current shell unless the user tells the system to use a different environment such as python script which would use python to execute the content of script.
To learn a lot more about the use of scripts and how they should be formatted and written look here where the introduction in part 1 talks about the sha-bang line.