seanspotatobusiness
Posts: 192
Joined: Tue May 22, 2012 11:19 pm

Starting a tmux script in lxterminal at automatically after log-in

Thu Jun 21, 2018 10:34 pm

I'm trying to make a script run in a terminal window at system start and I've tried and failed with four approaches, some of which might be entirely unsuitable in any case.

The script I want to run requires tmux and is as follows:

Code: Select all

#!/bin/bash
SESSION=$USER

lxterminal --geometry=126x45 -e tmux && tmux -2 new-session -d -s $SESSION

# Setup a window for monitoring TO/Sam, TO/Sean, TO/Sam+Sean, C/Sean, C/Sam, C/Sam+Sean, TS/Sean, ASICs
tmux new-window -t $SESSION:1 -n 'TradeOgre and Cryptopia monitors'
tmux split-window -h
tmux split-window -h
tmux split-window -v
tmux split-window -v
tmux split-window -v
tmux select-pane -t 0
tmux split-window -v
tmux split-window -v
tmux split-window -v
tmux select-layout tiled
tmux set pane-border-status
tmux select-pane -t 0 -T TradeOgre_Sean
tmux send-keys "python /home/pi/Mining/TradeOgreNotificationScript_Sean.py" C-m
tmux select-pane -t 1 -T TradeOgre_Sam
tmux send-keys "python /home/pi/Mining/TradeOgreNotificationScript_Sam.py" C-m
tmux select-pane -t 2 -T TradeOgre_SamSean
tmux send-keys "python /home/pi/Mining/TradeOgreNotificationScript_SamSean.py" C-m
tmux select-pane -t 3 -T Cryptopia_Sean
tmux send-keys "python /home/pi/Mining/CryptopiaNotificationScript_Sean.py" C-m
tmux select-pane -t 4 -T Cryptopia_Sam
#tmux send-keys "python /home/pi/Mining/CryptopiaNotificationScript_Sam.py" C-m
tmux select-pane -t 5 -T Cryptopia_SamSean
#tmux send-keys "python /home/pi/Mining/CryptopiaNotificationScript_SamSean.py" C-m
tmux select-pane -t 6 -T Tradesatoshi_Sean
#tmux send-keys "python /home/pi/Mining/TradesatoshiNotificationScript_Sean.py" C-m
tmux select-pane -t 7 -T Altex_Sean
tmux send-keys "python /home/pi/Mining/AltexNotificationScript_Sean.py" C-m
tmux select-pane -t 8 -T ASIC_monitor
tmux send-keys "python /home/pi/Mining/MinerMonitoringScript.py" C-m
If I type at the command line '/home/pi/Mining/tmuxScript.sh' then a large lxterminal window starts and gets divided into nine sections which then have their own scripts running inside them. The four methods I've tried to use to start my script automatically after log-on are: 1. "~/.config/lxsession/LXDE-pi/autostart", 2. init.d tab, 3. systemd and 4. crontab

1. When I try adding the line '@/home/pi/Mining/tmuxScript.sh' to '~/.config/lxsession/LXDE-pi/autostart' all I get is a large terminal window titled 'tmux' with a tmux session activated.

2. Nothing happens after the system starts.


3. using "sudo systemctl enable sample.service" after creating "/lib/systemd/system/sample.service":

Code: Select all

[Unit]
 Description=My Sample Service
 After=multi-user.target

 [Service]
 Type=idle
 ExecStart=/home/pi/Mining/atmuxScript.sh

 [Install]
 WantedBy=multi-user.target
Nothing happens after the system starts.

4. Nothing that I put in crontab has any effect at all:

Code: Select all

@reboot lxterminal
@reboot /home/pi/Mining/tmuxScript.sh
@reboot lxterminal -e python /home/pi/Mining/test.py
These all do nothing for both 'crontab -e' and 'sudo crontab -e'.
Raspberry Pi 3 B and B+
PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"
NAME="Raspbian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"

klricks
Posts: 6618
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: Starting a tmux script in lxterminal at automatically after log-in

Thu Jun 21, 2018 11:39 pm

You mostly had it working in your other thread????
viewtopic.php?f=91&t=216094
Unless specified otherwise my response is based on the latest and fully updated Raspbian Buster w/ Desktop OS.

User avatar
The Traveler
Posts: 363
Joined: Sat Oct 21, 2017 3:48 pm

Re: Starting a tmux script in lxterminal at automatically after log-in

Thu Jun 21, 2018 11:44 pm

From the discussion in your previous thread, I've found that the only way to get your tmux session working automatically is to run on a headless system. The only other window manager I found that was "tmux friendly" was i3, a minimal tiling window manager: https://i3wm.org/ There are others like xmonad and dwm, but i3 appears to be the better candidate for running on an RPi. Even then, I'm not sure your script can be started automatically. I would have to strip my LXDE WM down and install i3 to test it which I'd rather not do right now. You can Google "tmux and i3" for more info.

<Warning: personal opinion>
On a side note, if I were setting up a device for bitcoin mining, I'd just set up a RPi headless, install the necessary programming and dedicate the RPi only to bitcoin mining 24/7/365. Nothing else. As inexpensive as RPi's are, it seems to me to be a more secure and hassle-free alternative to what your currently trying to do. With hacking of bitcoin operations on the rise, and also increased hacking of home networks, having a dedicated and well secured RPi would be desirable in my opinion.
<End: personal opinion>

Cheers.
Retired IT professional, C programmer and "beardie weirdie".
RPi interests: Developing an Infinite Improbability Drive
“Thinking outside of the box allows you to get rewards outside of your reach.” Matshona Dhliwayo

User avatar
bertlea
Posts: 301
Joined: Wed Dec 07, 2016 6:33 am
Location: Hong Kong

Re: Starting a tmux script in lxterminal at automatically after log-in

Fri Jun 22, 2018 5:04 am

I think your attempt (1) is almost there, and the problem is when the script started an tmux session, the following commands are issued at the “script environment”, not inside the tmux session. Did you actually tried to run the script (not typing the commands in the script)? I guess, you will see the same result if you run that script, i.e. only see one tmux session activated and nothing else if my conjecture is right.

Below is a script that I can run to create a tmux session named as “server”. Then I split the screen in the server and run some command in each screen (screen: 0, and screen: 1). I added some “sleep” command between commands but that may not needed.

Code: Select all

#!/bin/bash
cd ~
echo 'creating tmux session'
tmux new-session -d -s server
sleep 1
tmux split-window -dh -t server
sleep 1
echo 'starting programs in tmux'
tmux send-keys -t server.1 'node --expose-gc' C-m
sleep 1
echo 'sending commands to node.js to load and run my server and show memory status in screen:0'
tmux send-keys -t server.1 '.load ./util/myServer.js' C-m
tmux send-keys -t server.0 'date; free -h' C-m

texy
Forum Moderator
Forum Moderator
Posts: 5160
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: Starting a tmux script in lxterminal at automatically after log-in

Fri Jun 22, 2018 6:53 am

Locking - no need to create a new thread, use your existing one here :
viewtopic.php?f=91&t=216094

Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

Return to “Beginners”