Page 1 of 1

Script file to open Terminal and run command?

Posted: Sat Jul 06, 2024 4:03 am
by FredW

I have several simple files that I use in main screen shortcuts to point my VPN to various locations. They are very simple and take the following form:

#!/bin/sh
windscribe connect seattle

I would like to make a file to keep in the same place that would then let me check if the command above is successful, instead of my usual method of checking, which involves opening a Terminal window and entering "windscribe status", after which windscribe will display my VPN location back into the same Terminal window. I haven't been able to figure out how to write a file that will do this. The closest I have come is finding that "xterm" will, in fact, open a Terminal window, but nothing I write afterwards in the script runs or appears in the Terminal window. How can I do what I want?

Another thought I had about it is that perhaps there would be a way to write the file just as

#!/bin/sh
windscribe status

but add something to the second line that would cause the result of the second line to display in a terminal window (or in something else that would be visible to me on the desktop). The word "pipe" comes to mind, but I'm really ignorant about this stuff even though I can sometimes hack out something that will work for me!


Re: Script file to open Terminal and run command?

Posted: Sat Jul 06, 2024 4:16 am
by williwaw

most desktop terminal emulators have options to

open a terminal window
run commands
and hold it open after the commands executes so you can see any output

for example

xterm -hold -e ls
should list the contentents of the present working directory

the -hold option varies if you are not using xterm
-e should be the last option before the windscribe command


Re: Script file to open Terminal and run command?

Posted: Sat Jul 06, 2024 4:24 am
by MochiMoppel
FredW wrote: Sat Jul 06, 2024 4:03 am

#!/bin/sh
windscribe status

Try

Code: Select all

#!/bin/sh
Xdialog --msgbox "$(windscribe status)" 0 0

Re: Script file to open Terminal and run command?

Posted: Sat Jul 06, 2024 4:36 am
by FredW

Thank you!

#!/bin/sh
xterm -hold -e windscribe status

works like a charm! ( Was hoping then that something like: xterm -hold -e echo "Finding windscribe status" windscribe status
would let me "title" the window, but it just printed everything after "echo". Hate to beg for more when it's not really necessary, but I'm always looking to learn.


Re: Script file to open Terminal and run command?

Posted: Sat Jul 06, 2024 4:58 am
by FredW

Thanks for the xterminal script! It really does what I want also.

And I have the same question as in my last post, if you don't mind: Is there a way to "stack" commands so they all can run in the same window or box?

For example, combine "windscribe connect Seattle". "sleep 10", and "windscribe status"?

Thanks again!


Re: Script file to open Terminal and run command?

Posted: Sat Jul 06, 2024 5:19 am
by FredW

With the xdialog command, I find I can do all three commands by just separating them inside the parenthesis with ";" Don't know about the way to do it with xterm. Thanks again!


Re: Script file to open Terminal and run command?

Posted: Sat Jul 06, 2024 5:27 am
by HerrBert

Assuming xterm is a script that runs urxvt, your commandline will look different:

Code: Select all

urxvt -title "Connecting to windscribe..." -e sh -c "windscribe connect Seattle; sleep 10; windscribe status; read -p \"FINISHED. PRESS ENTER KEY TO CLOSE THIS WINDOW\""

Re: Script file to open Terminal and run command?

Posted: Sat Jul 06, 2024 7:26 pm
by FredW

Fantastic, HerrBert ! I used your code as is; xterm is just something I came across and don't seem to need for what I wanted. Thanks very much to the both of you. Now I have a "Windscribe" folder in my-applications linked to the main screen that does everything I wanted. Plus, I'll have fun reading up on those commands.