Repeat a command every x interval of time in terminal?

1

Question: Sometimes I want to repeat a command (or shell-script) frequently (every few seconds). Is there a better way to execute a unix command every n seconds (instead of keep typing the same command manually)?

Answer: Using watch command you can execute a command and view it’s output every few seconds. This is very helpful while monitoring memory usage, disk usage etc.,

You can execute any Unix command using watch command. Watch command will be executed until you terminate it either by CTRL+C or kill the process.

Example 1: Watching for a file creation using watch ls

When you are expecting a file to be created by a background process, or when you are expecting a log file to keep growing in size, you might end-up doing ls command multiple times. Instead, you can use watch command, which will execute the ls command every 2 seconds as shown below.

$ watch ls Every 2.0s: ls Thu Apr 15 16:11:58 2010...
0 0
2

You control when and how often a job repeats by setting the repeat_interval attribute of the job itself or of the named schedule that the job references. You can set repeat_interval with DBMS_SCHEDULER package procedures or with Enterprise Manager.

The result of evaluating the repeat_interval is a set of timestamps. The Scheduler runs the job at each timestamp. Note that the start date from the job or schedule also helps determine the resulting set of timestamps. (See Oracle Database PL/SQL Packages and Types Reference for more information about repeat_interval evaluation.) If no value for repeat_interval is specified, the job runs only once at the specified start date.

Immediately after a job is started, the repeat_interval is evaluated to determine the next scheduled execution time of the job. It is possible that the next scheduled execution time arrives while the job is still running. A new instance of the job, however, will not be started until the current one...

0 0
3

There's a builtin unix command repeat whose first argument is the number of times to repeat a command, where the command (with any arguments) is specified by the remaining arguments to repeat. For example,

% repeat 100 echo "I will not automate this punishment."

will echo the given string 100 times and then stop.

I'd like a similar command, let's call it forever, that works similarly except the first argument is the number of seconds to pause between repeats, and it repeats forever. For example,

% forever 5 echo "This will get echoed every 5 seconds forever and ever."

I thought I'd ask if such a thing exists before I write it. I know it's like a 2-line perl or python script but maybe there's a more standard way to do this. If not, feel free to post a solution in your favorite scripting language, rosetta stone style.

PS: Maybe a better way to do this would be to generalize repeat to take both the number of times to repeat (with -1 meaning infinity) and...

0 0
4

A server administrator needs to maintain the system and keep it updated and safe. A number of intrusion attempts may happen every day. There are some other activities that maintain their log. These logs are updated regularly. In order to check these updates, the commands are executed repeatedly. For example, for simply reading a file, commands like head, tail, cat etc are used. These commands need to be executed repeatedly. The watch command can be used to repeat a command at regular intervals.

Watch Command

Watch is a simple command, with a few options. The basic syntax of watch command is:

watch [-dhvt] [-n ] [--differences[=cumulative]] [--help] [--interval=] [--no-title] [--version]

Watch command runs the command specified to it after every 2 seconds by default. This time is counted between the completion of command and beginning of next execution. As a simple example, watch command can be used to watch the log updates, The updates are appended...

0 0
5

congxz6688,
0~10 minutes is ok to farm a bit... although I think it should be a percentage of the interval time... like 20% for example.

Because now I cant user for this situation:
- attack with 1 troop (fake), repeat 5 times, interval 1 second.

This would generate 5 attacks, all close together in time, simulating catapults/conquer attacks... very usefull and timesaving!

with a percentage, it would work fine on both cases:
20% of 1 second --> 1 ~ 1.2 seconds
20% of 5 hours --> 5 ~ 6 hours

A great addition is to make this percentage a optional parameter of the script (a user command, like the 20 minutes refresh rate of the page)... some may want 5%, others 10%...etc...

Please consider this implementation in next...

0 0
6

Provided by:

tmux_1.6-1ubuntu1_i386

NAME

tmux — terminal multiplexer

SYNOPSIS

tmux [-28lquvV] [-c shell-command] [-f file] [-L socket-name] [-S socket-path] [command [flags]]

DESCRIPTION

