Legit command doesn't work in crontab

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.

what’s may be an issue here?

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 :slight_smile:

How are you doing the ‘syntax check’?

crontab -T -

ant then type in my coomand.

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.

pps: googling shell scrips rn anyway

What desktop environment are you using? A lot of them have a method for starting things.

i’m on kde. i know there’s this autostart menu on the settings app.

i have yet to learn how to produce a proper script though. simple text file saved as a .sh with executable permission doesn’t seem to work neither in autostart nor in general.

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!


This is the place for scripts which modifies settings for the current X11 session. And the xinput command is such a command.

i managed to run my script through autostart/settings app. the only thing i had to add for it to work was #! /bin/sh which is abracadabra to me.

everything from xinput itself to autorunning it was so simple yet so very much hard. it takes barely minutes to do things, but to find them… weeks of googling.

This is called the Shabang line (as the first line of a script) and it tells the system what environment to use to execute that script

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.

1 Like