Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Wed 14 Nov 2018, 23:47
All times are UTC - 4
 Forum index » House Training » Users ( For the regulars )
How can I automate the execution of a terminal command?
Moderators: Flash, Ian, JohnMurga
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [13 Posts]  
Author Message
Mike Walsh


Joined: 28 Jun 2014
Posts: 4365
Location: King's Lynn, UK.

PostPosted: Tue 12 Jun 2018, 13:31    Post subject:  How can I automate the execution of a terminal command?
Subject description: Perhaps not a very good description. Let me explain further.....
 

Afternoon, all.

We all know you can start any executable process from the terminal. You open the terminal, type in the path to the command, then hit 'Enter'.....and the process will start.

If it's a command-line app/program/process, you type the path-to-the-executable, hit 'Enter', and then the app/whatever will run in the terminal, showing the output as it does so. With me so far?

Now then; this is my question. How can I automate that process with a script?

I want to open a terminal (in this case, sakura), then, with the terminal open, execute the app/whatever within the terminal, and see the output progressing in the terminal.....just as though I'd manually typed it in. But without actually typing anything. (Does that make sense?)

Is this possible? I've tried several variations-on-a-theme, using example from AskUbuntu and SuperUser, but all I get is the terminal opening. The app/whatever won't actually run....or if it does, it's not showing me what's happening.

Where am I going wrong?

(Flash; this is probably in the wrong place. Can you move it, if deemed necessary? Thanks.)


Mike. Wink

_________________
MY PUPPY PACKAGES | 'Thanks' are always appreciated!
--------------------------------------


Last edited by Mike Walsh on Tue 12 Jun 2018, 14:15; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website 
dancytron

Joined: 18 Jul 2012
Posts: 1152

PostPosted: Tue 12 Jun 2018, 13:37    Post subject:  

If I understand correctly, the way I've done it (blatantly copied from Fred) is to use 2 scripts:

As an example:
The starter script:

Quote:

#!/bin/bash

xterm -T "Remove All Chrome Settings" -si -sb -fg white -bg SkyBlue4 -geometry 80x22 -e /usr/local/bin/RemoveAllChromeSettings.sh


The main script
Quote:

#!/bin/sh

# Deletes all Chrome user settings and caches. Mostly for prior to remaster. Use caution.

echo "CAUTION"
echo "This script deletes all Chrome user settings and cache files for all users."
echo "This is mainly useful for remastering."
echo "If that is not what you want to do, press Control-C now."
read -sp "Press ENTER to continue if you are sure"
clear
echo
set -x #echo on
rm -r /home/cat/.config/google-chrome ; rm -r /home/cat/.cache/google-chrome ; rm -r /home/cat/chrome ; rm -r /home/puppy/chrome ; rm -r /root/.config/google-chrome ; rm -r /root/chrome ; rm -r /home/puppy/.config/google-chrome ; rm -r /home/puppy/.cache/google-chrome ; rm -r /root/.cache/google-chrome ; rm -r /live/image/ChromeSettings/google-chrome
set +x #echo off
read -sp "Press ENTER to close"
Back to top
View user's profile Send private message 
Mike Walsh


Joined: 28 Jun 2014
Posts: 4365
Location: King's Lynn, UK.

PostPosted: Tue 12 Jun 2018, 14:23    Post subject:  

Hi, Dan.

Mm. O-kayyyy... yeah, fine.

What I want to be able to do is this: to click on a MenuEntry, to have a terminal open, then for the script execution command to enter, and the script to run, showing its output as it does so. I want to do all this as though I'd opened a terminal, typed a command in, then hit 'Enter'.....but I want this to happen without actually doing all that. Just a single click on a Menu Entry, and it'll automatically happen.

I'm probably not making much sense, am I? Laughing

