한참 머리 굴리다가 만들었다. ㅋㅋ


windows에 ssh 서버를 설치해야 하고, (cygwin으로 하면 편한듯)

각 ssh서버들에 id_rsa.pub을 .ssh/authorized_key로 복사해 넣어야 하는 단점이 있긴 하지만...

#!/bin/bash
if [[ -z $1 ]]; then
        RUN_IN_SEC=30
else
        RUN_IN_SEC=$1
fi
PC_ADDR=( "root@172.20.31.27,linux" "ikko@172.20.31.26,windows" "root@localhost,linux" )

# Remote PC
function Run_Remote_Suspend()
{
        local variables=( `echo $@ | tr "," " "` )
        local id_address=${variables[0]}
        local pc_type=${variables[1]}

        if [[ $id_address == "root@localhost" ]]; then
                #let localhost enter suspend mode last
                sleep 10
        fi
        sleep $RUN_IN_SEC

        case $pc_type in
        [lL][iI][nN][uU][xX])
                ssh $id_address "pm-suspend"
                ;;
        [wW][iI][nN][dD][oO][wW][sS])
                # This command disables hibernation feature in windows.
                # Windows requres to install ssh server (tested with cygwin sshd)
                ssh $id_address "powercfg -hibernate off && rundll32 powrprof.dll,SetSuspendState 0,1,0"
                ;;
        esac
}

function Ask_Cancel()
{
        /usr/bin/xmessage -display 127.0.0.1:0.0 -nearmouse -buttons "Cancel:1" "System will enter sleep mode in $RUN_IN_SEC sec"
        # Yes=true, No=False=1
        if [[ $? -eq 1 ]]; then
                kill ${remote_pid[*]} > /dev/null
                notify-send -t 2 -i "system" "Canceled entering Sleep Mode" "Entering sleepmode canceled by user"
        fi
}

notify-send -t 2 -i "system" "Entering Sleep Mode" "System will enter sleep mode in $RUN_IN_SEC seconds."
for each_pc in ${PC_ADDR[*]};
do
        Run_Remote_Suspend $each_pc &
        remote_pid=( ${remote_pid[*]} $! )
done

Ask_Cancel&
let xmessage_sleep=$RUN_IN_SEC-1
sleep $xmessage_sleep && killall xmessage


저작자 표시 비영리 동일 조건 변경 허락
신고
 «이전 1 ··· 6 7 8 9 10 11 12 13 14 ··· 465  다음»