Terminal not clearing after auto start bashscript in raspbian wheezy - linux

I'm using a raspberry pi 2 to show all the video's in a folder. The raspberry automatically boots up (with a generic electric timer) in to console (not the gui) and after it boots it runs a bashscript I found here. This bashscript contains an infinite loop to play all the videos in a folder using omxplayer.
When I boot in to consolemode and manually start the script everything works perfectly. The terminal screen clears, the first video starts, and after it ends there is a second or two of black screen (empty terminal) and the second video starts playing. This is exactly what I want.
However, when I use crontab to start this script (#reboot /path/to/script.sh) the terminal messages stay and it doesn't clear everything between video's.
I've tried creating my own script that first clears everything, and then calls the second script. But this doesn't work.
I'm really really new in this field (but I'm having fun) so any pointers in the right direction would be appreciated!
P.S. I edited the /boot/cmdline.txt file so it doesn't display critical kernal logs as a work-around.

You should not be doing this using cron. You should be changing the inittab so that it runs outside any environment that may be created. See the inittab(5) man page for details. You may also be interested in openvt(1) as well.

Related

Tmux output truncated

I have just setup a long-running scrip on an Amazon EC2 Linux 2 instance.
All works fine, I created a new session, launched my script, disconnected from the sever and was able to log back in and see it still running - great.
Just one inconvenience, my script outputs around 150 lines of text on each iteration (runs every few hours).
After the first run, I can see the script printing as it should, but after the script finishes executing, the top ~90% seems to be lost and I can see the AWS default text from when I first logged in which is odd.
Does anyone know why this happens and how I can see the full output from my script (and only my script) in a tmux window?
Thanks
You need to increase the scroll back buffer. In your .tmux.conf add something like,
set-option -g history-limit 10000
For some caveats, see answers to this related question.

Autostart GUI application with LXDE session

