-2

I have a folder where some files are written upon an event. I have a bash job that monitors the folder, upon recieving new file, it triggers a job to start.

here is what i am doing currently in crontab

@reboot /home/user/start_bash.sh

and in bash

#!/bin/bash

### Set initial time of file
LTIME=`stat -c %Z /home/client/data/*.txt`

while true
do
   ATIME=`stat -c %Z /home/client/data/*.txt`

   if [[ "$ATIME" != "$LTIME" ]]
   then
       Rscript /home/user/scripts/start_script.R

echo "Fertig."
LTIME=$ATIME
   fi
   sleep 5
done

now there is a requirement that we should update and restart the system every first sunday of the month at 2am.

EDIT: I would like to not to start the job from 01:55 and start the job at 2:30 AM every first Sunday of the month.

How can i achive this?

Thanks in advance.

sveer
  • 427
  • 3
  • 16

1 Answers1

1
55 01 1-7 * 7 /usr/bin/killall /home/user/start_bash.sh 

Run a script to kill the running process at 01:55 in the first 7 days of every month where the day of the month is Sunday

30 02 1-7 * 7 /home/user/start_bash.sh

Restart the script at 02:30 in the first 7 days of every month where the day of the month is Sunday

Raman Sailopal
  • 12,320
  • 2
  • 11
  • 18
  • is it okay to use ```@reboot``` to start the job after the reboot? – sveer Jan 19 '21 at 11:44
  • Thank you! another question, does kill all effects the runnig job that has already started? – sveer Jan 19 '21 at 11:59
  • 1
    Yeah, you said that you wanted to stop monitoring? – Raman Sailopal Jan 19 '21 at 12:00
  • yes, but it shall not stop the job that started already! bash file starts an R script, it take roughly a minute. it shall run and finish the job. but from 01:55 not further jobs shall start. – sveer Jan 19 '21 at 12:05
  • If the script is running to the foreground, then the process will be killed also. – Raman Sailopal Jan 19 '21 at 12:10
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/227533/discussion-between-sveer-and-raman-sailopal). – sveer Jan 19 '21 at 12:28