Monday, April 29, 2024
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 1590  / 2 Years ago, sat, october 22, 2022, 1:45:25

I'm new to shell scripting.


I'm trying to somehow cron a job that will wget one url once to trigger a task, and another url every 2 minutes after to keep the task alive.


So far I've managed to get the first url to work without issue, the problem comes with the second url wget repeating every 2 minutes for 1 hour.


I've tried including cron within the .sh script as I saw suggested somewhere else, like


*/2 * * * * wget $url

but terminal just throws it out with an error "no such file or directory".


Whats the best method of doing this?


More From » command-line

 Answers
1

As @Fiximan and @steeldriver suggested, another option is to run wget in a loop for 1 hour:


COUNT=0
while [ $COUNT -lt 30 ]; do
wget $url
sleep 120
COUNT=$((COUNT + 1))
done

Note that script containing this code must be run using #!/bin/bash, not #!/bin/sh.


[#2287] Monday, October 24, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dersol

Total Points: 78
Total Questions: 100
Total Answers: 124

Location: Christmas Island
Member since Mon, Oct 19, 2020
4 Years ago
dersol questions
Mon, May 16, 22, 00:10, 2 Years ago
Fri, Feb 24, 23, 20:00, 1 Year ago
;