Sunday, April 28, 2024
0
rated 0 times [  0] [ 0]  / answers: 1 / hits: 944  / 2 Years ago, wed, october 5, 2022, 9:01:14

I wrote a script to call terminal and run a series of commands. The terminal comes up but no result of the other commands.
I named the file show-services-status.sh dropped it in the home directory and made it executable using chmod +x


show-services-status.sh contain the following commands:


gnome-terminal
echo "Display Manager Status"
sudo systemctl status display-manager.service
echo "System Log Status"
sudo systemctl status syslog.service


  1. Why does the terminal comes up without showing the result of the other commands?

  2. I started terminal manually and executed bash show-services-status.sh it worked but i have to press q on the keyboard before i see the result of the next command. how can this be eliminated?
    thanks


More From » command-line

 Answers
5

  1. because all the commands are being run sequentially in the same shell from which you execute the gnome-terminal command - rather than running inside the new gnome-terminal



  2. you can add the --no-pager option to the systemctl commands - see man systemctl




If you want to run the following commands inside the new gnome-terminal, you could wrap them in a shell and pass them as a command string, like:


gnome-terminal -- sh -c '
echo "Display Manager Status"
systemctl --no-pager status display-manager.service
echo "System Log Status"
systemctl status syslog.service
'

Note that I omitted --no-pager on the final systemctl command in order to hold the terminal open - otherwise it will likely close immediately, before you have time to read the results.


[#2371] Wednesday, October 5, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
rhaeams

Total Points: 115
Total Questions: 111
Total Answers: 103

Location: Burundi
Member since Wed, Nov 25, 2020
4 Years ago
;