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 E9AF31381F3 for ; Sun, 5 May 2013 18:08:19 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id DD4F0E0919; Sun, 5 May 2013 18:08:13 +0000 (UTC) Received: from homiemail-a44.g.dreamhost.com (caibbdcaaaaf.dreamhost.com [208.113.200.5]) by pigeon.gentoo.org (Postfix) with ESMTP id 693DCE0903 for ; Sun, 5 May 2013 18:08:12 +0000 (UTC) Received: from homiemail-a44.g.dreamhost.com (localhost [127.0.0.1]) by homiemail-a44.g.dreamhost.com (Postfix) with ESMTP id DB5FA118060 for ; Sun, 5 May 2013 11:08:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=libertytrek.org; h= message-id:date:from:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; s= libertytrek.org; bh=cXAlw10A+po5ge1e14abHsJAf/M=; b=E+9ADkw7WNQx vdgYu7bvuJA3lgHjmfm3An0xluQJmE0nGcb6DVk1Rynt+OzDrGUsyDGTmN+RQLu1 POMeNxi+EEp24lgH93nZZmmWw2tWWfeQnCVAEPME02zu/9CjiheZ09FHOU1qXOkS 9qPMo2czkeq4s1ktNKY+s95nlJgJeNM= Received: from [127.0.0.1] (unknown [159.63.145.2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: tanstaafl@libertytrek.org) by homiemail-a44.g.dreamhost.com (Postfix) with ESMTPSA id B3DC4118057 for ; Sun, 5 May 2013 11:08:11 -0700 (PDT) Message-ID: <51869FF6.3000308@libertytrek.org> Date: Sun, 05 May 2013 14:07:50 -0400 From: Tanstaafl User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130328 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; format=flowed Content-Transfer-Encoding: 7bit X-Archives-Salt: 23373a18-e91f-4ee0-bcb2-570fbcaa8ce6 X-Archives-Hash: e2ddd672ff89dbeb3dc2466d408dea02 Ok, some of those variables were wrong (copy pasted from my first brain-dead attempt)... I now have a rudimentary bash script with contents: #!/bin/bash BACKUP_DIR="/home/user/mypg_backups" PGUSER="superuser" PGtt=`date '+%H:%M'` PGhr=`date '+%H'` PGdd=`date '+%a'` PGmm=`date '+%b'` PGyy=`date '+%Y'` /usr/bin/pg_dumpall -U $PGUSER -o | gzip > $BACKUP_DIR/$PGyy/$PGmm/$PGdd/pg_all-$PGtt.gz Running this results in: # ./mypg_pgdumpall.sh ./mypg_pgdumpall.sh: line 10: /home/user/mypg_backups/2013/May/Sun/pg_all-13:54.gz: No such file or directory So, it is expanding the variables properly, but apparently won't automatically create the directories? Is there some kind of flag I can add to the command to do that? Running the bare command without the variables works as expected, so it is just a matter of getting the directories auto created if they don't already exist. Is there a reasonably easy way of doing this? On 2013-05-05 12:56 PM, 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... >