From owner-freebsd-questions@FreeBSD.ORG Fri Jul 27 19:53:54 2007 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id ACBC616A417 for ; Fri, 27 Jul 2007 19:53:54 +0000 (UTC) (envelope-from martin@dc.cis.okstate.edu) Received: from dc.cis.okstate.edu (dc.cis.okstate.edu [139.78.100.219]) by mx1.freebsd.org (Postfix) with ESMTP id 770BF13C474 for ; Fri, 27 Jul 2007 19:53:54 +0000 (UTC) (envelope-from martin@dc.cis.okstate.edu) Received: from dc.cis.okstate.edu (localhost.cis.okstate.edu [127.0.0.1]) by dc.cis.okstate.edu (8.13.8/8.13.8) with ESMTP id l6RJrsXo086613 for ; Fri, 27 Jul 2007 14:53:54 -0500 (CDT) (envelope-from martin@dc.cis.okstate.edu) Message-Id: <200707271953.l6RJrsXo086613@dc.cis.okstate.edu> To: freebsd-questions@freebsd.org Date: Fri, 27 Jul 2007 14:53:54 -0500 From: Martin McCormick Subject: Remote Execution of sudo Command Hangs. X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 27 Jul 2007 19:53:54 -0000 We have 3 FreeBSD systems. One is trying to use ssh and sudo to run commands on two other systems. The remote command being executed is: ssh remote.system.domain sudo dhcpreset dhcpreset is an expect script most of which is shown here: spawn $env(SHELL) expect -exact "\#" send -- "date\r" expect -exact "\#" #body start send -- "cd /usr/local/etc\r" expect -exact "\#" send -- "/usr/local/etc/zap dhcpd\r" expect -exact "\#" send_user "Stopped [exec hostname] dhcpd at [exec date +%y%m%d%H%M%S ].\n\r" send -- "/usr/local/sbin/dhcpd -q &\r" expect -exact "\#" send_user "Partially restarted [exec hostname] dhcpd at [exec date +%y%m%d%H%M%S ].\n\r" send -- "tail -1f /var/log/syslog\r" expect -exact "peer moves from communications-interrupted to normal" send -- "$CONTROL_C" #body end expect -exact "\#" send_user "Fully restarted dhcpd at [exec date +%y%m%d%H%M%S ].\n\r" send -- "date;exit\r" expect eof The script works perfectly if you run it from a login shell on the system where it actually lives as in: sudo dhcpreset. If you run it via ssh from a remote system, however, it runs, produces the proper status messages and does its job and then . . . . . . You have to hit a Control-C to kill off the ssh connection which doesn't drop on its own. I think my script must somehow make sudo not see the exit. Even though you see the dhcpd -q process started as a background process, dhcpd daemonizes almost immediately and you even see the completion message in a log of the activity so it isn't that. Besides, it exits properly when called locally. Other remote commands using sudo properly exit. Any idea how I might figure out what is hanging things up? If you do a ps on the remote system, the expect script has ended. On the calling system, you still see ssh to the remote system. Reading the expect manual shows an exit command but also says that it is implied when the end of the script is reached. I have tried it with and without that command at the end with no effect. Thanks for any other suggestions for making this command terminate when done.