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 Sun 22 Jul 2018, 14:46
All times are UTC - 4
 Forum index » House Training » Users ( For the regulars )
Code to start an application manually, then quit and restart
Moderators: Flash, Ian, JohnMurga
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [13 Posts]  
Author Message
Smithy


Joined: 12 Dec 2011
Posts: 897

PostPosted: Sun 18 Mar 2018, 08:36    Post subject:  Code to start an application manually, then quit and restart  

Hi, looking for some correct code to quit and restart an application.

1. Start Application manually. (The desktop File will call the shellscript with the following commands)
2. After 40 seconds, Application quits.
3. After 5 seconds, Application starts up again.
4. Repeats 2 and 3 ten times.

I don't think cron has the granularity of anything less than a minute, and I did try some exotic jiggery pokery with timer delays, but if the sleep command works properly in puppy then that should do the task ok?
Plus I couldn't find the presets I made in Ziggy's PSchedule (nothing in vary/spool/crontab) and anyways, have to wait for a minute for command number 3. to function..
Back to top
View user's profile Send private message 
Burn_IT


Joined: 12 Aug 2006
Posts: 3147
Location: Tamworth UK

PostPosted: Sun 18 Mar 2018, 08:39    Post subject:  

I suspect you will have to control this from a second application!!!
_________________
"Just think of it as leaving early to avoid the rush" - T Pratchett
Back to top
View user's profile Send private message 
matchpoint

Joined: 26 Jan 2018
Posts: 169

PostPosted: Sun 18 Mar 2018, 08:45    Post subject:  

https://stackoverflow.com/a/1034256

https://unix.stackexchange.com/a/11105
Back to top
View user's profile Send private message 
Smithy


Joined: 12 Dec 2011
Posts: 897

PostPosted: Sun 18 Mar 2018, 09:14    Post subject:  

Ok, I was being hardline on the 40 secs bit, it will eventually be 40 mins, but I wanted to test the script without waiting for that amount of time to see if it works.
But I definitely don't want to wait a minute for an application to restart.
It's a bug tester.
Two applications Burn IT? Fire away lol. Can't even think of that method atm.
Matchpoint if you have something appropriate could you post the condensed code here please?
Back to top
View user's profile Send private message 
matchpoint

Joined: 26 Jan 2018
Posts: 169

PostPosted: Sun 18 Mar 2018, 09:18    Post subject:  

Neither of those answers any good? They sure looked appropriate to me.
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1550
Location: Japan

PostPosted: Sun 18 Mar 2018, 09:25    Post subject:  

Maybe something like this:
Create a desktop icon with contents as in screenshot.
Here again the arguments for /bin/bash:
Code:
-c 'for i in {1..5}; do timeout -t4 gxmessage -c "No. $i of 5" ; sleep 3; done'

When clicking on the desktop icon the program (here gxmessage -c "No. $i of 5", but can be any other program) will start.
Program quits after 4 sec.
After another 3sec program starts again.
This will repeat 5 times.
StartStopCycletest.png
 Description   
 Filesize   17.68 KB
 Viewed   167 Time(s)

StartStopCycletest.png


Last edited by MochiMoppel on Sun 18 Mar 2018, 09:32; edited 2 times in total
Back to top
View user's profile Send private message 
Burn_IT


Joined: 12 Aug 2006
Posts: 3147
Location: Tamworth UK

PostPosted: Sun 18 Mar 2018, 09:30    Post subject:  

Try a scheduling application.
It is your problem and I am suggesting where/what to look at, but I am NOT going to do your searches for you, nor should anyone else.

_________________
"Just think of it as leaving early to avoid the rush" - T Pratchett
Back to top
View user's profile Send private message 
matchpoint

Joined: 26 Jan 2018
Posts: 169

PostPosted: Sun 18 Mar 2018, 11:20    Post subject:    

Great example Mochi. Thanks for the lesson.
Back to top
View user's profile Send private message 
Smithy


Joined: 12 Dec 2011
Posts: 897

PostPosted: Sun 18 Mar 2018, 13:26    Post subject:  

Thanks Mochi, that works really well!
Back to top
View user's profile Send private message 
drunkjedi


Joined: 24 May 2015
Posts: 897

PostPosted: Mon 19 Mar 2018, 10:42    Post subject:  

MochiMoppel wrote:
Here again the arguments for /bin/bash:
Code:
-c 'for i in {1..5}; do timeout -t4 gxmessage -c "No. $i of 5" ; sleep 3; done'
I wondered why it wouldn't run for me.
The timeout command would give me error "timeout: invalid option -- 't' "

Found answer after searching in "man timeout" and timeout command in "man busybox".

It seems Fatdog is using coreutil's timeout which just needs a number to specify time in sec. (you can also use suffix 's' for seconds (the default), 'm' for minutes, 'h' for hours or 'd' for days.)

And what MochiMoppel's code uses is busybox's timeout, which is what all Pups use.

Thanks MochiMoppel for the code. I learned something new today.

I will go slightly off-topic and ask couple of questions,

1) Is there a way to specify time in minutes or hours while using busybox's timeout. I couldn't find it.

2) While using "man" or "info" command is there a way to go to directly timeout or any other sub command in busybox? I had to scroll down really long man page of busybox.
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1550
Location: Japan

PostPosted: Mon 19 Mar 2018, 11:20    Post subject:  

drunkjedi wrote:
1) Is there a way to specify time in minutes or hours while using busybox's timeout.
Apparently not. Or use -t $((60*60*5)) if you need a timeout of 5 hours.

Quote:
2) While using "man" or "info" command is there a way to go to directly timeout or any other sub command in busybox? I had to scroll down really long man page of busybox.
"info"? And "man" is a symlink to BK's script pman, quite different from the original man command, which is not installed in my Slacko.

I normally find busybox's --help option sufficient:
Code:
# busybox timeout --help
BusyBox v1.21.0 (2013-02-18 15:57:06 WST) multi-call binary.

Usage: timeout [-t SECS] [-s SIG] PROG ARGS

Runs PROG. Sends SIG to it if it is not gone in SECS seconds.
Defaults: SECS: 10, SIG: TERM
Back to top
View user's profile Send private message 
drunkjedi


Joined: 24 May 2015
Posts: 897

PostPosted: Mon 19 Mar 2018, 12:43    Post subject:  

Thanks for answers MochiMoppel.

Fatdog has "man" and "info" commands and documents in it's devx sfs. Which shows much info about commands.

Without devx there's also a perl script called manweb, I haven't used it though.

Thanks again.
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1550
Location: Japan

PostPosted: Tue 20 Mar 2018, 11:00    Post subject:  

OK, that might explain why I've never seen them. I never load devx sfs.

If timeout command causes problems and intervals should be specified in minutes or hours, here is a solution that avoids timeout and uses sleep - sleep can even be specified in days Wink
Code:
for i in {1..5}; do gxmessage -c "No. $i of 5" & CPID=$! ; sleep 4 ; kill $CPID ; sleep 3; done
Stores the PID of the just started command in a variable, waits for the specified interval, then kills the command. After a 3 sec mourning period starts all over again. A serial killer app.
Back to top
View user's profile Send private message 
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.0445s ][ Queries: 12 (0.0045s) ][ GZIP on ]