Xubuntu, make a launcher for a .sh - bash

I use Xubuntu with gnome-terminal.
I need to launch a sh script (restart.sh) on the pc startup.
The .sh file is in this directory: "/home/stark/Desktop/Tracking/Release/5600/"
I created a launcher like this:
[Desktop Entry]
Name=My GUI App
Exec=gnome-terminal -x sh -c "/home/stark/Desktop/Tracking/Release/5600/restart.sh"
Icon=/path/to/you/icon.svg
Terminal=true
Type=Application
StartupNotify=true
Name[en_US]=Intel5600
Comment=
Path=
What's wrong? Thank you!
EDIT:
This is the bash file:
#!/bin/bash
gnome-terminal -x sh -c 'python3 main00.py'
If I start it from its folder it works (if in a terminal I type: ./restart.sh), but from the launcher it doesn't work.
I tried to set terminal=false, but nothing changes.

add an #reboot cron task:
Running crontab -e will allow you to edit your cron.
Adding a line like this to it:
#reboot /path/to/script
will execute that script once your computer boots up.

vi /etc/rc.local
with content like the following:
# This script is executed at the end of each multiuser runlevel
/path/to/my/script.sh || exit 1 # Added by me
exit 0

Related

Exporting ROS Master URI from shell script

I am trying to export ROS_MASTER_URI from a shell script and then launch roscore. In my .sh file I have:
roxterm --tab -e $SHELL -c "cd $CATKIN_WS; $srcdevel; export ROS_MASTER_URI='http://locahost:1234'; roscore -p 1234"
When I do this, however, I get the following error in the roscore tab:
WARNING: ROS_MASTER_URI [http://locahost:1234] host is not set to this machine.
When I echo the ROS_MASTER_URI in this tab, it says that it is localhost:1234, which is correct. When I manually execute these commands, it works correctly and roscore launches without any issues. I am not sure why it does not work when launched from a bash file.
It was just a typo- missed the l in localhost. All working now.

How to fix "Failed to execute child process source (no such file or directory)"

I am trying to run a script in order to source my catkin workspace prior to running a driver.
This is the bash I am trying to run:
#!/bin/bash
gnome-terminal -e sudo systemctl start firmwared.service
sphinx /opt/parrot-sphinx/usr/share/sphinx/drones/bebop2.drone &
gnome-terminal -e source ~/bebop_ws/devel/setup.bash
roslaunch bebop_driver bebop_node.launch ip:=10.202.0.1
I get failed to execute child process source (no such file or directory) when running my bash
Seems like the problem was the quoting, it should look like this
gnome-terminal -e "bash -c 'source ~/bebop_ws/devel/setup.bash;roslaunch bebop_driver bebop_node.launch ip:=10.202.0.1'"
IF you want to use GUI on windows and failed then just use next command:
sudo apt-get install dbus-x11
source is built into the shell, so you would have to do something like
gnome-terminal -e 'bash -c "source ~/bebop_ws/devel/setup.bash"'

`notify-send` works when invoking script manually, but not from a crontab

I wanted my cron job to report to me on desktop when it executes, through notify-send command on Ubuntu. I've read through the common problems that stated a shell script didn't have access to a display, which is solved by adding this before calling notify-send:
export DISPLAY=:0.0
So i am okay in that regard.
The place where i am right now, is that my script works and notifies me on desktop if i invoke it from terminal manually, but not from the crontab.
The situation is as follows:
The script that executes is a PHP file. The PHP command to invoke the shell command, is:
<?php
`export DISPLAY=:0.0 && command -v notify-send && notify-send "Hello world"`;
(backticks in PHP mean execute in shell)
In both cases i am running it as root
When testing from terminal, i run:
sudo -u root /usr/bin/php -q /var/www/html/cron.php &> /dev/null
This works, and i get a desktop notification
To edit my crontab for the root user, i use:
sudo -u root crontab -e
In my crontab file, my line is this:
* * * * * /usr/bin/php -q /var/www/html/cron.php &> /dev/null
This one does not produce a desktop notification, even though the script 100% executes (i have the successful result in log files).
What goes wrong here, and why wouldn't i get the desktop notification?
you must set the PATH within the script or export it from crontab!
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

Stdout & stderr not redirecting on autostart

I am using Raspbian (Debian with LXDE on a Raspberry Pi).
I have created the following two files. The first one is a .desktop file so as lxde can autostart my script, and the second one is the script in question.
The problem is that when I manually start the script it works perfect, creating the directories and redirecting the streams. However when I reboot the pi, and the script autostarts I get no output at all. The script is surelly working as my final app indeed starts. Only the streams are not there.
I have no idea for what to search for, or what causes this...
.desktop
[Desktop Entry]
Type=Application
Exec=system_start.sh
system_start.sh
#!/bin/bash
cd ~/application.linux64/
mkdir system_log
DIR=system_log/$(date +%Y%m%d)
mkdir $DIR/
./start.sh 1> $DIR/$(date +%T)operation_log.txt 2> $DIR/$(date +%T)errors_log.txt
I had this same problem with Linux Mint. A working command with redirect to a file did not work when started at boot using autostart .desktop file.
Enclosing the command in bash -c " " helped:
bash -c "/home/huehuehue/myguiapp >> /home/huehuehue/myguiapp.log 2>&1"
You should probably use the whole path instead of a relative path to make your script work in any circumstances and avoid ~:
#!/bin/bash
DIR=/home/username/application.linux64/
mkdir $DIR/system_log
SUBDIR=system_log/$(date +%Y%m%d)
mkdir $SUBDIR
./start.sh 1> $SUBDIR/$(date +%T)operation_log.txt 2> $SUBDIR/$(date +%T)errors_log.txt

Excecuting script running ssh commands in the background

I'm trying to execute this script on a remote server with requiretty enabled in the sudoers file.
#!/bin/bash
value=$(ssh -tt localhost sudo bash -c hostname)
echo $value
If I run the script using $ ./sample.sh & it stays stopped in the background. Only by using fg I can force the script to run. I think the problem is the missing tty for the output, but what can I do?
... what can I do?
You can stty -tostop.

Resources