I have set a crontab job like this :
@reboot xmodmap -e \"keycode 105=Delete\"
@reboot xmodmap -e \"keycode 66=Home\"
and saved on default directory suggested by NANO (/tmp/..../.../cron
), but it's not working. I can list cron job, cron service is running, the output of journalctl -b 0 _SYSTEMD_UNIT=cron.service
displays the jobs without errors and so on. Besides that, I also can't run a script at boot: @reboot /home/user/scripts/myscript.sh
Why is cron
not working as I expect?
xmodmap modifies the keycode mapping for the current session. So if you run it in crontab, it opens a session, modifies the mapping and closes the session again - and its effect is gone.
You should instead run the xmodmap commands in your profile
$HOME/.profile
(or in your$HOME/.xinitrc
if you are starting the X session only at login).man xmodmap
says:Take a look at
man cron
, or other examples on the Internet. I believe that the problem you are having is you're not using the full path the the binaries.In your
cron -e
, instead ofxmodmap
, you would put/usr/bin/xmodmap
.But, even with this change, you won't see any key changes.
Linux is great in that it provides various solutions to problems, but look into how others have solved similar problems. For example,
xmodmap
is typically invoked in.xinitrc
, which is executed when your X session starts.xmodmap
really won't work the way you're trying, at least for your normal user.Since you're interested in
xmodmap
, I recommend you look at documentation and examples and forget aboutcron
completely for this current issue.If you are unwilling to look at documentation and other examples, or want a real understanding of how things work, you can look up the
man
pages:This last sentence has the answers to your problem.
At this point, you don't know if
cron
isn't working (this is your suspicion), or ifxmodmap
fired, but you don't see the effects. The latter is the likely scenario. Your user needs to executexmodmap
within the current X session forxmodmap
changes to be effective.Once you get
xmodmap
working withoutcron
, you can solve the next problem. As mentioned earlier, you need full system paths, but you also need to tellcron
how to run the file. You've simply pointed to the file, which works on your terminal, as it uses the shebang/interpreter (ie:#!/bin/bash
). So, forcron
to run abash
file...Though, do you really want
root
running a script found in your user directory? With what you've learned so far, maybe you add/usr/bin/bash /home/user/scripts/myscript.sh
(orsource
it) in~/.xinitrc
instead ^_~.