[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

RE: how to start a delayed shutdown over ssh and disconnect immediately?



Osamu Aoki wrote:
> By the way, test following to understand real reason why you had
> trouble ...
> Your console is used by shutdown and upon killing ssh connection,
> shutdown program get signal since its connected terminal dies.
> Test1:
> redirect STDOUT/STDERR
> $ sudo shutdown -h +1 >/dev/null 2>/dev/null &

Thank you for your reply.  :-)

2009-08-12 20:20:50 dpchrist@p43400e /cygdrive/u
$ ssh vmdebian500 'sudo shutdown -k +1 >/dev/null 2>/dev/null &'
2009-08-12 20:20:50 dpchrist@p43400e /cygdrive/u
$

That does not block.  Interesting, but I don't understand how/why it
works.  Is this a feature of shutdown?  sudo?  ssh (I think not)?
Something more generic (console I/O?)?  Is there something I can read
which explains this?


> Test 2:
> run shutdown in screen program.
>
http://www.debian.org/doc/manuals/debian-reference/ch09.en.html#_the_scr
een_program

'screen' looks useful -- I'll keep it in mind.


Siggy Brentrup wrote:
> How about
> %  ssh user@remote sudo "echo shutdown -h +1 | at now"

Thank you for your reply.  :-)

2009-08-12 20:38:42 dpchrist@p43400e /cygdrive/u
$ ssh vmdebian500 sudo "echo shutdown -k +1 | at now"

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

[sudo] password for dpchrist: warning: commands will be executed using
/bin/sh
********

Sorry, user dpchrist is not allowed to execute '/bin/echo shutdown -k
+1' as root on vmdebian500.localdomain.
job 20 at Thu Aug 13 00:40:00 2009


This variation seems to work:

2009-08-12 20:39:11 dpchrist@p43400e /cygdrive/u
$ ssh vmdebian500 echo "sudo shutdown -k +1 | at now"
warning: commands will be executed using /bin/sh
job 21 at Thu Aug 13 00:41:00 2009

But, I don't understand why.  I would expect echo to print "sudo
shutdown -k +1 | at now" on stdout and exit.  But, shutdown and at ran
on the remote host... (?) 


This variation does not work:

2009-08-12 20:40:07 dpchrist@p43400e /cygdrive/u
$ ssh vmdebian500 echo "sudo shutdown -k +1" | at now
Invalid command.

The AT command schedules commands and programs to run on a computer at
a specified time and date. The Schedule service must be running to use
the AT command.

AT [\\computername] [ [id] [/DELETE] | /DELETE [/YES]]
AT [\\computername] time [/INTERACTIVE]
    [ /EVERY:date[,...] | /NEXT:date[,...]] "command"

\\computername     Specifies a remote computer. Commands are scheduled
on the
                   local computer if this parameter is omitted.
id                 Is an identification number assigned to a scheduled
                   command.
/delete            Cancels a scheduled command. If id is omitted, all
the
                   scheduled commands on the computer are canceled.
/yes               Used with cancel all jobs command when no further
                   confirmation is desired.
time               Specifies the time when command is to run.
/interactive       Allows the job to interact with the desktop of the
user
                   who is logged on at the time the job runs.
/every:date[,...]  Runs the command on each specified day(s) of the week
or
                   month. If date is omitted, the current day of the
month
                   is assumed.
/next:date[,...]   Runs the specified command on the next occurrence of
the
                   day (for example, next Thursday).  If date is
omitted, the
                   current day of the month is assumed.
"command"          Is the Windows NT command, or batch program to be
run.

I believe echo ran on the remote host, printed "sudo shutdown -k +1" on
stdout, which ssh piped to at on my local host (Vista/Cygwin), which
can't handle commands arriving on stdin.  The AT spew matches:

2009-08-12 20:56:10 dpchrist@p43400e /cygdrive/u
$ /cygdrive/c/Windows/system32/at /?


This variation works, and makes the most sense to me:

$ ssh vmdebian500 'echo "sudo shutdown -k +1" | at now'
warning: commands will be executed using /bin/sh
job 22 at Thu Aug 13 00:47:00 2009

Echo runs on the remote host, piping "sudo shutdown -k +1" to the at
command on the remote host, which runs the (delayed) shutdown command
immediately.  No intermediate file, no chmod -- nice!  :-)


David



Reply to: