* Tanstaafl <tansta...@libertytrek.org> [130505 14:32]: > On 2013-05-05 2:18 PM, Neil Bothwick <n...@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 > > 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?
You can't put it in that line. Put it on it's own line before the pg_dumpall line: mkdir -p $BACKUP_DIR/$PGyy/$PGmm/$PGdd /usr/bin/pg_dumpall -U $PGUSER -o | \ gzip >$BACKUP_DIR/$PGyy/$PGmm/$PGdd/pg_all-$PGtt.gz You could have it check first and only do the mkdir if the directory didn't already exist: [[ -d $BACKUP_DIR/$PGyy/$PGmm/$PGdd ]] || \ mkdir -p $BACKUP_DIR/$PGyy/$PGmm/$PGdd