[Novalug] script question

Bryan J. Smith b.j.smith at ieee.org
Wed Mar 24 13:55:47 EDT 2010


To answer your questions ...

On permissions ... only root can change ownerships of a file.  So if
you copy a file, and want to retain original ownership, then you need to do
it as root, as only root can change the ownership on a copy (instead of it
being the user who copied it).  If you make an archive (like tar), then it can
be stored, and the issue is only one when you extract.

BTW, there are several ways to copy -- e.g. (not looking at remote copies):  
[ NOTE:  All these won't cross filesystem mounts, which is an important consideration sometimes ]
  # cp -dlpR (src) (dst)
  # cd (src) ; find . -mount | cpio -pmdv (dst)
  # cd (src) ; tar clf - --xattr . | tar xvf - --xattr -C (dst)

The former works for most things, but some files types may not work consistently
across platforms.  Remove the "-l" to cross filesystems.

The middle works consistently across most UNIX/Linux platforms, but it does not
always preserve hard links or extended attributes.  Remove the "-mount" to
cross filesystems (-xdev is not always supported in many find implementations).

The last works almost always for everything, at least with GNU Tar (1.14+), on
any platform.  It preserves everything, including hard links and extended attributes.
Remove the "-l" to cross filesystems.

On your script ... it looks like it is called by another program, and the base argument
(?) is a URL.  It then sends that to alpine, which I have never heard of before today.
Looks like a PINE replacement (simple, text-based e-mail client).

As far as book recommendations, I have two ... one to start, one to consider later ...

1)  Beginning Portable Shell Scripting
http://www.amazon.com/Beginning-Portable-Shell-Scripting-Professional/dp/1430210435  

Too many of us "old dogs" really get wrapped up with pdksh, ksh93 and bash
specifics.  But learning more "pure" POSIX Bourne shell (sh) is most ideal, and
will let you avoid having to hack shell scripts to run not only on different versions
of UNIX/Linux flavors, but different releases of even the same shell.  E.g., bash
2.05 v. 3.00 v. 3.1 has bitten me enough times that I fall back.

As I mentioned before, just knowing at least one shell scripting language is "good
enough."  But this book really takes the time to teach it "The Right Way(TM)" for
portability.  It's good stuff for seasoned sysadmins as well as beginniners.

I love the Apress books.  I'm currently reading Beginning Python Visualization
myself.  I'm not a Python coder (Perl and Java, yes, Python, only modifying others
existing code).  I'm not big on learning programming for programming's sake.
And it's written for engineers and scientists who want to visualize data with a real,
object oriented, platform-agnostic language -- instead of fighting various math
visualization packages and their script.

2)  Mastering Regular Expressions
http://www.amazon.com/Mastering-Regular-Expressions-Jeffrey-Friedl/dp/0596528124  

This one is for when you learn basic shell scripting and start branching out into
doing things regularly, possibly with Perl, Python, PHP, etc... too  You don't need
the latest edition of this book to get the fundamentals down, and even just reading
the early chapters will help you greatly (although newer editions will address
newer scripting languages more).  Learning how to use regular expressions to
match, extract and/or replace text strings in output and in files is a powerful and
I mean powerful tool that is applicable in everything and everywhere (even
Windows C++ code).  Again, just the first few chapters teach you how to think,
and 80-90% of what you'll need to use regex's.  Everything else is practice.

-- Bryan

P.S.  Although aged now, the April 2002 edition of Sys Admin Magazine
featured my ~200 line back2cd tcsh** script, which uses per-file compression
(your choice of bzip2, gzip or lzop), to put the files to CD/DVD.  I still use it for
"point" backups, fitting a good 12GiB per DVD-R.  Unlike a lot of people who
tar or, in some cases, afio, there is no "archive" on the CD/DVD, just the files
(as an ISO9660 "yellow book" track image -- aka .iso image -- is an archive
in itself), so it's very easy and quick to restore -- not to mention an optical error
is localized (to only the file, not anything that was compressed along with it like
in a tar.bz2/tar.gz/tar.lzo).  I still get request for it today, since samag.com is no
longer on-line.

**NOTE:  tcsh was utilized because bash was so inconsistent in handling paths
with whitespace back in '99-'01, and worked consistently across many platforms.

 


----- Original Message ----
From: Beartooth <beartooth at Beartooth.Info>

...
Question on that backup script:
...
an empty one will hold /home on any of my PCs with 
room to spare. I am able to copy directories into these, though 
sometimes only as root.
(Do I need to change ownership, or permissions, or what 
... 
    My ~/bin already contained an executable, which I have no 
recollection of. gedit couldn't handle it; upon experimentation, 
I got it open with something called KWrite, which shows :
...
#!/usr/bin/perl -w
use strict;
my $url_from_pan = $ARGV[0];
my $command = "Terminal -e 'alpine -url " . $url_from_pan . "'";
system($command);
Can anybody tell from that what it is or does?



More information about the Novalug mailing list