-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.sh
More file actions
67 lines (64 loc) · 2.51 KB
/
run.sh
File metadata and controls
67 lines (64 loc) · 2.51 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
# Function to calculate the difference in minutes between two times
time_diff_in_minutes() {
local start_time=$1
local end_time=$2
local start_seconds=$(date -d "$start_time" +%s)
local end_seconds=$(date -d "$end_time" +%s)
local diff_seconds=$((end_seconds - start_seconds))
local diff_minutes=$((diff_seconds / 60))
echo $diff_minutes
}
# Function to execute the custom command between 10 PM and 11 PM
execute_custom_command() {
# Check if the custom command has already been executed today
if [ ! -f "/tmp/custom_command_executed" ]; then
# Run the monthly_update.py script
python3 ./Python/monthly_update.py
# Add and commit all untracked and modified files except main.cpp
./commit.sh "Automatic commit $(date '+%Y-%m-%d %H:%M:%S')"
# Mark that the custom command has been executed today
touch "/tmp/custom_command_executed"
else
# Get the modification time of the file
modified_time=$(stat -c %Y /tmp/custom_command_executed)
# Calculate the time difference in seconds
current_time=$(date +%s)
time_diff=$((current_time - modified_time))
# echo ${time_diff}
# Check if more than 24 hours have passed since the last execution
if [ $time_diff -ge 1800 ]; then
echo "More than half an hour has passed since the last execution."
# Remove the file to allow execution again
rm /tmp/custom_command_executed
else
echo "Less than half an hour has passed since the last execution. Skipping."
return
fi
fi
}
# Get the start time from the main.cpp file
start_time=$(grep "// Start Time:" main.cpp | awk '{print $4}')
# Get the current time for the end time
end_time=$(date '+%H:%M:%S')
# Calculate the time taken in minutes
time_taken=$(time_diff_in_minutes "$start_time" "$end_time")
# Compile the main.cpp file
g++ -DLOCAL -g -fsanitize=address,undefined -o main main.cpp
success=$?
if [ $success -eq 0 ]; then
echo "Start of Program"
echo
./main < input.txt > output.txt
echo
echo "End of Program"
# Replace End Time and Time Taken fields if they exist
sed -i "s|// End Time :.*|// End Time : $end_time|" main.cpp
sed -i "s|// Time Taken:.*|// Time Taken: $time_taken minutes|" main.cpp
# Execute the custom command between 7 AM and 11 PM
execute_custom_command
else
echo "Compilation failed!"
fi
# Clean up
rm -rf main