Code to start an application manually, then quit and restart

Using applications, configuring, problems
Post Reply
Message
Author
User avatar
Smithy
Posts: 1151
Joined: Mon 12 Dec 2011, 11:17

Code to start an application manually, then quit and restart

#1 Post by Smithy »

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..

User avatar
Burn_IT
Posts: 3650
Joined: Sat 12 Aug 2006, 19:25
Location: Tamworth UK

#2 Post by Burn_IT »

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


User avatar
Smithy
Posts: 1151
Joined: Mon 12 Dec 2011, 11:17

#4 Post by Smithy »

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?

matchpoint
Posts: 168
Joined: Fri 26 Jan 2018, 20:54

#5 Post by matchpoint »

Neither of those answers any good? They sure looked appropriate to me.

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#6 Post by MochiMoppel »

Maybe something like this:
Create a desktop icon with contents as in screenshot.
Here again the arguments for /bin/bash:

Code: Select all

-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.
Attachments
StartStopCycletest.png
(17.68 KiB) Downloaded 190 times
Last edited by MochiMoppel on Sun 18 Mar 2018, 13:32, edited 2 times in total.

User avatar
Burn_IT
Posts: 3650
Joined: Sat 12 Aug 2006, 19:25
Location: Tamworth UK

#7 Post by Burn_IT »

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

matchpoint
Posts: 168
Joined: Fri 26 Jan 2018, 20:54

#8 Post by matchpoint »

Great example Mochi. Thanks for the lesson.

User avatar
Smithy
Posts: 1151
Joined: Mon 12 Dec 2011, 11:17

#9 Post by Smithy »

Thanks Mochi, that works really well!

User avatar
drunkjedi
Posts: 882
Joined: Mon 25 May 2015, 02:50

#10 Post by drunkjedi »

MochiMoppel wrote:Here again the arguments for /bin/bash:

Code: Select all

-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.

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#11 Post by MochiMoppel »

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.
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: Select all

# 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

User avatar
drunkjedi
Posts: 882
Joined: Mon 25 May 2015, 02:50

#12 Post by drunkjedi »

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.

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#13 Post by MochiMoppel »

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: Select all

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.

Post Reply