curl - Linux: run a command every 50 minutes randomly -


i need run curl request locahost @ least once in every 30 mins. command curl http://localhost:8080.

the catch here is, want select time randomly between 5min - 30 min , execute curl command. pseudo-code might this

while(true) n = random number between 5-30 run curl http://localhost:8080 after 'n' minutes 

a detailed answer nice since don't have knowledge linux.

if run above script, must run background process , make sure not killed (os, other users,...)

another way use cronjob trigger automatically script more complex.

cronjob setting:

* * * * * bash test_curl.sh >> log_file.log 

shell script test_curl.sh:

#!/bin/bash  # declare variable execute_time_file_path="./execute_time"  # load expected execute time expected_execute_time=$(cat $execute_time_file_path)  echo "start @ $(date)"  # calculate current time , compare expected execute time current_minute_of_time=$(date +'%m')  if [[ "$expected_execute_time" == "$current_minute_of_time"  ]];   curl http://localhost:8080   # random new time 5 -> 30   next_random=$((random%25+5))   # current time   current_time=$(date +'%h:%m')   # calculate next expected execute time = current time + next random   next_expected_execute_time=$(date -d "$current_time $next_random minutes" +'%m')   # save file   echo -n $next_expected_execute_time > $execute_time_file_path   echo "next executed time $(date -d "$current_time $next_random minutes" +'%h:%m')" else   echo "this $(date +'%h:%m') not expected time run test" fi  echo "end @ $(date)" 

i commented out in line can read easily. **

update: importance: file execute_time must has initial value. example, current minute of first time execute.

**


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -