BackupPC-users

Re: [BackupPC-users] automatic waking and shutting down Linux clients

2011-09-11 23:25:03
Subject: Re: [BackupPC-users] automatic waking and shutting down Linux clients
From: Holger Parplies <wbppc AT parplies DOT de>
To: "Robert E. Wooden" <rbrtewdn AT comcast DOT net>
Date: Mon, 12 Sep 2011 05:23:02 +0200
Hi,

Robert E. Wooden wrote on 2011-09-11 16:29:32 -0500 [[BackupPC-users] automatic 
waking and shutting down Linux clients]:
> First, I am very much a novice at bash scripting, so bare with me as I 
> learn by doing.

depends on what you want us to bare ;-).

> [...]
> So, I simply placed 
> '/usr/local/bin/shutdown.sh' into the client config file line 
> "DumpPostUserCmd". That shutdown script is: "ssh -T root@[my client 
> static IP address] /sbin/shutdown -h now >/dev/null" (minus the 
> quotation marks, of course.)
> 
> I now know that I can WOL a client and shut it down when the backup has 
> completed. Now, time to refine and simplify my shutdown script. I have 
> to study the manpage of ssh to see if "-T" means the same as the 
> ">/dev/null" term at the end of the string. If I don't need both then . . .
> 
> I am sure someone will have some thoughts and opinions?

I'm not quite sure what your question is. Should you read the ssh man page?
Yes. Does the ssh '-T' option redirect stdout to /dev/null? No. Is it
important to clean up your (working) script? No, but go ahead if you like to.
Remember what worked for you so you can always go back to that.

If your goal is to get rid of the script and put the command in
DumpPostUserCmd, you should be able to do that as it is (the output
redirection won't be handled locally, because BackupPC doesn't use a shell to
execute DumpPostUserCmd - it will be passed to the remote shell invoked by
ssh, which will handle it just fine). I don't really see why redirecting
*stdout* is important anyway (except for keeping your log file clean). As for
*stdin*, you could look at the '-n' option of ssh. '-q' works well for
backups, so you might as well add it here, too. '-T' doesn't seem to have any
effect - at least I wouldn't expect a tty to be allocated without it either
(but I might be wrong - try 'ssh root@host tty' to find out).

You could call your script with a parameter $host or $hostIP and then use

        ssh root@$1 ...

instead of hard-coding the static IP into shutdown.sh. That way, you could use
the same script for any of your clients (should you ever want to shut down
more than one of them). For readability/documentation, you might want to give
a name to your parameter, as in

        #!/bin/sh
        host=$1
        ssh root@$host ...

or even

        #!/bin/sh
        host=${1:-[default hostname]}
        ssh root@$host ...

if you want to shut down [default hostname] (replace by name or IP) if no
parameter is given (I don't know why you'd want to do that, but since you're
learning bash scripting, I thought I'd mention it anyway). Note that
'localhost' is probably *not* a good default in this case ;-).
Being prepared for someone forgetting the argument is always a good idea,
though you might prefer printing an error message and exiting the script
instead:

        #!/bin/sh
        host=${1:?Host name argument to $0 missing - check your hostname.pl}
        ssh root@$host ...

If you're experimenting with those examples, you'll probably want to run
something like 'date' instead of 'shutdown' ;-).

I can also recommend reading the bash man page. Long, but interesting.

Regards,
Holger

------------------------------------------------------------------------------
Doing More with Less: The Next Generation Virtual Desktop 
What are the key obstacles that have prevented many mid-market businesses
from deploying virtual desktops?   How do next-generation virtual desktops
provide companies an easier-to-deploy, easier-to-manage and more affordable
virtual desktop model.http://www.accelacomm.com/jaw/sfnl/114/51426474/
_______________________________________________
BackupPC-users mailing list
BackupPC-users AT lists.sourceforge DOT net
List:    https://lists.sourceforge.net/lists/listinfo/backuppc-users
Wiki:    http://backuppc.wiki.sourceforge.net
Project: http://backuppc.sourceforge.net/

<Prev in Thread] Current Thread [Next in Thread>