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

Starting a tmux script in lxterminal automatically after log-in

Sat Jun 16, 2018 5:38 am

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'.
Last edited by seanspotatobusiness on Fri Jun 22, 2018 9:20 am, edited 3 times in total.
Raspberry Pi 3 B and B+
PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"
NAME="Raspbian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"

User avatar
Paeryn
Posts: 2636
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: Need terminal command to open maximised terminal and run script in it

Sat Jun 16, 2018 8:41 am

seanspotatobusiness wrote:
Sat Jun 16, 2018 5:38 am
I want to use a command to open a terminal in a new maximised window and run a script. This is the command I have so far:

Code: Select all

lxterminal -e ./home/pi/Mining/tmuxScript.sh
You have got the path to your command wrong, the period at the start says "starting in the current directory" (a single period is a special directory name that every directory has which is the directory itself), if the current directory (the one you were in when you typed that line) is your home directory e.g. /home/pi then you have asked lxterminal to run

Code: Select all

/home/pi/home/pi/Mining/tmuxScript.sh
which I am betting is not correct. What you wanted was

Code: Select all

lxterminal -e /home/pi/Mining/tmuxScript.sh
If you ask lxterminal to run a command that doesn't exist you end up with a blank window that stays open as you see (I'm not sure why it doesn't print a message in that window telling you the command doesn't exist, I know xterm does).
She who travels light — forgot something.

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

Re: Need terminal command to open maximised terminal and run script in it

Sat Jun 16, 2018 12:20 pm

seanspotatobusiness wrote:
Sat Jun 16, 2018 5:38 am
I want to use a command to open a terminal in a new maximised window and run a script. This is the command I have so far:

Code: Select all

lxterminal -e ./home/pi/Mining/tmuxScript.sh
It isn't working. It instead opens a seemingly hung terminal window titled tmuxScript.sh which doesn't respond to pressing Ctrl + C.

Similarly, running

Code: Select all

lxterminal -e cd ./home/pi/Mining/
just opens a hung termminal titled cd.
Try:

Code: Select all

lxterminal -e bash /home/pi/Mining/tmuxScript.sh
bash is required here if you haven't set the file permissions to execute...
if you want to use the shortend command then:

Code: Select all

lxterminal -e bash ./Mining/tmuxScript.sh
If you want to add more command(s) such as cd /path/, then add them to your script or create a new script that includes the command(s) then calls the original.
Unless specified otherwise my response is based on the latest and fully updated Raspbian Buster w/ Desktop OS.

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

Re: Need terminal command to open maximised terminal and run script in it

Sat Jun 16, 2018 12:46 pm

Thanks. That's got me closer because it looks like my script starts to run in a new terminal window but there are two problems: one is that I'd like the window created to be maximised and the second is that the window closes very quickly after opening. I read that putting an ampersand & at the end of the line would keep the window open but it isn't true.

Edit: based on the results of the script, I'm inclined to believe that the script is actually running in the background still but the window closed. I would really like the window to stay open so I can see the script outputs.

Also how do I access the scripts I ran whose windows closed? I ran it twice and now it's sending me two emails every time an event happens but I don't know how to access and close them other than to restart the system.
Raspberry Pi 3 B and B+
PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"
NAME="Raspbian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"

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

Re: Need terminal command to open maximised terminal and run script in it

Sat Jun 16, 2018 4:26 pm

A nice gentle intro to the tmux terminal window manager. It may answer some your "how do I" questions. https://hackernoon.com/a-gentle-introdu ... 784c404340

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

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

Re: Need terminal command to open maximised terminal and run script in it

Sat Jun 16, 2018 5:04 pm

Thanks but that doesn't help with stopping the terminal window from closing. If I have to manually open the window again and then open the tmux session it defeats the whole point of having made the script start automatically in the first place.
Raspberry Pi 3 B and B+
PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"
NAME="Raspbian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"

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

Re: Need terminal command to open maximised terminal and run script in it

Sat Jun 16, 2018 5:43 pm

Thanks but that doesn't help with stopping the terminal window from closing.
Perhaps not, but it might give you the knowledge to troubleshoot the script and understand why it's closing. tmux has a fair number of configuration options and relying on pre-made scripts isn't always, er ... reliable on all systems.

I'm an advocate of the "teach a man to fish" learning philosophy. The more you learn, the better equipped you are to deal with future problems.

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

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

Re: Need terminal command to open maximised terminal and run script in it

Sat Jun 16, 2018 5:58 pm

The script runs fine when I launch it manually. There is nothing wrong with the script. The script keeps running in the background and sends me notification e-mails. The window only closes when I open the window with the command:

Code: Select all

lxterminal -e /home/pi/Mining/tmuxScript.sh
The command is not complete.
Raspberry Pi 3 B and B+
PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"
NAME="Raspbian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"

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

Re: Need terminal command to open maximised terminal and run script in it

Sat Jun 16, 2018 6:13 pm

The command is not complete.
I don't think that's the issue here. tmux is generally run from a non-gui interface, ie; command line, no window manager. I use tmux on both a Ubuntu server and RPi that run headless, no windows system at all. I surmise that when you open the lxterminal session, the window manager is killing your script.

You can try this and see if it works:

Code: Select all

lxterminal --command tmuxScript.sh 
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

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

Re: Need terminal command to open maximised terminal and run script in it

Sat Jun 16, 2018 6:50 pm

The Traveler wrote:
Sat Jun 16, 2018 6:13 pm
The command is not complete.
I don't think that's the issue here. tmux is generally run from a non-gui interface, ie; command line, no window manager. I use tmux on both a Ubuntu server and RPi that run headless, no windows system at all. I surmise that when you open the lxterminal session, the window manager is killing your script.

You can try this and see if it works:

Code: Select all

lxterminal --command tmuxScript.sh 
Cheers.
Thanks. Unfortunately that command in the form:

Code: Select all

[email protected]:~ $ cd /home/pi/Mining/
[email protected]:~/Mining $ lxterminal --command tmuxScript.sh 
[email protected]:~/Mining $ 
produces a hung terminal window like the one in the foreground of the screenshot in the OP.
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: 6550
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: Need terminal command to open maximised terminal and run script in it

Sat Jun 16, 2018 8:10 pm

seanspotatobusiness wrote:
Sat Jun 16, 2018 6:50 pm


Thanks. Unfortunately that command in the form:

Code: Select all

[email protected]:~ $ cd /home/pi/Mining/
[email protected]:~/Mining $ lxterminal --command tmuxScript.sh 
[email protected]:~/Mining $ 
produces a hung terminal window like the one in the foreground of the screenshot in the OP.
Using --command is the same as using -e
You likely need the full path to your script above.

My guess ...... and as from what I remember from other threads...... You may have a command(s) in your script which do not have the full path specified. If so then the script will run to that point and then dump out. Running a script with lxterminal -e requires full path on everything and will error out even if it runs OK from the CL.

If your script exits to the command line for any reason then the terminal will immediately close.
Unless specified otherwise my response is based on the latest and fully updated Raspbian Buster w/ Desktop OS.

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

Re: Need terminal command to open maximised terminal and run script in it

Sat Jun 16, 2018 9:57 pm

The same thing happens for:

Code: Select all

lxterminal --command /home/pi/Mining/tmuxScript.sh
as it does for:

Code: Select all

lxterminal -e /home/pi/Mining/tmuxScript.sh
This is what the script contains:

Code: Select all

#!/bin/bash
SESSION=$USER

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 split-window -v
tmux select-pane -t 0
tmux split-window -v
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
Is this script okay? Could it be MinerMonitoringScript.py?

It contains:

Code: Select all

import time
import datetime
import json
import Tkinter as tk
import RPi.GPIO as GPIO
from pycgminer import CgminerAPI

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)

def popup(message):
    root = tk.Tk()
    tk.Label(root, text=message).pack()
    root.mainloop()

def pin_setup(pin):
    GPIO.setup(pin, GPIO.OUT)

def pin_on(pin):
    GPIO.output(pin, GPIO.HIGH)

