1

I didn't get any idea of running the program daily after the specified date to idefinitely using crontab.

I tried below command but it's not working.

python3 $(date=$(date +%Y%m%d); if [ $date -gt 20180315 ]; then echo '--version'; else echo '/home/raman/Desktop/testp.py '; fi)

Where 20180315 = this is specified date after I have to run the program.

tripleee
  • 175,061
  • 34
  • 275
  • 318
Raman Kumar
  • 131
  • 8

1 Answers1

0

The solution is to convert the dates into seconds. Also it's better to make a bash script(say runPyAfterDate.sh) with the code below and save it in a suitable directory(I suggest mkdir ~/cronJobs).

Contents of runPyAfterDate.sh

#!/bin/sh
after=$(date -d 20180315 +%s); # 1521052200
curr=$(date +%s);  # currently 1521100701 
if [ $curr -gt $after  ]; then 
    python path/to/script.py; 
fi;

Don't forget to make it an executable:

sudo chmod +x runPyAfterDate.sh

In crontab you should put the following line:

@daily ~/cronJobs/runPyAfterDate.sh

Ref link: https://unix.stackexchange.com/questions/84381/how-to-compare-two-dates-in-a-shell

Udayraj Deshmukh
  • 1,814
  • 1
  • 14
  • 22