I would like to configure my Express Server to stop automatically at 3:00 pm on Saturdays and restart at 4:00am on Mondays. How could I do this ?
Also, I would like it to restart automatically if it crashes without waiting for file changes (I'm using nodemon).
You can write scripts that starts and kills the server and add them in a cronjob service, for example cron in linux.
For example: say script start.sh and stop.sh are in home directory that start and stop your server.
Add these lines to crontab file:
00 15 * * 6 ~/start.sh
00 04 * * 1 ~/stop.sh
First line: 3 PM on all Saturdays
Second line: 4 AM on all Mondays
Reference: Link
Related
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
I've been running a shell script every minute between Monday and Friday between business hours, and thought it was running fine, as I can see it when I use the "crontab -l" command. The script calls a piece of Java code which checks certain conditions in a postgresql table, and if those conditions are met, it writes out to another table. The script is in the following directory on our Linux server.
/var/lib/tomcat7/webapps/sh
So lets say it is called "test.sh", should my cronjob look like this this:
* 08-18 * * 1-5 /var/lib/tomcat7/webapps/sh/test.sh
ie, it should run every minute of every day from Monday to Friday between 8 am and 18:59 pm. I just tried testing it by adding dummy data to the postgresql table so that the other table should have been written to and nothing happened. However when i ran ./test.sh manually from the command line it worked fine. The issue seems to be with my cron. If I type:
grep CRON /var/log/syslog
I can see that it has run every minute today. The output looks like this
Nov 25 12:38:01 webserver CRON[11868]: (ubuntu) CMD (/var/lib/tomcat7/webapps/sh/test.sh)
Nov 25 12:39:01 webserver CRON[11888]: (ubuntu) CMD (/var/lib/tomcat7/webapps/sh/test.sh)
Nov 25 12:40:01 webserver CRON[11953]: (ubuntu) CMD (/var/lib/tomcat7/webapps/sh/test.sh)
Nov 25 12:41:01 webserver CRON[11953]: (ubuntu) CMD (/var/lib/tomcat7/webapps/sh/test.sh)
Nov 25 12:42:01 webserver CRON[11985]: (ubuntu) CMD (/var/lib/tomcat7/webapps/sh/test.sh)
etc.. However after I altered the data in the postgresql table this did not seem to have any effect. It's as if the script isn't actually running. Although it runs perfectly when I run it manually from the command line.
Has anyone ever experienced this sort of thing with cron jobs, or have any advice as to why this might be happening? Any assistance would be appreciated. Thanks in advance!
Your working directory is not /var/lib/tomcat7/webapps/sh but / when you launch your script with /var/lib/tomcat7/webapps/sh/test.sh
You can get the current working directory with pwd command or get the script location (see this post and then :
cd $SCRIPTPATH
cd ../java/JProject/sr
OR
change relative path ../java/JProject/src with the absolute path
I have a simple script that runs perfectly when used manually. When I entered into my crontab to run at 10 PM each night it appears to run several instances of the script, and times out my server. Any ideas?
22 * * * /mnt/myscript.sh
you are doing it wrong. It should've been
00 22 * * /mnt/myscript.sh.
Read about crons here.
https://access.redhat.com/site/documentation/en-US/Red_Hat_Enterprise_Linux/5/html/Deployment_Guide/ch-autotasks.html
I have created scripts and now I want them to run automatically at specified time, how can I do that?
I am using Ubuntu and JAVA to write my scripts.
You can use crontab to do this in a specific time continuously.
To edit a crontab entries, Login as root user (su – root) and do crontab -e as shown below. By default this will edit the current logged-in users crontab.
root#dev-db# crontab -e
Scheduling a Job For a Specific Time
The basic usage of cron is to execute a job in a specific time as
shown below. This will execute the Full backup shell script
(full-backup) on 10th June 08:30 AM.
Please note that the time field uses 24 hours format. So, for 8 AM use 8, and for 8 PM use 20.
30 08 10 06 * /home/ramesh/full-backup
More example here, and the crontab utils can be found here
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.