def pin_off(pin):
    GPIO.output(pin, GPIO.LOW)
    
def log(line):
    print str(datetime.datetime.now().strftime("%m%d %H:%M ")) + line

miners = [{
    "name": "Giant X10",
    "IP": "192.168.1.20",
    "api": None,
    "limit": 9000000,
    "unit": "KHS"
    },{
    "name": "L3+",
    "IP": "192.168.1.21",
    "api": None,
    "limit": 450,
    "unit": "GHS"
    },{
    "name": "S9-1of2",
    "IP": "192.168.1.22",
    "api": None,
    "limit": 8500,
    "unit": "GHS"
#    },{
#    "name": "S9-2of2",
#    "IP": "192.168.1.23",
#    "api": None,
#    "limit": 13000,
#    "unit": "GHS"
    }
]

beacon_pin = 21

def beacon_on():
    log("Beacon on")
    pin_on(beacon_pin)

def beacon_off():
    log("Beacon off")
    pin_off(beacon_pin)
    
def on_error_ok():
    print "whatever"    

def get_miners():
    for miner in miners:
        miner['api'] = CgminerAPI(miner['IP'])

def check_hashes():
    for miner in miners:
        try:
            summary = miner['api'].summary()
            hash = summary['SUMMARY'][0][miner['unit'] + ' 5s']
            log(miner['name'] + ": " + str(hash) + " " + miner['unit'])
#            print miner['limit']
            if (hash <= miner['limit']):
                beacon_on()
                problem = miner['name'] + " having hashrate issues"
                log(problem)
                popup(problem)
        except Exception as e:
            print e
            raise Exception(miner['name'] + " having connection issues")

pin_setup(beacon_pin)

while True:
    beacon_off()
    log("Retrieving miner status")
    try:
        get_miners()
        check_hashes()
    except Exception as e:
        beacon_on()
        log(str(e))
        popup(str(e))

    time.sleep(60)

GPIO.cleanup()
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: 6550
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: Need terminal command to open maximised terminal and run script in it

Sat Jun 16, 2018 10:30 pm

seanspotatobusiness wrote:
Sat Jun 16, 2018 9:57 pm
The same thing happens for:

Code: Select all

lxterminal --command /home/pi/Mining/tmuxScript.sh
as it does for:

Code: Select all

lxterminal -e /home/pi/Mining/tmuxScript.sh
Try this:

Code: Select all

lxterminal -e bash /home/pi/Mining/tmuxScript.sh
or if permission is set to execute then this will work:

Code: Select all

lxterminal -e ./Mining/tmuxScript.sh
Unless specified otherwise my response is based on the latest and fully updated Raspbian Buster w/ Desktop OS.

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

Re: Need terminal command to open maximised terminal and run script in it

Sat Jun 16, 2018 10:55 pm

klricks wrote:
Sat Jun 16, 2018 10:30 pm
seanspotatobusiness wrote:
Sat Jun 16, 2018 9:57 pm
The same thing happens for:

Code: Select all

lxterminal --command /home/pi/Mining/tmuxScript.sh
as it does for:

Code: Select all

lxterminal -e /home/pi/Mining/tmuxScript.sh
Try this:

Code: Select all

lxterminal -e bash /home/pi/Mining/tmuxScript.sh
or if permission is set to execute then this will work:

Code: Select all

lxterminal -e ./Mining/tmuxScript.sh
Unfortunately they both do the same thing.
Raspberry Pi 3 B and B+
PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"
NAME="Raspbian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"

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

Re: Need terminal command to open maximised terminal and run script in it

Sat Jun 16, 2018 10:55 pm

I think you'll need to run your tmuxScript.sh in a headless system like Raspbian Lite for it work as you want. tmux in and of itself it is a console manager.

The problem intrigued me so I've spent some time looking for a solution. I could find none. In short, it appears tmux was not intended to work with a GUI window manager. The only "maybes" were i3 and dwm which are both tiling window managers but it was not certain. I couldn't find any reliable information demonstrating how to run a tmux session in anything but a headless system.

You could try and strip away the tmux related parts of the script and see if you can simply start it as you would any other process and see if that works.

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

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

