Running script at startup not working

14 respuestas [Último envío]
sradms0
Desconectado/a
se unió: 08/24/2015

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.

ADFENO
Desconectado/a
se unió: 12/31/2012

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

sradms0
Desconectado/a
se unió: 08/24/2015

thanks, ADFENO

ADFENO
Desconectado/a
se unió: 12/31/2012

You're welcome. :)

lembas
Desconectado/a
se unió: 05/13/2010

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)

sradms0
Desconectado/a
se unió: 08/24/2015

thanks, lembas

sradms0
Desconectado/a
se unió: 08/24/2015

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?'

lembas
Desconectado/a
se unió: 05/13/2010

Inside the cron environment? If not or unsure, modify your command in crontab toDISPLAY=:0 whatevercommand

sradms0
Desconectado/a
se unió: 08/24/2015

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.

Magic Banana

I am a member!

I am a translator!

Desconectado/a
se unió: 07/24/2010

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

sradms0
Desconectado/a
se unió: 08/24/2015

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.

Magic Banana

I am a member!

I am a translator!

Desconectado/a
se unió: 07/24/2010

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).

sradms0
Desconectado/a
se unió: 08/24/2015

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.

Magic Banana

I am a member!

I am a translator!

Desconectado/a
se unió: 07/24/2010

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...

sradms0
Desconectado/a
se unió: 08/24/2015

The script is for mapping ctrl to the space bar.
I like to use this in all my areas of computing.