PDA

View Full Version : [ubuntu] [SOLVED] How to repeat terminal commands at intervals?



pHreaksYcle
September 20th, 2008, 05:37 PM
I want to repeat a wget line after a specific period of time. I went through man page for wget and found nothing like this. Any ideas? Thanks!

nisaky
September 20th, 2008, 05:41 PM
Press up key, few times if needed

sayakb
September 20th, 2008, 05:42 PM
Make a bash script for it:
At a terminal:

gedit script
Type in:

#!/bin/bash

while [ 1 ]; do
echo <command>
sleep 1
done

Replace echo line with the wget line. Set value of sleep in seconds.
Now exit gedit and at the terminal again:

chmod +x script
./script

pHreaksYcle
September 20th, 2008, 05:42 PM
EDIT: Do I replace the WHOLE echo line or just the part in <>?

EDIT: Thank you!

acidsolution
September 20th, 2008, 05:43 PM
you can have the entry of the script on the crontab

sayakb
September 20th, 2008, 05:44 PM
If your problems have been addressed, please mark the thread as solved (Thread tools->Mark thread as
solved) :)

pHreaksYcle
September 20th, 2008, 05:46 PM
Do I replace the WHOLE echo line or just the part in <>?

Sinkingships7
September 20th, 2008, 05:51 PM
Do I replace the WHOLE echo line or just the part in <>?

Replace the
<command> including the '<>', with the command you want executed.

pHreaksYcle
September 20th, 2008, 05:56 PM
./script: line 4: syntax error near unexpected token `newline'

sayakb
September 20th, 2008, 05:59 PM
You need to replace the whole echo line.
For example, if you want to execute:

wget http://blahblah.comThen it should look like:


#!/bin/bash

while [ 1 ]; do
wget http://blahblah.com &
sleep 1
done

RequinB4
September 20th, 2008, 06:00 PM
Um, the above won't work, simply putting it in a while loop starts dl, waits for it to finish, and then starts downloading the whole thing again. If you want to start wget download and then restart/continue downloading it after a certain time, you need:

(the last line is unnecessary I use it for debugging)


#!/bin/bash
echo "What is the URL?"
read url
wget $url &
sleep 6
killall wget
while [ 1 ] ; do
wget -c $url &
sleep 6
killall wget
done
killall wget


That'll fix problems. (control c stops the script)

Edit: just re-read the OP, this might not be what you want. Anyway, here it is.

pHreaksYcle
September 20th, 2008, 06:03 PM
Replace the
Code:

<command>

including the '<>', with the command you want executed.

Sorry! :P Thanks again!

pHreaksYcle
September 20th, 2008, 06:06 PM
It works and works well! Thank you!

sayakb
September 20th, 2008, 06:08 PM
Glad I could help! :)

lswb
September 20th, 2008, 06:46 PM
If the "wait" and and "waitretry" options for wget aren't what you want, look at the man pages for "at"

Say you wanted the command "wget http://www.website.com/file" to run in 10 minutes,

at a terminal type

at now + 5 min

the "at>" prompt will appear. Type your command here and press enter. You can keep adding commands as you like, when done adding commands type Ctrl-D

If you want this to be a recurring task take a look at cron and anacron.

pHreaksYcle
September 20th, 2008, 06:58 PM
I'm using this format:

#!/bin/bash

while [ 1 ]; do
wget http://blahblah.com &
sleep 1
done

for my script. The problem is, it bogs my system down with like a million wget instance. Ideas? Thanks!

cariboo
September 20th, 2008, 07:05 PM
Your script is going out and downloading whatever its that you are doing once every second. If you remeber from your first post the poster that suggested this script said to change the time to whatever you want in seconds.


#!/bin/bash

while [ 1 ]; do
wget http://blahblah.com &
sleep 1
done

Change the 1 in while [ 1 ]; do to the number of seconds you want to wait before your scripts runs again.

Jim

pHreaksYcle
September 20th, 2008, 07:08 PM
EDIT: I am using the parameter --spider so it isn't actually downloading, just bumping the page for info. Quicker that way.
EDIT: I thought you changed the sleep value not the while value

I know, I did. In this case, I changed it to .1 :)

Any knowledge you have on how to kill the process when it's done, then restarting it, instead of just multiplying like rabbits?

Thanks!

sayakb
September 20th, 2008, 07:10 PM
Add a killall wget above the done:
#!/bin/bash

while [ 1 ]; do
wget http://blahblah.com (http://blahblah.com/) &
sleep 1
killall wget
done

PS: Please do not open a new thread for similar topics. You could remove the SOLVED tag and continue asking in the previous one.

pHreaksYcle
September 20th, 2008, 07:13 PM
EDIT: LinuxIsInnovation, do I have to change the while value in [ ] as well as the sleep value or no?

Sorry about that :P

Thanks again, once more your solution has pleased me!

sayakb
September 20th, 2008, 07:27 PM
The value in [ ] is just a boolean flag signifying that the loop will go on indefinitely as the condition within [] is always true (ie. 1). It does not signify sleep time, or anything :)
So, no. You don't need to change that.

jpeddicord
September 20th, 2008, 07:44 PM
Merged threads.