From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 314C81381F3 for ; Sun, 5 May 2013 17:49:45 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 48D5EE08B8; Sun, 5 May 2013 17:49:35 +0000 (UTC) Received: from mail-wg0-f54.google.com (mail-wg0-f54.google.com [74.125.82.54]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id F2569E0871 for ; Sun, 5 May 2013 17:49:33 +0000 (UTC) Received: by mail-wg0-f54.google.com with SMTP id x12so2813457wgg.33 for ; Sun, 05 May 2013 10:49:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:message-id:date:from:user-agent:mime-version:to:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=HtZY/ITL4fFSefxb0E1XjGbC6Vz+Z+PQufHJU/vBOfM=; b=ioh4YXqfkKe9zAy9rFHPjC1NtvWJjVW6zFGdaNl1Q+FvX2+DaJ7tvkPfs6/6+S9o/y 6Wd+3Pf5YI3e2MJiC9ceYdwz1OdO54BUnF6707laJ3lNry1zJYFUVLSgp+YHrK2ZhMjR V3qGorGOcJpBMqmXXgwAoJjXDzr+S2rmDDpqTgaETuu3ZAt0wYLJ4wkOb1B5vM3nszMY uWsl6PFF7b/ethes3oRLKPOjqkdtQYPHliid0NAs6PQMoECeD2+VD0j7H0V78fGdodDx xm9W2pGnIiAck1aoPrWD3zAC2AWbMagvN5y3I9k7Kb5cW9RkFa5fLyNGYYj/vG/DwTO0 uyfA== X-Received: by 10.180.182.110 with SMTP id ed14mr5430122wic.6.1367776172658; Sun, 05 May 2013 10:49:32 -0700 (PDT) Received: from [172.20.0.41] (196-215-205-181.dynamic.isadsl.co.za. [196.215.205.181]) by mx.google.com with ESMTPSA id d8sm10207852wiv.10.2013.05.05.10.49.30 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 05 May 2013 10:49:31 -0700 (PDT) Message-ID: <51869BA5.9030206@gmail.com> Date: Sun, 05 May 2013 19:49:25 +0200 From: Alan McKinnon User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130413 Thunderbird/17.0.5 Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-user@lists.gentoo.org Reply-to: gentoo-user@lists.gentoo.org MIME-Version: 1.0 To: gentoo-user@lists.gentoo.org Subject: Re: [gentoo-user] Using date/time variables in cronjobs? References: <51868F41.6050407@libertytrek.org> In-Reply-To: <51868F41.6050407@libertytrek.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Archives-Salt: f0ab16a5-b33d-461f-a74c-a6d3d896bbe7 X-Archives-Hash: b563c13a648f9f92f3983b6c92605a54 On 05/05/2013 18:56, Tanstaafl wrote: > Ok, another little thing... > > Is there a simple way to use date/time variables in cronjobs? Or do I > need to use a bash script for this? I prefer simple, and just using the > variables directly in the cron command would be easier if it works, so > figured I'd ask first... > > I'm trying to schedule a dump of my databases like so: > > pg_dumpall --username=username -o -f > /home/user/mypg_backups/hourly/\%y/\%m/\%d/\%t.sql.gz > > But trying to run this command fails with: > > pg_dumpall: could not open the output file > "/home/user/mypg_backups/hourly/%y/%m/%d/%t.sql.gz": No such file or > directory > > Tried escaping the variables and not, same error... What creates those variables %y etc? They don't "just exist", something sets them. Check that that thing sets them correctly. But I'll bet the directory /home/user/mypg_backups/hourly/\%y/\%m/\%d/ doesn't exist. pg_dumpall won;t create it, that's your job. So now you need a test that the directory exists, mkdir -p it if not, and only then write the output file. Which is far easier done in a wrapper script than in a one-liner, if only for the fact that you have indented text. Sometimes, making things simpler makes your life harder. This looks like such a case. -- Alan McKinnon alan.mckinnon@gmail.com