Set time to automatically run and close the program Qt in Pi4 - linux

For some reason I need to run a Qt program on my Pi4 between 7am and 10pm, the rest of the time the program closes. This needs to happen automatically every day. I tried but it didn't work, the program couldn't open and close automatically as I wanted. Who can help me?

You can use crontab to run some script to start your program at 7am, then run another script to close the program at 10pm.
For example, add codes below in crontab and you can run and stop some program everyday.
0 7 * * * start.sh
0 22 * * * stop.sh
crontab tutorial

Related

How to configure cron to run at multiple random intervals?

I'm working on a new project and I would like to setup a cron to run every 6-8 hours at a random minute. Any suggestions on the best way to achieve this would be greatly appreciated.
Let's run the cron every 6 hours:
0 */6 * * * /path/to/script.sh
Now, in your bash script:
#!/bin/bash
maxdelay=$((2*60)) # 2 hours converted to minutes
delay=$(($RANDOM%maxdelay)) # a random delay
(sleep $((delay*60)); /path/to/script.sh) & # background a subshell to wait, then run the script
You can also use anacron for RANDOM_DELAY feature.

Cron job not running automatically for a non-root user

I am running SUSE Linux as a non-root user (getting root access also will not be a possibility). I would like to have a .sh script I created be run daily.
My crontab looks like:
0 0 * * * * /path/to/file.sh
I also have a line return after this as per many troubleshooting suggestions. My script deletes files older than 14 days. I also added a means to log output to check whether the script runs.
However, the job does not run automatically. I also am not able to check /var/log/messages for any notifications on whether cron can run or not.
What am I doing wrong? How can I check if cron itself is running/can run for my user? Do I have to supply cron with any paths or environment variables?
The correct approach to run your cron every midnight is:
00 00 * * * /bin/bash path/to/your/script.sh >> /path/to/log/file.log

Raspberry crontab script running

I'm trying to run a command by cron in Raspbian.
If I run ./sec_cam.sh, than my script runs, If I try to run it via crontab every 5 min, than nothing happens.
crontab -e shows me the followings:
*/5 * * * * ./sec_cam.sh
Did I configure the crontab wrong?
Thx in advance
scripts started from a cronjob are not setup with your usual environment, especially not with your current working directory (referenced by the . in ./sec_cam.sh). so to make this work you should specify a full path name like /home/user/sec_cam.sh

Using Cron to Reboot

I'm using a Raspberry Pi for a status display, but for whatever reason it gets incredabbly sluggish after a day or so of running so I wanted to reboot it every day so I setup a cron job to do that every morning at 8:50. But, it doesn't seem to be working. Is there anything special about using cron to do a reboot?
This is my crontab for the root user:
# m h dom mon dow command
50 8 * * * shutdown now -r >> /var/log/cron.log
0,30 * * * * date >> /var/log/cron.log
The second line works just fine, but I can't seem to get the restart command to work. It doesn't even output anything to the log.
Try using the fully specified path to shutdown. date may be in the PATH in roots cron environment, /sbin may not be looked up.
You need to edit the root user crontab
sudo crontab -e
then..
50 8 * * * reboot
Save and exit.

About system time in a bash script

I'm starting work on a bash script that will shutdown my computer at a certain time of day, but I'm not really sure what all specifically needs to go into that. Could someone post an example of how they would do it?
If you want to shut down at 22:15 every day, be root, run crontab -e, then add
15 22 * * * shutdown -h 5
on a line by itself.
Then save. At 22:15 every day, you will get a warning that the system will shut down in 5 minutes, and five minutes later, true to its word, it shuts down. If you want to abort the shutdown, run shutdown -c as root after the warning.

Resources