I am using centos

Please help what is SSH commands to do this:

run a command 20 times, break 2 seconds, and repeated again

so like this

// run 20 times
wget 
wget 
wget 
wget 
wget 
wget 
wget 
wget 
wget 
wget 
wget 
wget 
wget 
wget 
wget 
wget 
wget 
wget 
wget 
wget 
//break 2 seconds

// run 20 times
wget 
wget 
wget 
wget 
wget 
wget 
wget 
wget 
wget 
wget 
wget 
wget 
wget 
wget 
wget 
wget 
wget 
wget 
wget 
wget 
//break 2 seconds

and loop run it automatically, until i clik ctrl+c to stop it manually

will give rep +1 for all answered

Dani AI

Generated

A few replies already showed the basic idea (thanks , and ). Below are practical refinements you won’t find in the existing posts: a polite, robust fetch that doesn’t fill disk space, a graceful Ctrl+C handler, and simple ways to run it over SSH inside a detachable session so it survives your disconnect.

#!/bin/bash
trap 'echo "Stopped by user"; exit' INT

while :; do
  for ((i=0; i<20; i++)); do
    curl -sS -o /dev/null --max-time 10 --retry 2 --retry-delay 1 \
      -A "repeat-test/1.0 (contact: you@example.com)" http://test.com
  done
  sleep 2
done

Notes: curl -sS -o /dev/null discards the body but surfaces errors; --max-time bounds each request; --retry makes intermittent failures less noisy; the trap makes a clean stop on Ctrl+C. If you prefer wget for its --spider behavior or built-in --wait, use those options instead.

To run remotely via SSH and keep the job running after you log out, copy the script to the host and start it inside screen/tmux (or use ssh user@host 'bash -s' < repeat.sh to run without copying):

scp repeat.sh user@server:~/repeat.sh
ssh user@server 'chmod +x ~/repeat.sh && screen -dmS repeater ~/repeat.sh'
# to reattach: ssh user@server 'screen -r repeater'

Responsible-use warning: as already cautioned, hitting the same URL repeatedly can trigger rate limits or get your IP blocked. Test against a local server first, use HEAD requests (curl -I) or wget --spider to avoid downloading large content, add longer sleeps or lower concurrency, and contact the site owner if this is anything but private testing. ’s SSH question is fully covered by the SSH examples above; ’s point that wget and SSH are separate remains true — SSH is just the transport for running the commands remotely.

Recommended Answers

All 5 Replies

If there is a python interpreter, you can try this perhaps

python -c "$(echo -e "from subprocess import call\nfrom time import sleep\nwhile True:\n for i in range(20): call('wget ', shell=True)\n sleep(2)")"

Hello,

Here is a shell script for what you are requesting but I home you are not really going to do a wget 20 times. If you do you will probably trigger DDOS attack filters that will block your IP address. The "while true " loop will continue to execute (since it is always true ) until you do a <CTRL> C

#!/bin/bash
while true
do
        i=0
        while [ $i -lt 20 ]
        do
                wget 
                i=$[$i+1]
        done
        sleep 2
done
commented: This shell script looks good. The sleep command will pause for 2 seconds. +0

What do you mean by "SSH command"? Are you looking for a way to ssh in to a computer and then run a script that does as you described?

commented: good question +13

As per andy1973's question, there is no ssh in the provided code. The wget command has nothing to do with ssh.

commented: I think by "SSH" basketmen just means "shell" +5

Seems like has what OP is looking for. Here's an alternative that I like, using the 'seq' command as the counter:

#!/bin/bash
while true; do
    for i in $(seq 1 20); do
        wget 
    done
    sleep 2
done

I hope this helps!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.