[NCLUG] Oops,

alan schmitz alan.schmitz88 at gmail.com
Thu Feb 20 21:54:08 MST 2014


Is it possible to see anything useful by adding
set -x
to the beginning of the script and check the output?
On Feb 20, 2014 9:38 PM, "Bob Proulx" <bob at proulx.com> wrote:

> Steve Wolf wrote:
> > I agree.  --exclude makes your life much easier.  --recursion is the
> > default behavior in tar, so I'd suggest
>
> Agreed to all.
>
> > #!/bin/sh
> > pushd /home
> > tar cvzpPf /mnt/UserBackup/BKkerrym2.tar.gz \
> >   --exclude=kerrym2/KerrysStuff \
> >   --exclude=kerrym2/Pictures \
> >   --exclude=kerrym2/Downloads \
> >   --exclude=kerrym2/.wine/drive_c \
> >   kerrym2
> > popd
> > echo -e "\nBKkerrym2.sh done"
> > return
>
> Hmm...  That depends upon the system.
>
>   rwp at dismay:~$ /bin/sh
>   $ type pushd
>   pushd: not found
>   $ type popd
>   popd: not found
>   $
>
> It depends on if your system has /bin/sh symlinked to bash or not
> since those are bash'isms.  Ubuntu, Debian, Mint, others, link it to
> dash.  But the popd is not needed.  It isn't necessary to cd anywhere
> at the end of the script when exiting.  Just exit the script.  And I
> mean "exit 0" not "return" too.  :-) "return" is from shell functions
> not the script itself.
>
> Amazingly echo is much less portable than people think.  I would avoid
> the -e option.  If you really want escapes then "printf" is the best
> most portable way to do that these days.  AFAIK the -p is only for
> extracting from the tar file.  I also don't think the -P option
> is needed either.  With that I suggest:
>
> #!/bin/sh
> cd /home || exit 1
> tar cvzf /mnt/UserBackup/BKkerrym2.tar.gz \
>   --one-file-system \
>   --exclude=kerrym2/KerrysStuff \
>   --exclude=kerrym2/Pictures \
>   --exclude=kerrym2/Downloads \
>   --exclude=kerrym2/.wine/drive_c \
>   kerrym2
> if [ $? -ne 0 ]; then
>   echo "Error: tar exited with an error" 1>&2
>   exit 1
> fi
> echo "BKkerrym2.sh done"
> exit 0
>
> If we keep passing it around and everyone adds something to it by the
> end of the week we would have full option processing and online help
> in there too.  :-)
>
> Bob
> _______________________________________________
> NCLUG mailing list       NCLUG at lists.nclug.org
>
> To unsubscribe, subscribe, or modify
> your settings, go to:
> http://lists.nclug.org/mailman/listinfo/nclug
>


More information about the NCLUG mailing list