Re: Need terminal command to open maximised terminal and run script in it

Sat Jun 16, 2018 11:23 pm

The Traveler wrote:
Sat Jun 16, 2018 10:55 pm
I think you'll need to run your tmuxScript.sh in a headless system like Raspbian Lite for it work as you want. tmux in and of itself it is a console manager.

The problem intrigued me so I've spent some time looking for a solution. I could find none. In short, it appears tmux was not intended to work with a GUI window manager. The only "maybes" were i3 and dwm which are both tiling window managers but it was not certain. I couldn't find any reliable information demonstrating how to run a tmux session in anything but a headless system.

You could try and strip away the tmux related parts of the script and see if you can simply start it as you would any other process and see if that works.

Cheers.
The OP said everything works when run manually from command line prompt....
The script runs fine when I launch it manually. There is nothing wrong with the script. The script keeps running in the background and sends me notification e-mails. The window only closes when I open the window with the command:

Code: Select all

lxterminal -e /home/pi/Mining/tmuxScript.sh
Unless specified otherwise my response is based on the latest and fully updated Raspbian Buster w/ Desktop OS.

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

Re: Need terminal command to open maximised terminal and run script in it

Sat Jun 16, 2018 11:44 pm

The Traveler wrote:
Sat Jun 16, 2018 10:55 pm
I think you'll need to run your tmuxScript.sh in a headless system like Raspbian Lite for it work as you want. tmux in and of itself it is a console manager.

The problem intrigued me so I've spent some time looking for a solution. I could find none. In short, it appears tmux was not intended to work with a GUI window manager. The only "maybes" were i3 and dwm which are both tiling window managers but it was not certain. I couldn't find any reliable information demonstrating how to run a tmux session in anything but a headless system.

You could try and strip away the tmux related parts of the script and see if you can simply start it as you would any other process and see if that works.

Cheers.
Okay but what about this; there's this combination of buttons; I don't know the combination nor what it's called but if you press that combination you go away from the GUI to a command line and it's like a full-screen command line, like, behind the scenes. What if my script ran in that? Do you know what thing I'm talking about? It was on another system that I did it and it was like a year ago. I need to find out what that is called.
Raspberry Pi 3 B and B+
PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"
NAME="Raspbian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"

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

Re: Need terminal command to open maximised terminal and run script in it

Sat Jun 16, 2018 11:48 pm

The OP said everything works when run manually from command line prompt....
Yes. The problem I believe is that the tmux session is not being attached to the lxterminal shell when he starts it and I don't have a clear understanding of why. Running it manually works as the terminal spawned shell is already active. I've looked at quite a few possible solutions. There are a number of suggestion in this thread: https://stackoverflow.com/questions/110 ... ll-session if one wishes to try them.

They all seem to have potential problems and may require trial and error but, if the risk is acceptable and it works, well and good.

If I had an RPi with a GUI on it, I'd try them myself just to satisfy my curious nature. ;)

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
The Traveler
Posts: 360
Joined: Sat Oct 21, 2017 3:48 pm

Re: Need terminal command to open maximised terminal and run script in it

Sat Jun 16, 2018 11:57 pm

Okay but what about this; there's this combination of buttons; I don't know the combination nor what it's called but if you press that combination you go away from the GUI to a command line and it's like a full-screen command line, like, behind the scenes. What if my script ran in that?
Yep, generally speaking linux systems have both a single graphical window and up to 6 text terminal windows. Usually they are accessed by Ctrl + Alt + Fn using 1-7 for the n. F1-6 opens text terminals, F7 back to the graphical window. (At least on my Lubuntu laptop).

So, yes. You could try it with little risk I think if Raspbian works the same way. With tmux running in a single full terminal window may work for you. Once you have it running in a terminal window, you can verify it's PID by running something like "top | grep tmux" (substitute the actual name of your process). When you switch back to your GUI, you should be able to open an lxterminal and execute the same command to verify the tmuxScript process is still running. If so, there you go. :)

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

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

Re: Need terminal command to open maximised terminal and run script in it

Sun Jun 17, 2018 1:50 am

I can't use the virtual terminal since it's not compatible with VNC but I did find out how to modify my command so that it works without closing the window. The command I needed was:

Code: Select all

lxterminal -e tmux && /home/pi/Mining/tmuxScript.sh
The only problem I have with it now is that the window does not start maximised.
Raspberry Pi 3 B and B+
PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"
NAME="Raspbian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"

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

Re: Need terminal command to open maximised terminal and run script in it

Sun Jun 17, 2018 2:16 am

Heh, using && never occurred to me in this case to test truth for command execution. I use it mostly in bash scripting ...

Glad to hear you found a solution. :)

As for the maximize, you can create an desktop icon and pass some command parameters to lxterminal just for your tmux session. See this man page, http://manpages.ubuntu.com/manpages/pre ... nal.1.html --geometry=CHARACTERSXLINES before the -e should do it.

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

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

Re: Need terminal command to open maximised terminal and run script in it

Sun Jun 17, 2018 3:40 am

Thanks!

I wanted this to run every time my Pi turns on but nothing seems to happen after adding my line to the autostart file at

Code: Select all

~/.config/lxsession/LXDE-pi
at with an @ symbol appended. Is it possible to do it this way?

Code: Select all

@lxpanel --profile LXDE-pi
@pcmanfm --desktop --profile LXDE-pi
@xscreensaver -no-splash
@point-rpi

@lxterminal --geometry=126x45 -e tmux && /home/pi/Mining/tmuxScript.sh
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: 6550
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: Need terminal command to open maximised terminal and run script in it

Sun Jun 17, 2018 3:51 am

You could try xdotool. xdotool is a command line scripting tool which allows you to send keyboard and mouse commands.
This will Maximize the current window:

Code: Select all

xdotool windowsize $(xdotool getactivewindow) 100% 100%


Another way to do the same thing......
This command moves the mouse to x y coordinate of the maximize box and then clicks the left mouse button.

Code: Select all

xdotool mousemove 933 184 click 1
The x y coordinates will be different depending on screen resolution.
use xdotool getmouselocation to find the coordinates.

Code: Select all

sudo apt update
sudo apt install xdotool
Unless specified otherwise my response is based on the latest and fully updated Raspbian Buster w/ Desktop OS.

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

Re: Need terminal command to open maximised terminal and run script in it

Sun Jun 17, 2018 4:16 am

seanspotatobusiness wrote:
Sun Jun 17, 2018 3:40 am
Thanks!

....

@lxterminal --geometry=126x45 -e tmux && /home/pi/Mining/tmuxScript.sh[/code]
This works for me in autostart using a different script of course

Code: Select all

@lxterminal --geometry=126x45 -e myscript
The @ is optional.
Unless specified otherwise my response is based on the latest and fully updated Raspbian Buster w/ Desktop OS.

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

Re: Need terminal command to open maximised terminal and run script in it

Sun Jun 17, 2018 12:01 pm

klricks wrote:
Sun Jun 17, 2018 4:16 am
This works for me in autostart using a different script of course

Code: Select all

@lxterminal --geometry=126x45 -e myscript
The @ is optional.
Indeed this one works:

Code: Select all

@lxterminal --geometry=126x45 -e tmux
while these don't:

Code: Select all

@lxterminal --geometry=126x45 -e tmux && /home/pi/Mining/test.py                                                             
@lxterminal --geometry=126x45 -e tmux && /home/pi/Mining/tmuxScript.sh 
and I'm guessing it's the && which it doesn't like so I'm back to square one :'(

I tried removing 'tmux &&' and putting tmux in the script even though it's already there in the form 'tmux -2 new-session -d -s $SESSION' but all it does is create a terminal window with 'tmuxScript.sh' as the title with no script running in it.

Perhaps I can find another way to start my tmux session automatically without the ~/.config/lxsession/LXDE-pi/autostart file. There's five for me to go through here: https://www.dexterindustries.com/howto/ ... t-startup/
Raspberry Pi 3 B and B+
PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"
NAME="Raspbian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"

Return to “Beginners”