Running script at startup not working
I've been trying to run this script when the system turns on.
I have tried multiple methods: init.d, rc.local, and now currently messing with crontab.
This is what I have in my crontab file:
* * * * * bash /home/user/Scripts/space_as_ctrl
I was trying '@reboot' but wasn't working so i tried using '*' for the date fields.
I can run this manually with no problem.
It is also executable.
Thanks for you help.
Be aware: Time specification "* * * * *" will run the command every
minute. It's useful for testing purposes, but can waste resources.
The script probably doesn't run because it probably needs a variable
which your user's crontab doesn't have set.
Since crontabs are designed to be executed/run even when the user isn't
paying attention to the computer, some variables are unset.
I once had a similar problem with GNUnet (which I installed from Guix),
and even though following the instructions that came with the README
file, the `gnunet-arm -s` crontab wouldn't run. Then I found out that it
needs the $USER variable to be set.
You can check which variables your crontab will run with by adding the
following line to your crontab:
* * * * * env > "env.txt"
Then wait a minute for an "env.txt" text file to appear in your user's
home (crontab always runs things from your user's home, unless told
otherwise), and you can comment that same crontab line now. Open the
"env.txt" to see which variables crontab is running your commands with.
In my case, I solved my problem with GNUnet by using this crontab line:
@reboot USER="adfeno" "/home/adfeno/.guix-profie/bin/gnunet-arm" -c
"$HOME/.config/gnunet.conf" -s
The manual page for cron says "When executing commands, any output is mailed to the owner of the crontab". This output will by default found in the ~/mbox file. That might come handy.
While probably unrelated to this issue, when dealing with anything graphical and sometimes even without any apparent reason with silly programs you get output like "Error opening display!" which can be mitigated by setting the DISPLAY variable. (usually to :0)
thanks, lembas
The DISPLAY var is set to ':0'.
When I look in my mail file, searching for CRON, this stands out: 'Unable to connect to X11 display. Is $DISPLAY set?'
Inside the cron environment? If not or unsure, modify your command in crontab toDISPLAY=:0 whatevercommand
Didn't work
I keep trying to just run this script in /etc/init.d, too.
I run 'update-rc.d' on that script, and no errors come up.
The link has been added successfully to my rc directories, too.
It can as well be defined before the actual scheduling of commands. For instance, to wake up at 7:30am with RhythmBox, I have:
DISPLAY=:0
30 7 * * * rhythmbox-client --play
Ok....so my ignorance got the best of me.
Since I am using xmodmap in this script, I needed to run this in my .xsessionrc file.
Thanks to all of you for you fast responses, I really appreciate it.
Isn't it a script you want to run once whenever you log in? For the graphical session, you can "Add" it to the "Startup Applications". For shells, you can add it to their configuration files (e.g., ~/.bashrc if you use GNU Bash, Trisquel's default).
Yes..
I have got this to work in Startup Applications, under Trisquels default session, but I mainly use i3.
The script does not run in any other desktop environment using that method.
For .bashrc, I'm pretty sure the script would only run when a terminal has been opened. Though, it has been a while since I have tested that. I'm going to give it a try actually. Thanks for that reminder.
Yes, the shell configuration only is interpreted when the shell starts, i.e., when a terminal is opened (if it is your default file). I do not know what you script is for. It could have been useful in text sessions...
The script is for mapping ctrl to the space bar.
I like to use this in all my areas of computing.