tmux is a terminal multiplexer: it enables a number of terminals to be created, accessed, and controlled from a single screen. tmux may be detached from a screen and continue running in the background, then later reattached. When tmux is started it creates a new session with a single window and displays it on screen. A status line at the bottom of the screen shows information on the current session and is used to enter interactive commands. A session is a single collection of pseudo terminals under the management of tmux. Each session has one or more windows linked to it. A window occupies the entire screen and may be split into rectangular panes, each of which is a separate pseudo terminal (the pty(4) manual page...
0 0
7

crontab - A command to manage crontab files for each users and schedule commands ans other scripts.
Format:
crontab [-u user] file
crontab [-u user] [-l | -r | -e]

DESCRIPTION
Crontab is the program used to creat, remove or show the tables used to drive the cron(8) daemon in ISC Cron.

It is meant to be used for scheduling re-occurring jobs. If you want to schedule a job for one time exection, you should use at command in Linux.

Each user can have their own crontab, and though these are files in /var, they are not intended to be edited directly.

Related files: /etc/cron.allow, /etc/cron.deny

Note:-
Cron.allow: If the cron.allow file exists, then you must be listed therein in order to be allowed to use this command.

Cron.deny: If the cron.allow file does not exist but the cron.deny file does exist, then you must not be listed in the cron.deny file in order to use this command.

If neither of these...

0 0
8
...
0 0
9

A system administrator often needs to run a command repeatedly in a certain periods of time. Often such tasks can be easily completed with simple cron commands. In most of the cases this should work, but the shortest period which you can run cron command is every 1 minute. Believe it or not, in many cases this is too slow.

Run Linux Command Every Second

In this tutorial, you will learn a simple scripting techniques to monitor or keep a eye on a particular command in continuously running state similar to top command (continuously monitor the process and memory utilization) for every 3 seconds by default.

We will not stop to discuss the reasons, why you would need to run commands this often. I believe everyone has different reasons for that in their daily jobs or even at home PCs and laptops.

1. Use watch Command

Watch is a Linux command that allows you to execute a command or program periodically and also shows you output on the screen. This...

0 0
10
...
0 0
11
...
0 0
12

We respect its storied history, and value the contributions of its many readers, but we can no longer support it at the level it deserves. There’s a wealth of great information here that many will find useful, so we've elected to maintain it in a read-only form. Thanks for your many years of attention and everything you've done to make the site such a valuable resource.


You rated: 2 / 5 (3 votes cast)

[72 views]


I sometimes find the Java setup on my various Apple devices to be a mystery.

Recently, I was trying to get a Java applet to run in the same way on 2 iMacs and my MacBook Air. The applet is a simple vpn client from Juniper that lets me access a Citrix Desktop from any Mac that I can install the Citrix receiver client on so I can work on 'Company stuff' from a large screen iMac when I'm sat at home or from my MacBook when I'm on the road (it works fine over 3/4G).

The first thing is that...

0 0
13

NAME

lftp - Sophisticated file transfer program

SYNTAX

lftp

[

-d

] [

-e cmd

] [

-p port

] [

-u user

[

,pass

]] [

site

]


lftp -f script_file
lftp -c commands
lftp --version
lftp --help

DESCRIPTION

lftp

is a program that allows sophisticated ftp and http connections to other hosts. If

host

is specified then lftp will connect to that host otherwise a connection has to be established with the open command.

lftp can handle six file access methods - ftp, ftps, http, https, hftp, fish and file (https and ftps are only available when lftp is compiled with openssl library). You can specify the method to use in `open URL' command, e.g. `open http://www.us.kernel.org/pub/linux'. hftp is ftp-over-http-proxy protocol. It can be used automatically instead of ftp if ftp:proxy is set to `http://proxy[:port]'. Fish is a protocol working over an ssh connection.

Every operation...

0 0
14

I don't think a command or shell builtin for this exists, as it's a trivial subset of what the Bourne shell for loop is designed for and implementing a command like this yourself is therefore quite simple.

For starters you can use a dummy for loop:

for i in `seq 10`; do command; done

Or equivalently as per JimB's suggestion, using the Bash builtin for generating sequences:

for i in {1..10}; do command; done

This iterates ten times executing command each time - it can be a pipe or a series of commands separated by ; or &&. You can use the $i variable to know which iteration you're in.

If you consider this one-liner a script and so for some unspecified (but perhaps valid) reason undesireable you can implement it as a command, perhaps something like this on your .bashrc (untested):

#function run run() { number=$1 shift for i in `seq $number`; do $@ done }

Usage:

run 10 command

Example:

run 5 echo 'Hello...
0 0
15

Terminal app can be daunting at first, but it’s really the best way to hack into your Mac’s configurations and preferences to customize things to work for you rather than against you. With the right Terminal commands, you can tweak the Finder, mess with the user interface, build a more private and secure Mac, and even enable features that aren’t officially supported on older Macs.

Here are a few of the better ones.

Hack The Finder

The Finder can be hacked a bit using the Terminal, of course, so we figured we could show you a few tricks, too. Here’s how to hack up the Finder a bit to make it work better for you.

Show Hidden Files

The Finder hides many configuration files in the finder, some of which you might want to get into to change things. Most of the time, these files should stay hidden or left alone, but we’re not interested in playing it safe all the time. If you want to see all the files on your Mac for your own reasons, launch Terminal and type...

0 0