Tuesday, January 18, 2011

Httrack Backs Up Your Website

There's a command that you can install
under Linux. It is called Httrack. It
will backup your website, or any other
website for that matter.

Httrack is called an offline browser.
It only backs up files that are availabe
to a web browser. For this reason, it is
not a great tool for formal website backups.
It's intended more for casual backups.

In many cases, though, Httrack can
be quite useful. Say, for example,
you've been asked to backup a website
by the copyright owner for that website.
For whatever reason, the copyright owner
is unable to get an FTP password
for the website. This can happen if the password is held by someone who is
hostile to the copyright owner.

In this case, the parts of the website
that require no special programming can
be backed up with Httrack. Many websites
are like this. They have no backend
programming that needs to be backed up.
These websites consist of nothing but
purely informational web pages.

The great advantage of Httrack is
its simplicity. Here's the command
to backup up a simple website:

httrack http://www.mywebsite.com/

It's a wonderful wonderful thing to
have tools that scale to the size of
the problem. If you only want a very
very simple backup, why not use a very
very simple tool.

Of course, Httrack has many command
line options too. With these command
line options, you can extend the
capabilities of Httrack.

Ed Abbott

Tuesday, January 4, 2011

The Linux su Command

I have always assumed that the
su command stood for switch
user
. After doing a little reading,
I find that the actual meaning is
substitute user. That's pretty
close to the same thing.

I've made many many false assumptions
regarding acronyms in the past. For years
I thought the pwd command stood
for print working directory. Then
I read it stands for present working directory.
Recently I read that it really is
print working directory
. Go figure.

Maybe it is not so important what these
commands stand for as what they do.

The su command indeed lets you
switch from one user to another. Most
often, I find myself switching to the
root user.

Here are 4 different ways to switch to
the root user:

  1. su
  2. su -
  3. su root
  4. su - root

The first way is very simple. You
switch to root. but many variables,
which are exported into your new
shell environment, remain the same.

Here's an example of something that
will stay the same if I do as in the
first example where I type the su
command without the hypen:

---
me=ed
export me
echo $me
ed
su
Password:
echo $me
ed
---

Notice that I've set a
variable called me
to my first name, ed. Next,
I export the variable. I find
the variable still has my
first name in it after I've
logged in as root.

Let try the same thing with
the su - command. This
time, the variable is not exported:

---
me=ed
export me
echo $me
ed
su -
Password:
echo $me

---

See the difference? If I type
expert $me, I end up with
an empty variable and an empty
line. The difference is that I
type su with a hyphen in
one case and without a hyphen
in the other.

The hypen basically says, behave
as if I logged in as root
. The
absence of the hypen says, I
wish to be root but I'd like to
retain as much of my old environment
as possible.


The 3rd and 4th choices shown above
are the same except that the default
root user is explicitly stated. Of
course, you can explicitly state a
user other than root if you wish.

I switch user to root on average once
a day or so. It is something I frequently
need to do.

If you use Linux on a single-user computer,
like I do, it makes sense to switch user
to root often. There's no one here but
myself to administer my system so that's
the way it needs to be.

The lesson of the su command seems
to be to only give yourself as much authority
and power as you need to get the job done. To
overuse or over-reach your authority can lead
to unintended consequences, especially if you
are being careless.

That's the beauty of Unix. You need only give
yourself the authority you need at that moment
and no more.

One more thing I should mention about the using
su with a hypen. If you use the hypen,
then the login shell for the user that you are
switching to is run. Running the login shell
mimics the user you've switched to almost perfectly.

I'd summarize it this way:

  • su without the hypen mimics the
    permissions of the new user but retains
    much of the environment of the old user
  • su with the hypen mimics the
    permissions and the environment of
    the user you have newly switched
    to as completely as possible

I suppose it is the difference between
fully immersing yourself in something
and retaining a little bit of your old
self.

In life, some tasks require very little
of you and so the tendency is to multi-task
and be more than one person in the same
time frame. Other tasks require your full
attention and your full immersion.

The command with the hypen, su -,
is the full immersion version.

Ed Abbott