Terminal on Autostart [SOLVED]

Quick to answer questions about finding your way around Linux Mint as a new user.
Forum rules
There are no such things as "stupid" questions. However if you think your question is a bit stupid, then this is the right place for you to post it. Stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions use the other forums in the support section.
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
jay1077
Level 1
Level 1
Posts: 4
Joined: Mon Jun 21, 2021 1:35 am

Terminal on Autostart [SOLVED]

Post by jay1077 »

Hello,

I am relative new to Linux.
I need to check many Laptops Batterys, out of this reason i created a USB Stick with Linux Mint.
I already installed acpitool to check the stat of the batteries.
Now i want at the startup of Linux to open a terminal which executes the command acpitool -BV.
I was able to get the terminal on Startup.
I reated a new command on startup.
The command is /usr/bin/gnome-terminal
But whatever i do i cannot open the terminal and have the command executed.
I dont know what to enter in the autostart so that the terminal opens and i see the fulfilled command.
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
dave0808
Level 5
Level 5
Posts: 973
Joined: Sat May 16, 2015 1:02 pm

Re: Terminal on Autostart

Post by dave0808 »

The issue is that the whilst you can get the terminal to run a command, it will terminate and close afterwards, so the "trick" is to create a small shell script that runs the required command and then waits for user input before closing. So create a file, for example /usr/local/sbin/battcheck and add the following contents...

Code: Select all

#!/bin/bash
acpitool -BV
read x
You'll need to change the permissions so that it can be executed. You should also change the owner so that no other user can alter the contents of the script and make it do something that you don't want...

Code: Select all

cd /usr/local/sbin
sudo chmod 755 battcheck
sudo chown root:root battcheck
./battcheck
The final line above will run your command and then wait for you to enter something on the keyboard, at this point simply pressing <ENTER> is enough.

Now you can simply add your autostart command to be /usr/bin/gnome-terminal -- /usr/local/sbin/battcheck. Note the double dash after 'gnome-terminal'. That worked on my Mint 20.1 system.
jay1077
Level 1
Level 1
Posts: 4
Joined: Mon Jun 21, 2021 1:35 am

Re: Terminal on Autostart

Post by jay1077 »

Thank you very much.
Now my Linux starts with the terminal and shows me the capacity :)
dave0808
Level 5
Level 5
Posts: 973
Joined: Sat May 16, 2015 1:02 pm

Re: Terminal on Autostart

Post by dave0808 »

Good to know that it works for you.

Another option, would be to use a command called watch, which will repeat the command that it is given. So rather than passing the 'battcheck' script as the gnome-terminal argument, you could do the following instead...

Code: Select all

gnome-terminal -- watch -n 5 acpitool -BV
This would keep the terminal window open, running the command every 5 seconds. You can stop it at any time using Ctrl-C and the terminal will close.

Please mark your topic as solved for future readers.
Locked

Return to “Beginner Questions”