Como programar tarefas em Linux usando o `' no comando

por Sukrit Dhandhania em Maio 4, 2009

Linux

Os trabalhos do Scheduling são uma parte essencial de administrar usuários de Linux. Nós fizemos exame de um olhar em como programar trabalhos em usar-se da máquina de Linux cron comando mais cedo. Está aqui uma alternativa a cron - em. A diferença preliminar entre os dois é que quando você programa uma tarefa usando o cron ele execute repetidamente sem a necessidade para rescheduling. Com em, na uma mão, programar de uma tarefa é somente para uma única execução. Ambos estes comandos têm seu uso, e eu sugeriria que você começa uma compreensão boa deles ambos.

Vamos olhar como programar uma tarefa executar somente uma vez usar-se em comando. Certifique-se primeiramente de que no daemon está funcionando usando um comando como isto:

# picosegundo - ef | grep atd
raiz 8231 1 0 18:10? 00:00: 00 /usr/sbin/atd

Se você não vir atd começo running ele com este comando:

# começo de /etc/init.d/atd

Uma vez que o daemon foi começado com sucesso você pode programar em tarefa usando as duas opções - f, para a lima a ser executada, e - v, por o tempo em que deve ser executado. Assim se você quiser executar o certificado de escudo shellscript.sh em 6:30 PM você funcionaria o seguinte comando:

# - f shellscript.sh - em v 18:30

Recorde isso com em comande o certificado shellscript.sh executará em 6:30 PM e então programar desaparecerá. Assim se este não for o que você deseja, você é melhor fora de usar-se cron.

em o comando é consideravelmente inteligente que pode fazer exame de algumas ordens em inglês se você gostar. Por exemplo, você pode programar trabalhos usando a seguinte sintaxe também:

# - em f shellscript.sh 10pm amanhã

# - em f shellscript.sh 2:50 terça-feira

# - em f shellscript.sh 6:00 julho 11

# - em f shellscript.sh 2:00 semana seguinte

Bornes relacionados:
  • Aumente seus Linux/produtividade do Unix: Como usar o crontab
  • Dashboard Widget: Programação de MLB
  • Como parar seu Mac de acordar quando dever dormir
  • Como conservar a saída de um comando de Linux a uma lima
  • How to post to Twitter from the Linux command line
  • Get Simple Help tutorials just like this one in your email inbox every day - for free! Just enter your email address below:

    You can always opt out of this email subscription at any time.

    { 2 comments… read them below or add one }

    1 MikeT 05.04.09 at 5:26 am

    If you don’t see atd running start it with this command:

    # /etc/init.d/atd start

    More correctly, if it isn’t running, it probably is not configured to startup when the system is restarted. Which may also keep the above command from working as expected. To correct this, use:

    # chkconfig atd --level 234 on
    # service atd start

    and check again to make sure it is running, if it is, continue with the instructions (which are very good BTW).

    2 MikeT 05.04.09 at 5:32 am

    I have another followup for you on use of the at command.

    I’ve run into situations where I’ve needed a command run every hour BUT I needed the command to run ONLY if the previous run has completed. It might not be hung but it might be very very busy. I don’t mind skipping an hour’s execution if the process is still busy.

    When this situation arises, I don’t use cron, I use ‘at’ and the last thing I put in my script is the at command itself to resubmit the job for execution.

    Now, even if the job takes three hours, at the top of the following hour, the at command will launch the job as expected without cron jobs bumping into each other.

    Yes, there’s ways to put the logic into a script for cron to deal with it but that can also be difficult to maintain and not as obvious (to some) as this approach.

    Leave a Comment

    You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>