Run Google Assistant SDK on boot (Raspbian) - linux

I am currently trying to get a cron job working, so that the google assistant starts automatically after boot. For that I created this cron job which executes on reboot.
SHELL=/bin/sh
PATH=/usr/bin:/bin:/home/pi/Desktop:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
#Reboot lxterminal -t "Google Assistant" -e /bin/bash /home/pi/Desktop/init.sh
lxterminal will open a window with google assistant running within.
Here is my full cron job:
#!/bin/bash
SHELL=/bin/sh
PATH=/usr/bin:/bin:/home/pi/Desktop:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
source /home/pi/env/bin/activate
python3 /home/pi/assistant-sdk-python/google-assistant-sdk/googlesamples/assistant/grpc/pushtotalk.py
I already tried answers from similar problems and even specified the path variable for cron, but it still won't work for me. The script isn't the fault, when I execute it manually it runs fine.

The problem wasn't with cron, though I settled for using a systemd service instead.
What I didn't know was, that Lxterminal needed a initalized screen to work and due to the script running on boot it wasn't.
This is an easy fix. Either add an delay of 30 Seconds or other values, depending on your system, to the beginning of your script or simulate the display beeing initalized already with export DISPLAY=:1

Related

Crontab won't launch Node.js Discord bot on Ubuntu

I have a bot running on an Ubuntu machine which I'd like to autorun on boot, and so I'm using crontab's #reboot scheduled line for it:
#reboot ~/Bot/run
It works perfectly for all other scripts I have running on boot on my machine, but for this specific script, every line is seemingly being executed correctly, except for the one involving the actual node . command, which launches my Discord bot. The script works perfectly fine when I run it myself from a terminal. Here's the script in question, run.sh, very simple and short in nature:
#!/bin/bash
cd ~/Bot
echo "Launching Discord Bot"
screen -dmS BOT node .
To sum it up, I first enter the correct working directory, send a basic echo, then create a new detached screen session called BOT, to which I pass the node . command, in which the period . implies the index.js file found in my bot's directory. And yes, I intend the screen session to automatically close if/when the bot's process stops.
As mentioned, it seems to actually run the script as intended, but just failing to launch the node.js server. I've tried adding other test lines to the script, including one that sends a message to said Discord server using a webhook, and it correctly sends the messages when placed before and after the node . line.
I've been troubleshooting this for a little while, and I've tried adding a task as a system service in /etc/systemd/system instead of using Crontab, to no avail. I've also tried setting the cronjob to use a login shell with bash -lc to set the proper environment variables for Crontab, still to no avail. I'm all out of solutions, would anyone know how to solve this issue?

Using Gnome-Schedule to run shell script that opens Chromium browser

I have a Raspberry Pi running Raspbian 8.0. I have a shell script that triggers a Chromium Browser to open and go to a specified URL that changes every day. The shell script works when executed from the terminal. How would I get this to work through Gnome Schedule's GUI? I would like this to trigger everyday at a specified time. I've tried setting the command to /home/pi/test.sh, sh /home/pi/test.sh. I read something about needing to specify the display output since I'm running Gnome Schedule from root which isn't the current user logged in. So for that I tried export DISPLAY=:0 && /home/pi/test.sh. Is this going to be possible?
If you put
export DISPLAY=:0.0 at the top of your script rather than export DISPLAY=:0, this should work.

Pcmanfm set wallpaper fails on Raspbian stretch in cron

