Friday, May 3, 2024
 Popular · Latest · Hot · Upcoming
0
rated 0 times [  0] [ 0]  / answers: 1 / hits: 818  / 2 Years ago, sun, may 29, 2022, 11:30:37

I want to run a command/shell script say script.sh from 1AM to 2AM per minute. After observing that crontab can't work it out 'per sec' I had to go with 'per min'.



Basically, My server.sh file takes backup of my database on server. This is done by three text files with names of tables in it, hence creating three backup archives. These backup archives are named like 'prefixYYYYmmdd', where prefix = heavy/light/weekly according to the backup type.



Now I want to copy these particular files after they are stored on server. Suppose the backup on server took 15 min. Now I should run the copy script-client.sh on my local computer. As this copy script doesn't know the names of the files just created by server, it should run per sec/min in the interval those files are being created by server and grab that file.



How to use crontab per min/sec within that time interval?


More From » backup

 Answers
6

First make a cron job that will start by 1 AM



 1 * * * /path_to_script/script.sh


In script.sh



#!/bin/bash
while true
do
find dir -mtime -1 -exec cp {} directory ;
TEST=`echo $(date +%H)`
if [ $TEST > 2 ]
then
exit 0
fi

sleep 1
done


Modify the find command to your need ( To find the files modified recently use mtime and use rsync if you want to back from a remote machine or just cp/mv in case it from a local machine)



This script will check for the date and if its beyond 2 AM it will exit automatically.



Hope this helps


[#35085] Tuesday, May 31, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ightrushi

Total Points: 129
Total Questions: 125
Total Answers: 127

Location: French Southern and Antarctic Lands
Member since Fri, Jan 6, 2023
1 Year ago
;