There's quite a bit of information out there on this topic, but for some reason I just can't get it to work. This is on a raspberry pi running the 'DietPi' flavor over the raspian distro, and is perhaps what separates my question from the others.
So I have a GUI application that I wish to launch at boot, after the LXDE session has begun. So I have utilized the following file here:
/etc/xdg/lxsession/LXDE/autostart
and added the line:
#/myapplication
This works, however, it launches multiple instances of this program, and the first one always crashes. This creates problems because there's some competition for resources (IO, files, etc). So what I did was create script file, /myapplication-autostart.sh instead like so:
if pgrep "myapplication" > /dev/null
then
echo "my application is already running"
else
/myapplication
fi
and then changed /etc/xdg/lxsession/LXDE/autostart to #/myapplication-autostart.sh. Now what I find is the program launches once, but the instance crashes. It crashes when it attempts to create a window (opencv imshow). This is strange because the program will also run headless if an X-session is not available, but for some reason it crashes and I do not know where to check why.
Also, to test it wasn't an issue with the script file, I commented everything out except the /myapplication and I have found the script file runs in a continuous loop and every time I close the application it opens back up. I'm not sure why this is either.
I've tried adding a sleep delay in the script and it does not help. For whatever reason, it seems the LXDE autostart script is ran at least 3 times when booting the pi and the circumstances around the first cause the program to crash. Does anybody understand this sequence and behavior of calling this autostart script?
It is also possible to use the XDG standard Autostart - which is independent of the used desktop environment - by placing desktop files at
$XDG_CONFIG_HOME/autostart (by default ~/.config/autostart)
or for system-wide autostarts at $XDG_CONFIG_DIRS/autostart (by default /etc/xdg/autostart).
Such a .desktop-file could look like:
[Desktop Entry]
Type=Application
Version=1.0
Name=JDownloader
Exec=/usr/local/bin/my-application.sh
Categories=Utilities
The specification of desktop-files can be found at freedesktop.org.
Here was the final solution...
/etc/xdg/lxsession/LXDE/autostart added the line:
/myapplication-autostart.sh
and /myapplication-autostart.sh was changed to:
#!/bin/bash
if pgrep "myapplication" > /dev/null
then
echo "my application is already running"
else
if [[ "$DISPLAY" = ":0" ]]
then
/myapplication
fi
fi
I had to write the display variable to file in combination with the errors to file to discover the issue. At login 2 X sessions were created, display ":1" and display ":0", in that sequence. Display ":1" crashed because, although not headless, it was not initialized to a particular resolution and there was some resizing code in my program. Display ":0" was the actual display on the HDMI out and the one I wanted. Really, the conditional check to see if the application isn't necessary but I left it in there to be safe. I could have also left the # on the LXDE autostart file but it got annoying in the cases I wanted to close the application because it'd keep re-opening. Possibly I'll put it back later.
Thanks for the help!
First, some comments about opening several instances of the program: when you use "#" at the beginning of the line on the startup file (ex.: #/myapplication), this requests your system to try to launch the program, but if the program fails to open correctly, then the system will try to open it multiple times until it opens correctly -- if you remove "#" from the line beginning, then the system will only try to open the program once.
Now, to find out why the program is failing, I advise you to add
2> /file/log
to the end of every command on your script. Doing so would append any error message to a log (/file/log), and analyzing those error messages would be key to find out why the program is misbehaving.
One important note: if your program needs root privileges to run, then it will fail when called via /etc/xdg/lxsession/LXDE/autostart, as this method calls programs without elevated permissions.
This is an old thread but I was having problems getting autostart to start all the tasks listed. After many days I concluded there were one or more "invisible" characters that autostart didn't like. So I deleted the lines for the tasks that didn't start and retyped them. That solved the problem!
I think I corrupted the lines because I was editing some of the lines on my Windows computer. It was likely inserting CR with LF or some other stuff. I WILL NEVER EDIT TEXT FOR LINUX USING WINDOWS!
Maybe someone else will hit this problem and this may help them. I don't know where else to put this information.

Running a program in linux (debian) on startup

I would like to point out that I tried A LOT of different tutorials from the internet but they don't seem to work...
Adding stuff to init.d, rc.local etc. for some reason it doesn't work.
I'm really desperate to get this done, but I'm a total noob when it comes to linux.
when I type in "matchbox-keyboard" it runs just fine and as intended.
That's literally all I want, but I'd like to run it every time so when I turn my raspberry pi on, I won't have to connect a keyboard and a mouse to initialize on-screen keyboard.
Is there a simple way to get this done, something like dropping the program into autostart folder in windows?
I have no experience with linux at all, I don't know how to write scrips and all that stuff and all I want is to run this "matchbox-keyboard" after every reboot...
Please help me, I'm really desperate and I can't figure it out. Spent all day doing it and still nothing...
The simplest way is to drop in a new cronjob (a cronjob is a task that is scheduled to run at a particular time):
crontab -e
This allows you to edit your cron file. Instead of putting in a time, use #reboot. So you should have a new line in your cronjob file that looks like this:
#reboot matchbox-keyboard
The cronjobs run in a different environment from your login environment, so you may need to use the full path to the program. I'm also not familiar with the matchbox-keyboard program, but it looks like it will run fine since it can run as a background process.
Maybe you have gnome-tweaks installed?
apt list gnome-tweaks
Listing... Done
gnome-tweaks/stable,now 3.30.2-1 all [installed,automatic]
It has a graphical Startup Applications function that allows you to select application icons and start them at LOGIN time. I use it to start my favorite text editor.
Starting things like an Apache server (e.g. XAMPP) at BOOT time is a whole new ball game. I used this link as a starting point.

Handling input device plug/unplug while reading from it

I have a bluetooth remote that is paired with my linux box, when active, this remote is visible at /dev/input/event13.
I have a small C program that open this device and read directly from it, which works fine.
Now, my problem is that this remote goes to sleep after a few minutes of inactivity and /dev/input/event13 disappears. It reappears as soon as I press a key on my remote.
I put the output of udevadm here: https://gist.github.com/9fff2f0d7edef1050060.
I use the following code (small ruby ext I wrote), to read from the device: https://gist.github.com/b403d538eb6a8627e2bd.
I thought of writing an udev rule that would start my program when my remote is added and stop it when it is removed. I read the udev documentation, but I couldn't figure it out how to do it. I'm open for suggestion.
After some digging and a lot of frustration I did the following:
I put into /etc/udev/rules.d/99-rmote.rules
KERNEL=="event*", SUBSYSTEM=="input", ACTION=="add|remove", ATTRS{name}=="TiVo Keyboard Remote", RUN+="/home/kuon/handleConnect.rb"
And in handleConnect.rb I check the ACTION environment variable and I start/stop my daemon accordingly. Quite simple in the end and it works well.

In gnome w/ xmonad, how can I call a script when a monitor is plugged in OR when docking my laptop?

Problem:
I have an extra set of top and bottom gnome-panels for a second monitor. When I undock my lenovo Thinkpad (T510), the extra top and bottom panels remain, so I have two on top and two on the bottom. I am currently running a RHEL6/Fedora (x86_64) gnome (2.28.2) instance with xmonad (0.9.1-6.1.el6) set as the window manager, using the xmonad extensions to work within gnome.
Tried:
I've used acpi and found a code for docking and undocking, but when I try to utilize a script I found in this blog post, it gets zero for the call to xrandr. The script works when called on its own from the terminal. I've tried calling a separate looping script in its own thread and it keeps getting zero for the value, long after the screen(s) update(s).
I have figured out how to have a script loop every X seconds and check for a file which is touched into existence in the event of the script getting a zero, then performing the necessary change, but I don't like that approach.
Question:
I'm hoping someone knows a place I can drop a call to the referenced script and have my panels come and go as I would expect without needing to initiate the script manually.
Thanks!
Update: I have added a bounty of 50 (max I can do) for an answer.
Ben
I guess one of the problems listed below occures (or both):
1) looks like your xrandr snippet doesn't return proper values because the $DISPLAY environment variable is not set correctly. Acpi handler script normally runs as a user which is not the user running your current X session. That way xrandr just does not know which $DISPLAY to access.
2) if $DISPLAY is set correctly, the acpid user might still not be able to access your running xsession. You might check whether the script will work over acpi handler, if you execute xhost + as the user who is currently runging the current xsession with $DISPLAY specified in your script. This will disable access control for X. You can reenable it with xhost - again.
Check it, I hope it helps or will at least point you in which direction to dig.

Resources