Using Cron tabs to open localhost on a web browser - cron

I am trying to get my PI, which is running rasbian, to automatically run a bash command whenever the pi is booted. The ultimate goal is to open the localhost web page.
I ran
crontab -e
to open my crontab, and added this to the end of the file:
#reboot chromium-browser --kiosk localhost
but when I reboot the pi, nothing appears to happen. I then added this to test to see if crontab was even running or if I had formatting wrong:
#reboot cd && sudo touch sucess
But it executed exactly as expected
What am I missing?
EDIT 1: I did try doing this but it still didn't execute:
#reboot cd && chromium-browser --kiosk localhost
EDIT 2: I also saw an article suggesting that cron cannot find bash command locations, so I tried this as well, also to no avail:
#reboot cd && /bin/chromium-browser --kiosk localhost
EDIT 3: I also attempted to put the same command in root's crontab instead by doing sudo crontab -eBut that didn't work either

Related

bash script to auto run on boot, make screen, execute a command and detach

I am using Centos 7 and on boot I would like to:
Make a screen
Execute a command: osrm-routed --algorithm=MLD
~/osrm-backend/profiles/australia-latest.osrm
Detatch from screen (possibly not needed, just as long as I can
access it myself after its running in future)
Here is something I have thought about, although not correct and wont work
filename: mapstart.sh
Contents of file:
#!/bin/bash
/usr/bin/screen -dmS mapapi osrm-routed --algorithm=MLD ~/osrm-backend/profiles/australia-latest.osrm
With your help with the script. I am not sure the best way to run that on boot with centos 7.
Appreciate your help and input.
For those who would like to know. The issue was with OSRM and centos. I was able to get it running using the full paths of everything and the following in crontab -e
To get the full path of osrm-backend i ran the command of:
which osrm-routed
It returned the result of:
/usr/local/bin/osrm-routed
That then enabled me to add the full path of the command I was trying to run from crontab -e which is required. From there it worked running the below in crontab -e
#reboot /usr/bin/screen -dm -S pistartup /usr/local/bin/osrm-routed --algorithm=MLD ~/osrm-backend/profiles/australia-latest.osrm
break down of all the above:
runs command at reboot only:
#reboot
full path to screen command:
/usr/bin/screen
create screen with name of pistartup and detach:
-dm -S pistartup
my particular command i wanted to run inside the screen:
/usr/local/bin/osrm-routed --algorithm=MLD ~/osrm-backend/profiles/australia-latest.osrm
Now when ever the machine is rebooted. it has created a screen and run my command. To resume the screen manually If i ever wanted to, i could issue the command of:
screen -r pistartup

Running a command on startup

I want to run this command on my ubuntu server installation on startup:
~/factorio/bin/x64/factorio --start-server-load-latest --server-settings ~/factorio/data/server-settings.json
I tried putting this code in the /etc/rc.local directory:
~/factorio/bin/x64/factorio --start-server-load-latest --server-settings ~/factorio/data/server-settings.json || exit 1
exit 0
And the command doesn't run on startup. I know that the command runs when I type it into the command line, but it won't run for some reason when I put it in the /etc/rc.local file. Can anyone tell me where the error is in my code or another way that I could get this command to run on boot?
Open crontab.
sudo crontab -e
Then try adding you command as root to the bottom.(use nano editor).
#reboot root ~/factorio/bin/x64/factorio --start-server-load-latest --server-settings ~/factorio/data/server-settings.json
Note that this will run under root so you will need to change the path of every file from '~/call' to '/full/path/to/file'

Ubuntu - Run command on start-up

I would like to run 2 commands when Ubuntu starts up(before anyone even logs in)
Also, these commands should be able to work, immediately after boot up.
So how do I do this?
Navigate to /etc/ and run
sudo nano rc.local
Place your commands below the comments, and above the command, "exit 0"
The commands should run on startup

Scrapyd not starting at boot-up - Ubuntu 14

I have Scrapyd installed on server.
I want it to start whenever my server restarts.
I created job here /etc/init/myjob.conf with following contents
description "my job"
start on startup
task
cd /var/www/scrapers && scrapyd >& /dev/null &
I also tried to put following command in crontab -e
#reboot cd /var/www/scrapers && scrapyd >& /dev/null &
Both of them did not work.
I checked cronlogs using grep CRON /var/log/syslog and here I see command ran but Scrapyd did not start
Mar 30 13:33:28 mani CRON[446]: (root) CMD (cd /var/www/scrapers && scrapyd >& /dev/null &)
As you can see that command ran as ROOT user.
If I manually run that command in terminal it works!
PS:
I changed command to
#reboot cd /var/www/scrapers && scrapyd >> /var/www/log.txt
and log file is created but its empty!
You must try to start process manually, and see what happens. The line:
cd /var/www/scrapers && scrapyd
makes sense if: 1) directory /var/www/scrapers do exist 2) scrapyd is a binary that exists in that directory, and PATH environment variable includes actual directory ("." wildcard).
Maybe you could try:
cd /var/www/scrapers && ./scrapyd
without redirect standar output to /dev/null, to see what happens. Always try manual before use cron.
I could not get my scrapyd start through /etc/rc.local or crontab so I found a work around. I am sure there will be a better way but for mean time this worked for me.
I created a python file start.py.
import os
os.system('/usr/bin/python3 /home/ubuntu/.local/bin/scrapyd > /home/ubuntu/scrapy.log &')
And simply call the python file start.py through crontab.
Add this to crintab file by cronat -e.
#reboot /usr/bin/python3 /home/ubuntu/start.py
Basically what I did is execute the scrapy through shell by calling the python filr through crontab.

run a screen after reboot

i tried to google but had no luck perhaps because i am not sure on the terms to look for. basically im trying to auto run a screen after the system reboots. i tried crontab but it seems that i cannot execute the jar file unless im in the directory.
something like
crontab -e:
#reboot screen -d -m -S ModBot java -jar /home/themoduser/modbotfiles/ModBot.jar start
im not sure if that is a correct method or if trying to use a .sh script:
cd /home/themoduser/modbotfiles/
screen -d -m -S ts3bot java -jar ModBot.jar
and in crontab
#reboot /home/themoduser/modbotfiles/ModBot_startscript.sh start

Resources