public inbox for gentoo-user@lists.gentoo.org
 help / color / mirror / Atom feed
From: Alan McKinnon <alan.mckinnon@gmail.com>
To: gentoo-user@lists.gentoo.org
Subject: Re: [gentoo-user] Using date/time variables in cronjobs?
Date: Sun, 05 May 2013 22:17:40 +0200	[thread overview]
Message-ID: <5186BE64.8020801@gmail.com> (raw)
In-Reply-To: <5186A58C.4070804@libertytrek.org>

On 05/05/2013 20:31, Tanstaafl wrote:
> On 2013-05-05 2:18 PM, Neil Bothwick <neil@digimed.co.uk> 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



      parent reply	other threads:[~2013-05-05 20:17 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-05 16:56 [gentoo-user] Using date/time variables in cronjobs? Tanstaafl
2013-05-05 17:07 ` Mick
2013-05-05 17:32   ` Tanstaafl
2013-05-05 17:49 ` Alan McKinnon
2013-05-05 18:07 ` Tanstaafl
2013-05-05 18:18   ` Neil Bothwick
2013-05-05 18:31   ` Tanstaafl
2013-05-05 20:06     ` Todd Goodman
2013-05-05 21:25       ` Neil Bothwick
2013-05-05 21:56         ` Tanstaafl
2013-05-05 23:21           ` Tanstaafl
2013-05-06  0:09             ` Volker Armin Hemmann
2013-05-06  9:48             ` Neil Bothwick
2013-05-06  3:25           ` Pandu Poluan
2013-05-11 16:51             ` SOLVED - WAS " Tanstaafl
2013-05-05 20:17     ` Alan McKinnon [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5186BE64.8020801@gmail.com \
    --to=alan.mckinnon@gmail.com \
    --cc=gentoo-user@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox