From: "Victor Zhuravlyov" <vitich@gmail.com>
To: "ALT Linux Community general discussions" <community@lists.altlinux.org>
Subject: Re: [Comm] Вопрос по IceWM
Date: Tue, 11 Sep 2007 11:08:16 +0300
Message-ID: <304a207e0709110108k1c3ffafam87d5d48961b4c6b3@mail.gmail.com> (raw)
In-Reply-To: <m3sl5l3e7e.fsf@evg.krastel.ru>
Рассказываю по порядку.
Сначала создаются два пользователя remote-powerdown remote-reboot с
соответствующим шеллом )
Есть скрипт использующий expect:
[vitich@vitich poweroff]$ cat ssh_poweroff.expect
#!/usr/bin/expect -f
# usage: ssh_poweroff [terminal_address]
set PASSWORD "FiniSH+OK"
stty -echo
set ADDRESS  "[lrange $argv 0 0]"
puts "\n*** Halting the terminal $ADDRESS ***\n"
spawn ssh remote-poweroff@$ADDRESS
puts "*** Waitimg for 'assword' ..."
expect {
    "assword"	{puts "*** Sending password ***" ;  send "$PASSWORD\n" }
    timeout	{puts "*** Timeout ..." ;  exp_continue}
}
send_user "*** Waiting for terminal halt ... ***"
expect {
    "system"	{}
    "reboot"	{}
    "halt"	{}
    fail	{puts "\n*** SSH connect broken ***\n"}
    timeout	{puts "*** Timeout ..." ;  exp_continue}
}
puts "\n*** OK ***\n"
И есть два скрипта /usr/bin/rpoweroff и /usr/bin/rreboot
Почти всё позаимствовано у скрипта display2menu Миши Шигорина дабы
определить адрес x-терминала для выключения.
[vitich@vitich poweroff]$ cat rpoweroff
#!/bin/bash
debug() {
	[ -n "$DEBUG" ] && echo "$*" >&2
}
LC_MESSAGES=C
RESOLVE=/usr/bin/resolve
get_ip() {
	[ -x "$RESOLVE" ] && {
		IP="`resolve -s $HOST 2>/dev/null`"
		[ -z "$IP" ] && {
			debug "Can't resolve $HOST, using as is"
			IP="$HOST"
		}
		echo $IP
	} || {
		debug "No $RESOLVE executable!"
	}
}
[ -z "$DISPLAY" ] && {
	debug "No DISPLAY defined!"
	exit
}
HOST=${DISPLAY%%:*}
DISP=${DISPLAY##*:}
case "$HOST" in
	# I know it's a shell pattern... so 80% solution
	[0-9]*.[0-9]*.[0-9]*.[0-9]*)
		IP="$HOST"
		debug "X-terminal; IP: $IP"
		;;
	[a-zA-Z]*)
		IP="`get_ip $HOST`"
		debug "X-terminal; host: $IP"
		;;
	*)
		HOST="`hostname 2>/dev/null`"
		IP="`get_ip $HOST`"
		debug "Local display; $HOST"
esac
ssh_poweroff.expect $IP
Второй скрипт аналогичный.
Так вот если запускать из-под рядового пользователя из xterm - работает.
Прописал в ~/.icewm/preferences и /etc/X11/icewm/preferences
RebootCommand="rreboot"
ShutdownCommand="rpoweroff"
С /usr/bin тоже пробовал прописывать, хотя смысл? В консоли работает и без пути
Скрипт на expect не мой, я не программер :)
Может есть более правильное решение по управлению x-терминалом, но
стандартно при попытке перезагрузить или выключить комп с терминала он
просто секунд 10-20 висит, потом перезапускает gdm. А надо тушить.
next prev parent reply	other threads:[~2007-09-11  8:08 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-10 14:36 Victor Zhuravlyov
2007-09-11  6:31   ` Евгений Терешков
2007-09-11  8:08     ` Victor Zhuravlyov [this message]
2007-09-17 13:16       ` Michael Shigorin
2007-09-11  8:10     ` Victor Zhuravlyov
2007-09-11 12:35       ` Евгений Терешков
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox
  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):
  git send-email \
    --in-reply-to=304a207e0709110108k1c3ffafam87d5d48961b4c6b3@mail.gmail.com \
    --to=vitich@gmail.com \
    --cc=community@lists.altlinux.org \
    /path/to/YOUR_REPLY
  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
ALT Linux Community general discussions
This inbox may be cloned and mirrored by anyone:
	git clone --mirror http://lore.altlinux.org/community/0 community/git/0.git
	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 community community/ http://lore.altlinux.org/community \
		mandrake-russian@linuxteam.iplabs.ru community@lists.altlinux.org community@lists.altlinux.ru community@lists.altlinux.com
	public-inbox-index community
Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://lore.altlinux.org/org.altlinux.lists.community
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git