Terminal: come usare 'at'?

3

Qualcuno potrebbe fornire alcuni esempi di utilizzo per il comando at ? Sto trovando il man super confusion.

$ man at

Ad esempio, se volessimo eseguire un comando tra 10 minuti, è possibile farlo utilizzando at ? (e senza usare sleep )

    
posta user310974 19.11.2018 - 12:09
fonte

2 risposte

2

Le specifiche del tempo per "10 minuti da ora" sono now +10 minutes . Ad esempio,

echo 'open ~' | at now +10 minutes

Tuttavia, il sistema at è disabilitato di default in macOS, come menzionato nella pagina man at :

IMPLEMENTATION NOTES
     Note that at is implemented through the launchd(8) daemon periodically
     invoking atrun(8), which is disabled by default.  See atrun(8) for infor-
     mation about enabling atrun.

La pagina man di atrun dice che è necessario eseguire

sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.atrun.plist
    
risposta data 19.11.2018 - 12:48
fonte
0

I Use the at command when I need to do some heavy processing on data, which I want to have executed during the night, when I am not behind my computer. Of course I could start the process just after I leave, but this is something I tend to forget.

The result of the command is not different from regularly execution of the script or command.
@Bernhard

Che cosa fa
estratto da at man page

NAME
       at, batch, atq, atrm - queue, examine or delete jobs for later execution

DESCRIPTION
       at  and  batch  read  commands  from  standard  input or a specified file
       which are to be executed at a later time, using /bin/sh.
    

Utilizzo
L'uso degli strumenti:

Usage: at [-V] [-q x] [-f file] [-mldbv] timespec ...
       at [-V] [-q x] [-f file] [-mldbv] -t time
       at -c job ...
       atq [-V] [-q x]
       atrm [-V] job ...
       batch    

at include 4 comandi ( at , atq , atrm e batch ). Usa at e batch per pianificare i lavori, atq per vedere cosa è programmato e atrm per rimuovere un lavoro prima che funzioni.

$ at -f <cmd> timspec

timespec
Il tempo di eseguire il lavoro at può essere specificato in diversi modi.

modulo estratto nella pagina man

At allows fairly complex time specifications, extending the POSIX.2 standard. It accepts times of the form HH:MM to run a job at a specific time of day. (If that time is already past, the next day is assumed.) You may also specify mid‐ night, noon, or teatime (4pm) and you can have a time-of-day suffixed with AM or PM for running in the morning or the evening. You can also say what day the job will be run, by giving a date in the form month-name day with an optional year, or giving a date of the form MMDD[CC]YY, MM/DD/[CC]YY, DD.MM.[CC]YY or [CC]YY-MM-DD. The specification of a date must follow the specification of the time of day. You can also give times like now + count time-units, where the time- units can be minutes, hours, days, or weeks and you can tell at to run the job today by suffixing the time with today and to run the job tomorrow by suffixing the time with tomorrow.

Esempi
Supponi di avere questo script di shell.

$ cat mycrontest.sh

#!/bin/bash
 echo "It is now $(date +%T) on $(date +%A)"

Esecuzione campione:

$ ./mycrontest.sh
It is now 18:37:42 on Friday

Esempio di invio di lavoro:

$ at -f mycrontest.sh  10pm tomorrow
job 14 at Sun Jul  8 22:00:00 2007

$ at -f mycrontest.sh 2:00 tuesday
job 15 at Tue Jul 10 02:00:00 2007

$ at -f mycrontest.sh 2:00 july 11
job 16 at Wed Jul 11 02:00:00 2007

$ at -f mycrontest.sh 2:00 next week
job 17 at Sat Jul 14 02:00:00 2007

Crediti a @slm

    
risposta data 19.11.2018 - 12:36
fonte

Leggi altre domande sui tag