Score:0

How to Automatically run/stop a script at a certain time of the day

in flag

What I want to achieve:

8:00 AM:
Runs a sh script (this script does not stop running until the user presses ctrl+c)

8:00 PM: stops the script by sending ctrl+c or other means

Repeat

I tried researching crontab but I'm not sure about the stop script at 8 pm part.

user535733 avatar
cn flag
Scripts can be terminated by other scripts. See `man kill`
uz flag
Jos
Have script 1 write its PID (process ID) into a file somewhere: `cat "$$" > /path/to/myPID`. Script 2 reads that file and kills the process with that PID: `kill $(cat /path/to/myPID)`. Try it out.
vanadium avatar
cn flag
Systemd can do that.
Score:-1
in flag

I found a way. It turns out that the script I'm running is a nodejs program.
So here's my solution:
Script 1:
Infinite loop
If time is in the right interval to start script:
npm start
sleep

Script 2: Infinite loop If time is in the interval to stop the script:
killall npm
sleep

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.