From owner-freebsd-questions@freebsd.org Mon Dec 30 19:38:49 2019 Return-Path: Delivered-To: freebsd-questions@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 976001E81D3 for ; Mon, 30 Dec 2019 19:38:49 +0000 (UTC) (envelope-from jguojun@gmail.com) Received: from mail-oi1-x233.google.com (mail-oi1-x233.google.com [IPv6:2607:f8b0:4864:20::233]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 47mnmR6yP9z4PLw for ; Mon, 30 Dec 2019 19:38:47 +0000 (UTC) (envelope-from jguojun@gmail.com) Received: by mail-oi1-x233.google.com with SMTP id z64so5122768oia.4 for ; Mon, 30 Dec 2019 11:38:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=prs72ZHtmMyMpKxYJyR7uUfyhm5yxwrLI18WMCT5RYU=; b=tURQiw4w5rb94m80cQTAIvn1PowW+MqITuQ0PbePD75p/m07Q0jiSPowRGNLnqeDNU 9S7Kc4ZAQz0AF/1MQud90JF8+tp4xXU+5wnAcQA/oWnvPvvZ0EVEbVcfeNnk2v2CG8fM 0WCpX2UwGAG6Ze5Ay3/fFzp/BEj16rgZYk74DCscqUJYQI/m8WZn0Mj8WNz1IRGe8dOh LeeEvxnNs7kfq1m7j2D1KhwxlUkxqnI6hPUAYl4D75jLVluI5DsYKv1H1l6huKdPFzMt Pgq8Jl4aKN3xPpVAeBpTsQLxaVRaGjRwzqXbLxp564VQMxTNOspPNZ9XGwWv04D8KafA zNmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=prs72ZHtmMyMpKxYJyR7uUfyhm5yxwrLI18WMCT5RYU=; b=lNme+lEYAi62lcyiAM30i1HWkUCiL+ds+AfrQ+aoIwKun4tWJGf2kZlm8YVidH9xan KV52F3VZNUgMdaqBp2jO18fODkVDFjCBcVWKAQ9Mdt5M84n9DQwWk+TtzlVXTcP2Q7rK dLV+w3pOXBpjXv1ZH/YIQOVgvLapendfNtG9VDG+7n9bsyYldtCvBuAUtbBN9w9sO161 fFpt2tC5cgvcU9ChQpFaqTi3SWq65XrgJ/ViLAMeOtrrXNwCLEfqrrgPkwSopyWnY7+w dDWw2oXL4R56lOJvsm6NWroI1r06b5Bg1zIzKxjouqj1yUSiL1c5yfnqLwumoTIE89Tb x4qw== X-Gm-Message-State: APjAAAXm8R9PGUxTx0q9iq9fX5Hgucm8EXti52PAIw4itqmbAYqRnJmq QXEdpZvAYDLBp9mbo3MvVtX6wA8= X-Google-Smtp-Source: APXvYqx7dHdEWkjY2SVam6dyEXjouG5gMy+01OfhKVsI2HdKc9hqivk8Xhr4mNsWiuQP6pfVKkwFUA== X-Received: by 2002:aca:de06:: with SMTP id v6mr298378oig.168.1577734726036; Mon, 30 Dec 2019 11:38:46 -0800 (PST) Received: from [192.168.1.82] (162-239-0-170.lightspeed.sntcca.sbcglobal.net. [162.239.0.170]) by smtp.gmail.com with ESMTPSA id d131sm9434644oia.36.2019.12.30.11.38.44 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 Dec 2019 11:38:45 -0800 (PST) Subject: Re: Program order in crontab To: freebsd-questions@freebsd.org References: <20191230143159.GA80921@thismonkey.com> From: "Jin Guojun[VFF]" Message-ID: <9bd9c6a3-0690-4b2b-e8d3-1cadf32236d8@gmail.com> Date: Mon, 30 Dec 2019 11:38:39 -0800 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <20191230143159.GA80921@thismonkey.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Rspamd-Queue-Id: 47mnmR6yP9z4PLw X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org; dkim=pass header.d=gmail.com header.s=20161025 header.b=tURQiw4w; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (mx1.freebsd.org: domain of jguojun@gmail.com designates 2607:f8b0:4864:20::233 as permitted sender) smtp.mailfrom=jguojun@gmail.com X-Spamd-Result: default: False [-3.00 / 15.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_SPF_ALLOW(-0.20)[+ip6:2607:f8b0:4000::/36:c]; FREEMAIL_FROM(0.00)[gmail.com]; TO_DN_NONE(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; DKIM_TRACE(0.00)[gmail.com:+]; DMARC_POLICY_ALLOW(-0.50)[gmail.com,none]; FROM_EQ_ENVFROM(0.00)[]; IP_SCORE(0.00)[ip: (-8.18), ipnet: 2607:f8b0::/32(-2.15), asn: 15169(-1.87), country: US(-0.05)]; MIME_TRACE(0.00)[0:+]; FREEMAIL_ENVFROM(0.00)[gmail.com]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US]; MID_RHS_MATCH_FROM(0.00)[]; DWL_DNSWL_NONE(0.00)[gmail.com.dwl.dnswl.org : 127.0.5.0]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; R_DKIM_ALLOW(-0.20)[gmail.com:s=20161025]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[freebsd-questions@freebsd.org]; IP_SCORE_FREEMAIL(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; RCVD_IN_DNSWL_NONE(0.00)[3.3.2.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.0.0.4.6.8.4.0.b.8.f.7.0.6.2.list.dnswl.org : 127.0.5.0]; RCVD_TLS_ALL(0.00)[] X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 30 Dec 2019 19:38:49 -0000 On 12/30/19 06:31, Scott wrote: >> In a standard 'crontab', if I have three programs as show below, do they >> run in order as listed or all at one time, or something else? Does each >> program finish before the next one starts? >> >> */5 * * * * /usr/home/gerard/Scripts/Program1.sh >> */5 * * * * /usr/home/gerard/Scripts/Program2.sh >> */5 * * * * /usr/home/gerard/Scripts/Program3.sh >> >> Thanks >> >> -- >> Jerry > They would run asynchronously, although I'm not sure of the order they would > be started. > > The cron code may shed some light (I would assume top down but I haven't > checked the code). > > If you wanted to ensure they are run synchronously just put them on one line > separated with a '; '. The order of job execution in cron is typically bottom-up in FreeBSD or top-down in Linux. Additional, all jobs are executed in parallel if they have the same time scheduled, and cron has no guarantee for which one can be executed and completed in any order. This may be an ancient topic that above cronjob is not desired. If P1, P2, P3... order is expected, people should do following: */5 * * * * /usr/home/gerard/Scripts/Batch.sh Including P1, .. Pn commands in /usr/home/gerard/Scripts/Batch.sh file as: BPATH=$(cd `dirname $0`; pwd) # if all commands in the same dir; or set BPATH to where other commands are $BPATH/P1.sh $BPATH/P2.sh $BPATH/P3.sh ... $BPATH/Pn.sh This also makes easier to change the job and/or the order without mucking the crontab. -Jin