-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsetup_daily_pipeline.sh
executable file
·29 lines (22 loc) · 1.16 KB
/
setup_daily_pipeline.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/bin/bash
# Define variables
SCRIPT_PATH="/Users/mdayanarshad/Desktop/Data_Science_Projects/HFT_RealTime_DataPipeline/pipelines/run_pipeline.py"
VENV_PATH="/Users/mdayanarshad/Desktop/Data_Science_Projects/HFT_RealTime_DataPipeline/.conda"
CRON_TIME="0 22 * * *"
LOG_FILE="/Users/mdayanarshad/Desktop/Data_Science_Projects/HFT_RealTime_DataPipeline/pipeline_cronjob.log" # Log file path
# Check if the Python script exists
if [ ! -f "$SCRIPT_PATH" ]; then
echo "$(date) - Error: Script $SCRIPT_PATH does not exist. Exiting." >> "$LOG_FILE"
exit 1
fi
# Check if the virtual environment exists
if [ ! -d "$VENV_PATH" ]; then
echo "$(date) - Error: Virtual environment $VENV_PATH does not exist. Exiting." >> "$LOG_FILE"
exit 1
fi
# Create the command to activate the virtual environment and run the script
CMD="source $VENV_PATH/bin/activate && python $SCRIPT_PATH && deactivate"
# Add the cron job
(crontab -l 2>/dev/null | grep -v "$SCRIPT_PATH"; echo "$CRON_TIME $CMD >> $LOG_FILE 2>&1") | crontab -
# Display confirmation and log it
echo "$(date) - Cron job scheduled to run $SCRIPT_PATH daily at 10 PM using the virtual environment $VENV_PATH." >> "$LOG_FILE"