I am running a nearly fresh image of Raspbian Stretch 4.9 with a desktop and have a program which creates a new image for the computer background every few minutes.
I am trying to create a cron job to properly update the background using pcmanfm and, having followed the suggestions here, have created the following script called update.sh to set the background:
!#/bin/bash
export DISPLAY=:0
export XAUTHORITY=/home/pi/.Xauthority
pcmanfm -w '/home/pi/folder/image.png'
The script is executable and when it is run from the terminal it functions as intended. I have created a crontab to have this run automatically as such:
* * * * * /home/pi/folder/update.sh > /home/pi/folder/log.txt 2>&1
When the cron job triggers every minute, a pop-up window appears with an error saying "Desktop manager is not active." with a button "OK" to dismiss it, and the log file reads:
** Message: x-terminal-emulator has very limited support, consider choose another terminal
I have tried the command directly in the crontab
* * * * * DISPLAY=:0 && pcmanfm -w '/home/pi/folder/image.png' > /home/pi/folder/log.txt 2>&1
And the error is different this time
Cannot open display:
I am not entirely sure what sense to make of this, though from looking around it seems cron jobs can be finnicky. I am not sure if it is a Path or environment problem because I do not know many details about these things, but I don't think it should be a problem as I am using the full path to the image and the scripts. It shouldn't be a permissions error, because I have tried this on both a user crontab and a system crontab, and both fail. (Besides, the default pi user has root permissions by default anyways.) I am not sure what else to search for or try so I am asking for help if someone could point me in the right direction or has encountered this problem before.
I had exactly the same issue, except I am running Lubuntu 17.04. It appeared lately after a recent update, though cannot pinpoint when. After lot's of research I became suspicious that one of the XDG enviromental variables must be exported too. Following some trial and error, I found that exporting XDG_RUNTIME_DIR solved the problem for me. You may want to give it a try.
To figure out the value run: echo $XDG_RUNTIME_DIR
The working wallpaper changer running from cron for me now looks like:
#!/bin/bash
...
export DISPLAY=:0
export XAUTHORITY=/home/krisz/.Xauthority
export XDG_RUNTIME_DIR=/run/user/1000
pcmanfm --set-wallpaper=${dir}/${file} --wallpaper-mode=crop
...

How to start application after login on CentOS?

I am trying to start GUI application with upstart script on CentOS. I have test script located /etc/init/ folder.
start on desktop-session-start
stop on desktop-shutdown
respawn
script
export DISPLAY=:0
sleep 5
exec /.1/Projects/UpstartTest/start.sh &
end script
start.sh scripts is running binary files for GUI application.
After reboot my computer. When I typed:
[root#mg-CentOS ~]# initctl status test
test stop/waiting
So my upstart is not runnig. When i type
initctl start test
manually it works fine without any problem.
How can I run this upstart script after user login (desktop started) ? I am trying to find detailed documents for CentOS for upstart but there is no.
For this purpose, you can use the update-rc tool, which is builtin on linux distributions. It basically creates a symbolic link for the script you want to be executed at startup, or some other OS states, on the folder rc.X, where X is the number of the folder that determines a state that you want.
You may want to have a look at this answer: Update-rc.d custom script running too late, and also runs at shutdown
More information about can be found here:
http://www.linux.com/news/enterprise/systems-management/8116-an-introduction-to-services-runlevels-and-rcd-scripts
Detailed information about the CentOS booting process can be found here: https://www.centos.org/docs/5/html/Installation_Guide-en-US/s1-boot-init-shutdown-process.html;
the rc is being explained at this document as well.

Using script to automatically start program when the system boot up (linux, shell)

Here is the situation, I'm planning to use a simple script to start a program call "STAF", when the Suse system is fully booted. I have achieved this by putting it in the "/etc/init.d/", but this script is basically executed at the background, which means that I cannot see its progress.
When the "STAF" is started this way it works but it doesn't show any working progress when its running service (for example ping, or system backup), instead if I start the "STAF" manually by running the same script whit a terminal, the working progress of "STAF" can be seen on the terminal. Its sort of like the program needs to be started with a interactive terminal, but how can I make this starting process automatic and it should imitate human opening a terminal and run the script?
Sorry if I explained it poorly because its a confusing situation. Thanks.
First, go to the KDE Startup and Shutdown options under System Settings. Then add this command as a new startup script:
konsole -e bash nameofyourscript.sh
I believe the screen utility can do what you describe. Instead of running STAF on startup, you would run screen STAF. To open that terminal, you would run screen -ls to get the screen ID, and screen -r ... to open it.
(Disclaimer: I have not tried this.)

Resources