Scheduling jobs is an essential part of administering Linux servers. Plānošanas darba vietas, ir būtiska daļa lieto Linux serveriem. We took a look at how to schedule jobs on Linux machine using the Mums bija skatīties, kā plānot darba vietas uz Linux mašīnas, izmantojot cron cron command earlier. komanda agrāk. Here's an alternative to cron – at . Lūk alternatīvu cron - ne. The primary difference between the two is that when you schedule a task using cron it execute repeatedly without the need for rescheduling. Galvenā atšķirība starp abiem ir tā, ka, ja plānojat uzdevumu, izmantojot cron to izpildīt atkārtoti nav nepieciešams grafika. With at , on the other hand, the scheduling of a task is only for a single execution. Kam ir, no otras puses, par uzdevuma plānošana ir tikai viena izpildei. Both of these commands have their use, and I would suggest that you get a good understanding of them both. Abas šīs komandas to izmantošanu, un es ieteiktu jums labu izpratni par tiem abiem.
Let's look at how to schedule a task to execute only once using the at command. Apskatīsim, kā plānot uzdevumu izpildīt tikai tad, kad izmanto ar komandu. First make sure that the at daemon is running using a command like this: Vispirms pārliecinieties, ka pie dēmona darbojas, izmantojot komandu šādi:
# ps -ef | grep atd # Ps-ef | grep ATD
root 8231 1 0 18:10 ? root 8.231 1 0 18:10? 00:00:00 /usr/sbin/atd 00:00:00 / usr / sbin / ATD
If you don't see atd running start it with this command: Ja jūs neredzat ATD ieskriešanās to ar šo komandu:
# /etc/init.d/atd start # / Etc / init.d / ATD sākums
Once the daemon has been started successfully you can schedule an at task using the two options -f , for the file to be executed, and -v , for the time at which it should be executed. Kad dēmons ir uzsākta veiksmīgi varat plānot pēc uzdevuma, izmantojot divas iespējas-f, lai fails tiktu izpildīts, un-v, par laiku, kad tas ir izpildīts. So if you want to execute the shell script shellscript.sh at 6:30 PM you would run the following command: Tātad, ja jūs vēlaties izpildīt shell script shellscript.sh at 6:30 Jūs palaist šādu komandu:
# at -f shellscript.sh -v 18:30 # At-f shellscript.sh-v 18:30
Remember that with the at command the script shellscript.sh will execute at 6:30 PM and then the scheduling will disappear. Atcerieties, ka ar pie komandu skripts shellscript.sh veiks pie 6:30 un tad plānošanas pazudīs. So if this is not what you desire, you are better off using cron . Tātad, ja tas nav tas, ko jūs vēlaties, jūs labāk izmantojot cron.
The at command is pretty clever in that it can take some orders in English if you like. At komanda ir diezgan gudrs, jo tas var aizņemt kādu angļu valodā rīkojumus, ja vēlaties. For example, you can schedule jobs using the following syntax as well: Piemēram, varat plānot darbavietām, izmantojot šādu sintaksi, kā arī:
# at -f shellscript.sh 10pm tomorrow # At-f shellscript.sh 10 rīt
# at -f shellscript.sh 2:50 tuesday # At-f shellscript.sh 2:50 otrdiena
# at -f shellscript.sh 6:00 july 11 # At-f shellscript.sh 6:00 11 jūlijs
# at -f shellscript.sh 2:00 next week # At-f shellscript.sh 2:00 nākamnedēļ























{ 1 trackback } (1 Trackback)
{ 2 comments… read them below or (2 comments ... lasīt tos zem vai add one pievienot vienu } )
If you don't see atd running start it with this command: Ja jūs neredzat ATD ieskriešanās to ar šo komandu:
# /etc/init.d/atd start # / Etc / init.d / ATD sākums
More correctly, if it isn't running, it probably is not configured to startup when the system is restarted. Precīzāk, ja tas nedarbojas, tas, iespējams, nav konfigurēta, lai starta, kad sistēma tiek atsākta. Which may also keep the above command from working as expected. Kas arī var saglabāt iepriekš minēto komandu no darba, kā paredzēts. To correct this, use: Lai labotu šo, izmantojiet:
# 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). un pārbaudiet vēlreiz, lai pārliecinātos, ka tas darbojas, ja tā ir, turpiniet ar instrukcijām (kas ir ļoti labi BTW).
I have another followup for you on use of the at command. Man ir cits follow Jums uz izmantošanu, pie komandas.
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. Esmu uzskriet situācijās, kur es esmu vajadzīga komanda darboties katru stundu, bet man vajadzēja komandu skaitīt tikai tad, ja iepriekšējā palaist ir pabeigta. It might not be hung but it might be very very busy. Nebūtu hung, bet tas varētu būt ļoti ļoti aizņemts. I don't mind skipping an hour's execution if the process is still busy. Man nav nekas izlaižot stundas izpildes, ja process joprojām ir aizņemts.
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. Ja šī situācija, es nedomāju izmantot cron, es izmantošana "ir", un pēdējā lieta man manā skripts ir par komandu pati atkārtoti iesniegt darbu izpildi.
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. Tagad, pat tad, ja darbs ir trīs stundām, aug pēc stundas, pēc komandas uzsāks darbu, kā paredzēts bez cron darba mutuļošana viens otram.
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. Jā, tur ir iespējas ieviest loģika stājas skriptu cron pilnvaroti ar to nodarboties, bet var arī būt grūti uzturēt, nevis acīmredzama (dažiem), kā šo pieeju.
Leave a Comment Leave Comment