(You're all thinking to yourselves, 'If he wants to run a command-line app, why doesn't he just open the terminal, type the command in, and hit the Enter key? What's so hard about that???')

That's exactly what I do want to do.....but I would like to automate it by clicking on a script, rather than physically performing those actions.


Mike. Wink

Last edited by Mike Walsh on Tue 12 Jun 2018, 16:05; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website 
dancytron

Joined: 18 Jul 2012
Posts: 1152

PostPosted: Tue 12 Jun 2018, 14:56    Post subject:  

That's what it does.

Look in any for Fred's distros in /usr/local/bin at any of the scripts that end with "-start" to see how he uses it.

Remember if you want to see it run, you have to pause it at the end otherwise the script will finish and close the window before you can read it.
Back to top
View user's profile Send private message 
mjmikulcik

Joined: 09 Jun 2017
Posts: 32

PostPosted: Tue 12 Jun 2018, 14:59    Post subject:  

You could try

xterm -hold -e (then whatever path for your executable)

for example:

Code:
#!/bin/sh
xterm -hold -e ppm


The hold flag keeps the terminal from closing after it finishes
Back to top
View user's profile Send private message 
Mike Walsh


Joined: 28 Jun 2014
Posts: 4365
Location: King's Lynn, UK.

PostPosted: Tue 12 Jun 2018, 16:16    Post subject:  

@ Dan/mjmikulclk:-

I'll give these a try - probably tomorrow, now - and let you know how I get on. Cheers, guys.


Mike. Wink

_________________
MY PUPPY PACKAGES | 'Thanks' are always appreciated!
--------------------------------------

Back to top
View user's profile Send private message Visit poster's website 
ETP


Joined: 19 Oct 2010
Posts: 1111
Location: UK

PostPosted: Tue 12 Jun 2018, 17:31    Post subject:  

Hi Mike,

Something along the lines as in the linked screenshot below may meet your needs.
It is a technique that I have used in all of my DLNA Pups since Nov 2015 without change.

The composite shot is from the current one, DLNA Quirky Xerus64-V2.
Start with the desktop file at the bottom of the screen which points at the
script on the top left. The terminal output (read only) is in the top right window.

Full sized screen-shot here: (Press F11 to toggle into full screen then click on link)

https://drive.google.com/uc?export=view&id=1_hxDEcjPXMvVvvaxFDs95_VXVs1M-oLb

_________________
Regards ETP

Kennels
Back to top
View user's profile Send private message 
nosystemdthanks

Joined: 03 May 2018
Posts: 350

PostPosted: Tue 12 Jun 2018, 18:00    Post subject:  

im 90% certain i get what youre saying mike, and while the solutions presented here are probably going to do exactly what you want, i will speak more generally and say:

most term window programs (xterm, lxterm, etc) have a command line option to "run a command" when they open.

so you just look up the switches for whichever term window youre using, and then look for the one that runs a command.

some likely have options for staying open after the command is run, or doing the opposite.

once you have the command to open the term with the program already running, you just put that in a script and voila-- a script to run a term with a command in it.

now, if you want to create a script that will do this for all sorts of commands rather than a specific one-- thats also very possible, either through further scripting-- or rox-filer already has this as a feature.

for now i assume you mean you want to open it with a specific command running. yes, thats what the solutions here do.

please note: i realise youre an experienced puppy user and should this come off as condescending, its really not intended-- we are all trying really hard not to be vague or misunderstood in this thread.

_________________
the end of the distro war, and the distro https://ptpb.pw/OnBT
Back to top
View user's profile Send private message Visit poster's website 
fredx181


Joined: 11 Dec 2013
Posts: 3532
Location: holland

PostPosted: Tue 12 Jun 2018, 18:19    Post subject:  

Hi Mike,
Perhaps best is that you give one or more examples of what you'd like to run in terminal.

Fred

_________________
Dog Linux website
Back to top
View user's profile Send private message 
Mike Walsh


Joined: 28 Jun 2014
Posts: 4365
Location: King's Lynn, UK.

PostPosted: Tue 12 Jun 2018, 19:37    Post subject:  

fredx181 wrote:
Hi Mike,
Perhaps best is that you give one or more examples of what you'd like to run in terminal.

Fred


Fair comment!

What I want to do this with is the attached .pet; a system information tool, which I found on OMG Ubuntu! earlier on yesterday. You install it, then run

Code:
neofetch


.....in the terminal, for 'basic' info.

Code:
neofetch --travis


.....gives more detailed info.

What I want to do is to add a Menu entry, because I think this could prove useful to newbies when we ask them their system info. You d/l it, you click to install, you go into the Menu and click the MenuEntry to run it.....and you get the info required.

Remember, most of these are coming to Puppy (and Linux in general) from Windows. Many of them don't even know what a terminal is, much less where to find it. This way, they get to give us what we ask of them, and they get to see a terminal for the first time.

Myself, I use Sakura.....but I'd set this to use urxvt, 'cos it comes as standard in Pup.

Perhaps I'm simply being over-complicated for the sake of it. Probably just as easy to get them to run it in the terminal first as last..... It's an enormous script, but 90% of it is different sets of ASCII character encoding to represent the logos of all the major Linux distros.....and many of the smaller ones, too. There's even a 'Puppy' logo, though I haven't yet figured out which bits need to be uncommented to make it active..!

----------------------------

nosystemdthanks wrote:
please note: i realise youre an experienced puppy user and should this come off as condescending, its really not intended-- we are all trying really hard not to be vague or misunderstood in this thread.


'Experienced'; hmmm.....that's debatable! Laughing Anyway, I'm fairly laid back at the best of times; I don't easily take offence. (Unlike certain individuals from north of the Great Lakes.....who shall remain nameless.)

And I freely admit I don't always express myself as clearly as I could. I know what I want to say, but don't always put it into words as well as I might..... Smile



Mike. Wink
neofetch-4.0.2_1-noarch.pet
Description  Neofetch command-line system info tool
pet

 Download 
Filename  neofetch-4.0.2_1-noarch.pet 
Filesize  75.06 KB 
Downloaded  47 Time(s) 

_________________
MY PUPPY PACKAGES | 'Thanks' are always appreciated!
--------------------------------------

Back to top
View user's profile Send private message Visit poster's website 
nosystemdthanks

Joined: 03 May 2018
Posts: 350

PostPosted: Tue 12 Jun 2018, 19:55    Post subject:  

urxvt -e sh -c 'neofetch ; read p'
_________________
the end of the distro war, and the distro https://ptpb.pw/OnBT
Back to top
View user's profile Send private message Visit poster's website 
Mike Walsh


Joined: 28 Jun 2014
Posts: 4365
Location: King's Lynn, UK.

PostPosted: Tue 12 Jun 2018, 20:30    Post subject:  

@ nosystemdthanks:-

Code:
urxvt -e sh -c 'neofetch ; read p'


.....works a treat. That'll do nicely..! And by referring to an earlier post, and consulting the help file, I have it working how I want in Sakura, with

Code:
sakura --hold -e sh -c 'neofetch ; read p'


So; thanks for the 'inspiration' on that one, too. Just out of curiosity, what do the '-e' and '-c' flags do? (Scratch that, the Sakura help file tells me '-e' is execute (obviously), but '-c'? 'Columns'? Not too sure what that actually does..... And, er....'read p'?)

(See, I may have produced many packages for Puppy & the community, but even there, I tend to go with what's relatively easy to put together, or where it's easy to 'modify' an existing package. I freely admit I'm no more than an enthusiastic amateur (definitely no 'script jockey'); when it comes to relatively simple stuff like this, I'm still learning!)

Anyway; cheers, boys & girls! Smile


Mike. Wink

_________________
MY PUPPY PACKAGES | 'Thanks' are always appreciated!
--------------------------------------

Back to top
View user's profile Send private message Visit poster's website 
nosystemdthanks

Joined: 03 May 2018
Posts: 350

PostPosted: Tue 12 Jun 2018, 20:46    Post subject:  

Mike Walsh wrote:
I tend to go with what's relatively easy to put together, or where it's easy to 'modify' an existing package. I freely admit I'm no more than an enthusiastic amateur;


i wrote my own programming language with that philosophy-- i mean: when writing the translator itself, i went with what was easy to put together, or where its easy to modify or wrap an existing command.

when i teach, i teach in this style. people can learn how to "go pro" once they are comfortable with the subject. linus torvalds himself started by playing with simple things: https://www.youtube.com/watch?v=S5S9LIT-hdc its obviously a good way to learn.

the educational system (in most of the world, really) creates a visceral fear of learning. making people excited to learn is a lot easier without the fear of making unimportant mistakes (though by the time youre working on mission critical, or studying medicine, some harshness is called for.)

i learned a lot of my foundational gnu/linux skills on this very forum. mounting iso files? learned it here. python? learned it from playing with this friendly educational ide on the sugar platform 3 years later: https://www.youtube.com/watch?v=WLHl0UfXDdo well, then i read "think python" but i probably wouldnt have without the friendly intro. and i already knew basic, from this: https://www.ebay.com/p/Vintage-Hands-on-Basic-for-The-IBM-PCjr-Personal-Computer-Self-Tutor-Book-1983/1608184855

_________________
the end of the distro war, and the distro https://ptpb.pw/OnBT
Back to top
View user's profile Send private message Visit poster's website 
Display posts from previous:   Sort by:   
Page 1 of 1 [13 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » House Training » Users ( For the regulars )
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0655s ][ Queries: 13 (0.0088s) ][ GZIP on ]