-
Notifications
You must be signed in to change notification settings - Fork 2
RDKB-63303, RDKB-63414 : Move RdkLogger Scripts to Cron #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,4 +1,4 @@ | ||||||
| #!/bin/sh | ||||||
|
Check failure on line 1 in fileUploadRandom.sh
|
||||||
| ########################################################################## | ||||||
| # If not stated otherwise in this file or this component's Licenses.txt | ||||||
| # file the following copyright and licenses apply: | ||||||
|
|
@@ -34,7 +34,17 @@ | |||||
| SELFHEAL_PATH="/usr/ccsp/tad" | ||||||
| CERT_CHECKER_PATH="/lib/rdk" | ||||||
|
|
||||||
| calcRandTimeandUpload() | ||||||
| CRON_MODE=0 | ||||||
| FILEUPLOAD_TMP_DIR="/tmp/.fileupload_random" | ||||||
| RANDOM_DELAY_FILE="$FILEUPLOAD_TMP_DIR/.remaining_secs" | ||||||
| TICK_FILE="$FILEUPLOAD_TMP_DIR/.tick" | ||||||
| CRON_INSTALLED_FLAG="$FILEUPLOAD_TMP_DIR/.cron_installed" | ||||||
|
|
||||||
| if [ ! -d "$FILEUPLOAD_TMP_DIR" ]; then | ||||||
| mkdir -p "$FILEUPLOAD_TMP_DIR" | ||||||
| fi | ||||||
|
|
||||||
| generate_random_delay() | ||||||
| { | ||||||
| rand_hr=0 | ||||||
| rand_min=0 | ||||||
|
|
@@ -45,15 +55,71 @@ | |||||
|
|
||||||
| # Calculate random second | ||||||
| rand_sec=`awk -v min=0 -v max=59 -v seed="$(date +%N)" 'BEGIN{srand(seed);print int(min+rand()*(max-min+1))}'` | ||||||
|
|
||||||
| # Calculate random hour | ||||||
| rand_hr=`awk -v min=0 -v max=2 -v seed="$(date +%N)" 'BEGIN{srand(seed);print int(min+rand()*(max-min+1))}'` | ||||||
|
|
||||||
| echo_t "RDK Logger : Random Time Generated : $rand_hr hr $rand_min min $rand_sec sec" | ||||||
| echo_t "RDK Logger : Random Time Generated : $rand_hr hr $rand_min min $rand_sec sec" >&2 | ||||||
|
|
||||||
| min_to_sleep=$(($rand_hr*60 + $rand_min)) | ||||||
| sec_to_sleep=$(($min_to_sleep*60 + $rand_sec)) | ||||||
| sleep $sec_to_sleep; | ||||||
|
|
||||||
| echo "$sec_to_sleep" | ||||||
| } | ||||||
|
|
||||||
| calcRandTimeandUpload() | ||||||
| { | ||||||
| delay_completed=0 | ||||||
| if [ "$CRON_MODE" = "1" ]; then | ||||||
| if [ ! -f "$RANDOM_DELAY_FILE" ]; then | ||||||
| sec_to_sleep=$(generate_random_delay) | ||||||
| echo "$sec_to_sleep" > "$RANDOM_DELAY_FILE" | ||||||
| echo_t "fileupload_random: Initial random delay stored: $sec_to_sleep seconds" >&2 | ||||||
| else | ||||||
| echo_t "fileupload_random: Random delay already generated, reusing existing value" >&2 | ||||||
| fi | ||||||
|
|
||||||
| if [ -f "$TICK_FILE" ]; then | ||||||
| current_tick=$(cat "$TICK_FILE") | ||||||
| else | ||||||
| current_tick=0 | ||||||
| fi | ||||||
|
|
||||||
| if [ "$current_tick" = "0" ]; then | ||||||
| remaining=$(cat "$RANDOM_DELAY_FILE" 2>/dev/null) | ||||||
| [ -z "$remaining" ] && remaining=0 | ||||||
|
|
||||||
| if [ "$remaining" -le 300 ]; then | ||||||
| echo_t "fileupload_random: Sleeping $remaining seconds NOW" >&2 | ||||||
| [ "$remaining" -gt 0 ] && sleep "$remaining" | ||||||
| rm -f "$RANDOM_DELAY_FILE" "$TICK_FILE" | ||||||
| delay_completed=1 | ||||||
| else | ||||||
| echo_t "fileupload_random: Remaining delay before upload: $remaining seconds" >&2 | ||||||
| new_remaining=$((remaining - 300)) | ||||||
| if [ "$new_remaining" -lt 0 ]; then | ||||||
| new_remaining=0 | ||||||
| fi | ||||||
| echo $new_remaining > "$RANDOM_DELAY_FILE" | ||||||
| echo_t "fileupload_random: Updated remaining delay to $new_remaining seconds, exiting" >&2 | ||||||
| fi | ||||||
| else | ||||||
| echo_t "fileupload_random: Skipping countdown this minute (tick=$current_tick/4)" >&2 | ||||||
| fi | ||||||
|
|
||||||
| new_tick=$(( (current_tick + 1) % 5 )) | ||||||
| echo "$new_tick" > "$TICK_FILE" | ||||||
|
|
||||||
| if [ "$delay_completed" != "1" ]; then | ||||||
| return 0 | ||||||
| fi | ||||||
| fi | ||||||
|
Comment on lines
+73
to
+116
|
||||||
|
|
||||||
| if [ "$CRON_MODE" != "1" ]; then | ||||||
| sec_to_sleep=$(generate_random_delay) | ||||||
| echo_t "fileupload_random: Sleeping for $sec_to_sleep seconds" >&2 | ||||||
| sleep "$sec_to_sleep" | ||||||
| fi | ||||||
|
|
||||||
| if [ -f "$MAINTENANCEWINDOW" ] | ||||||
| then | ||||||
|
|
@@ -226,37 +292,85 @@ | |||||
| fi | ||||||
| } | ||||||
|
|
||||||
| check_maintenance_window_upload() | ||||||
| { | ||||||
| upload_logfile=1 | ||||||
| if [ "$UTC_ENABLE" == "true" ]; then | ||||||
| cur_hr=`LTime H | tr -dc '0-9'` | ||||||
| cur_min=`LTime M | tr -dc '0-9'` | ||||||
| else | ||||||
| cur_hr=`date +"%H"` | ||||||
| cur_min=`date +"%M"` | ||||||
| fi | ||||||
|
|
||||||
| if [ "$cur_hr" -ge "02" ] && [ "$cur_hr" -le "05" ]; then | ||||||
| if [ "$cur_hr" = "05" ] && [ "$cur_min" != "00" ]; then | ||||||
| upload_logfile=1 | ||||||
| else | ||||||
| if [ "$upload_logfile" = "1" ]; then | ||||||
| calcRandTimeandUpload | ||||||
| fi | ||||||
| fi | ||||||
| else | ||||||
| upload_logfile=1 | ||||||
| fi | ||||||
| } | ||||||
|
Comment on lines
+295
to
+317
|
||||||
|
|
||||||
| BUILD_TYPE=`getBuildType` | ||||||
| SERVER=`getTFTPServer $BUILD_TYPE` | ||||||
| loop=1 | ||||||
| upload_logfile=1 | ||||||
| while [ $loop -eq 1 ] | ||||||
| do | ||||||
| sleep 60 | ||||||
|
|
||||||
| if [ "$UTC_ENABLE" == "true" ] | ||||||
| then | ||||||
| cur_hr=`LTime H | tr -dc '0-9'` | ||||||
| cur_min=`LTime M | tr -dc '0-9'` | ||||||
| else | ||||||
| cur_hr=`date +"%H"` | ||||||
| cur_min=`date +"%M"` | ||||||
| fi | ||||||
| install_cron_entry() { | ||||||
| CRON_LINE="* * * * * /rdklogger/fileUploadRandom.sh" | ||||||
|
|
||||||
| if crontab -l 2>/dev/null | grep -q "fileUploadRandom.sh"; then | ||||||
|
||||||
| if crontab -l 2>/dev/null | grep -q "fileUploadRandom.sh"; then | |
| if crontab -l 2>/dev/null | grep -qE '^[^#]*[[:space:]]/rdklogger/fileUpload\.sh([[:space:]]|$)'; then |
Copilot
AI
Feb 20, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In service mode, CRON_MODE is set to 0 inside the while loop (line 346), but this is unnecessary since CRON_MODE is already set to 0 at line 374 before calling service_mode. Setting it repeatedly inside the loop is redundant and could be misleading. Consider removing this line or moving it outside the loop.
| CRON_MODE=0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same tick-based countdown logic issue exists here. The tick counter increments from 0 to 4, but countdown only happens when current_tick is 0, meaning the delay countdown progresses once every 5 minutes instead of every minute. For a random delay of up to 10800 seconds (3 hours), this would make the actual delay up to 5x longer than intended.