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 6215B1381F3 for ; Sun, 5 May 2013 20:17:57 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 8051CE0950; Sun, 5 May 2013 20:17:50 +0000 (UTC) Received: from mail-wi0-f172.google.com (mail-wi0-f172.google.com [209.85.212.172]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 41786E0919 for ; Sun, 5 May 2013 20:17:48 +0000 (UTC) Received: by mail-wi0-f172.google.com with SMTP id hm14so1980251wib.5 for ; Sun, 05 May 2013 13:17:47 -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=pZrZ69+a0LHW/b/5YyPS0b2mAvY6NTS2JuB8ESB8HDc=; b=nhhdRmzTZUg9D077ZtO/HxtpTJB2CMNMDjV2/ruwL9Diwmo/3Jt+tHIyVpa7Q3XRZF znErOw6rXia3mjmSito/3Do9r7Xoy381MJ8xesRK2ZoGTC82fbKpcil18CBTwKXxdm25 R/C48oH3fHBHo0ZFvREDd9NREaukZlnDEoYNL9fXSalNjql/66thpFlSa0CxpuZvafWd rgGY/UMCD4KznS5xE76k4BbMVfDDbJPNBPUU0E+Ik7LSc5xOnJv0BYv1mb+iEn0UVjw1 Bgvi7Xk5dve7ySMwYOjSyy8nfTMi5wassNkEg7xzIoiLUPzjjSrIom+3gsBDLJZ5kvMz EL6A== X-Received: by 10.180.104.197 with SMTP id gg5mr5695098wib.13.1367785067905; Sun, 05 May 2013 13:17:47 -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 o3sm11020789wia.2.2013.05.05.13.17.45 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 05 May 2013 13:17:46 -0700 (PDT) Message-ID: <5186BE64.8020801@gmail.com> Date: Sun, 05 May 2013 22:17:40 +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> <51869FF6.3000308@libertytrek.org> <5186A58C.4070804@libertytrek.org> In-Reply-To: <5186A58C.4070804@libertytrek.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Archives-Salt: 60931741-effa-4c0e-b7ea-ea1d768a1254 X-Archives-Hash: a625922cd50e121d46933d2856c185a5 On 05/05/2013 20:31, Tanstaafl wrote: > On 2013-05-05 2:18 PM, Neil Bothwick wrote:> On > Sun, 05 May 2013 14:07:50 -0400, Tanstaafl wrote: >>> /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? > >> mkdir -p $BACKUP_DIR/$PGyy/$PGmm/$PGdd/ > > Thanks Neill... > > Tried changing the command in the script to: > >> /usr/bin/pg_dumpall -U $PGUSER -o | gzip > mkdir -p >> $BACKUP_DIR/$PGyy/$PGmm/$PGdd/pg_all-$PGtt.gz That can never possibly work. Look at it carefully and see what it does: You pipe pg_dumpall to gzip and redirect that to a FILE called gzip. I hope you don't run that as root in /bin/! Anyway, what is the shell supposed to do with the -p $BACKUP.... ? What you want cannot be done in one step. You must do it this way (in pseudocode) if dir does not exist create dir write output to file in that dir In real bash test -d $BACKUP_DIR/$PGyy/$PGmm/$PGdd/ || mkdir -p $BACKUP_DIR/$PGyy/$PGmm/$PGdd/ /usr/bin/pg_dumpall -U $PGUSER -o -f $BACKUP_DIR/$PGyy/$PGmm/$PGdd/pg_all-$PGtt.gz I deliberately used the less common "test" command for readability rather than what you will usually find in practice "[[" > > and got this error: > > # ./ecat_pgdump.sh > gzip: invalid option -- 'p' > > Tried putting quotes around it like this: > >> /usr/bin/pg_dumpall -U $PGUSER -o | gzip > "mkdir -p >> $BACKUP_DIR/$PGyy/$PGmm/$PGdd/pg_all-$PGtt.gz" > > and got the original error with the added 'mkdir -p': > > # ./mypg_pgdumpall.sh > ./mypg_pgdumpall.sh: line 10: mkdir -p > /home/user/mypg_backups/2013/May/Sun/ecat-14:26.gz: No such file or > directory > > I'm guessing I just need to know where to put the quotes? No, you need to learn basic script techniques and how bash works wrt to redirection and piping. I recommend a rather famous tutorial - Bash Scripting Guide. Last I looked it was available on tldp.org, but Google knows all the places it is -- Alan McKinnon alan.mckinnon@gmail.com