F.M
F.M

Reputation: 511

Ignore duplicate jobs running with at command

I'm on Freebsd9.2.(I have to use this operating system) I want to run multiple scripts with at command but I want to ignore running a script in a same time.

For example: I have 3 script files: 1.sh, 2.sh, 3.sh

I have a job to execute 1.sh at today 16:20, when I run the at command with the same time and script, the number of the jobs in /var/at/jobs changed to 2 jobs. I want to ignore this, but the script 2.sh can run with thw same time. Do you have any idea what should I do?

Upvotes: 0

Views: 182

Answers (1)

nbari
nbari

Reputation: 26905

I don't know if I understood correctly the problem, but maybe the command lockf could help.

For example try this in one terminal:

$ lockf -t 0 /tmp/a.lock sleep 5

In another terminal run:

$ lockf -t 0 /tmp/a.lock echo "sleep finished"

In this example until the command sleep 5 doesn't exit, if you try to run another command you will get something like:

lockf: /tmp/a.lock: already locked

A cron example:

15 4 * * * lockf -t 0 /tmp/poudriere.lock /usr/local/etc/poudriere.d/cron 12amd64 default

This prevents running the script/app if the lock exists, so probably you can get an idea of how you could use it with at

Upvotes: 1

Related Questions