I need to set a program in cron which is set in such a way that it restarts everytime the program is terminated
why do i want to do this job?
The program is actually extracting information from a website using web scraping and it terminates when it reaches the point where the information is up-to- date
This the part of the python code
    sql = """SELECT Short_link FROM Properties WHERE Short_link=%s"""
            rows = cursor.execute(sql,(link_result))
            print rows
            if rows>=1:
                print "Already present"
                sys.exit()
            else:
        query="""INSERT INTO Properties (Published_Date, Title,Price,Bedroom,Agency_Fee, Bathroom, Size,Prop_ref,Furnished_status,Rent_payment,Building_info,Amenities,Trade_name,Licence, RERA_ID,Phone_info,Short_link) values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"""
        cursor.execute(query,(date_result, title_result, price_result, bedroom_result, agencyfee_result, bathroom_result, size_result, propertyref_result, furnished_result, rent_is_paid_result, building_result, Amenities_result, tradename_result, licencenum_result, reraid_result, phone_result, link_result))
The script is as follows: run.sh
#!/bin/bash
    PATH=$PATH:/bin:/usr/bin
    
    date +'%H:%M:%S Started' >> /home/ahmed/Desktop/log.txt
    
    TMP_FILE=/tmp/i_am_running
    [ -f $TMP_FILE ] && exit
    touch $TMP_FILE
    
    date +'%H:%M:%S Starting Python' >> /home/ahmed/Desktop/log.txt
    /usr/bin/python /home/ahmed/Desktop/python.py
    rm $TMP_FILE
    
    date +'%H:%M:%S Ended' >> /home/ahmed/Desktop/log.txt
The cron command i am using is * * * * * /home/ahmed/Desktop/run.sh
The log file is as follows:
15:21:01 Started
15:21:02 Starting Python
15:22:02 Started
15:23:01 Started
15:24:01 Started
15:24:30 Ended
15:25:01 Started
15:25:01 Starting Python
15:26:01 Started
15:27:18 Started
15:28:01 Started
15:29:01 Started
15:30:01 Started
15:31:01 Started
15:31:16 Ended
15:32:01 Started
15:32:01 Starting Python
15:33:01 Started
15:34:01 Started
It seems like the program is restarted before its ended. the log file should have starting program, started, ended, starting program, started, ended and so on.
Can someone guide me please? perhaps there are some changes need in the bash script? how can i set the program to starting, started, ended and so on
 
     
     
    