Skip to content

Commit

Permalink
Send WOL (wake on lan) to group
Browse files Browse the repository at this point in the history
  • Loading branch information
raultm committed Jul 4, 2022
1 parent d220a7e commit 0e89af8
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 4 deletions.
4 changes: 2 additions & 2 deletions DEBIAN/control
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: multish
Version: 1.0.0
Version: 1.0.3
Architecture: all
Maintainer: Raul Tierno<[email protected]>
Depends: tmux,sshpass,nmap
Depends: tmux,sshpass,nmap,ldapscripts,wakeonlan
Description: multish allows you to connect and act in multiple ssh connection simultaneously
8 changes: 6 additions & 2 deletions usr/bin/multish
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,13 @@ function selectoption {
echo "-----------------------------------------"
PS3="$prompt "

select opt in "${options[@]}" "Find hosts with port 22 open in network" "Copy SSH public key to group" "Quit" ; do
if (( REPLY == 3 + ${#options[@]} )) ; then
select opt in "${options[@]}" "Find hosts with port 22 open in network" "Copy SSH public key to group" "Wake Up Group" "Quit" ; do
if (( REPLY == 4 + ${#options[@]} )) ; then
break
elif (( REPLY == 3 + ${#options[@]} )); then
echo
multish-wake
exit
elif (( REPLY == 2 + ${#options[@]} )); then
echo
multish-copy-id
Expand Down
29 changes: 29 additions & 0 deletions usr/bin/multish-wake
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

prompt="Select group:"
options=( $(find /etc/multish/group -type f -name "*" -print0 | xargs -0) )
echo ""
echo "Send Wake up message to group"
echo "------------------------"
PS3="$prompt "
select opt in "${options[@]}" "Quit" ; do
if (( REPLY == 1 + ${#options[@]} )) ; then
break
elif (( REPLY > 0 && REPLY <= ${#options[@]} )) ; then
echo "You picked $opt which is file $REPLY"
echo -n Password:
read -s password

for name in $(cat $opt | awk -F\# '$1!="" { print $1 ;}' | sed 's/.*@//' | sed 's/\..*//');
do
echo ""
echo $name
/usr/share/multish/despierta.sh $name
done
break
else
echo "Invalid option. Try another one."
fi
done

multish
34 changes: 34 additions & 0 deletions usr/share/multish/despierta.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash
# despierta.sh
# Victor Martinez Pajares
# Envia una señal wakeonlan a un equipo según su nombre
# Se puede hacer con etherwake, pero obliga a generar un fichero de macs-name y es un rollo.

if [ "$#" -ne 1 ]; then
echo "Send a wakeonlan magic packet to a hostname"
echo "Use: $0 hostname"
exit
fi

# Search in group 1
echo "Searching $1 in group 1."
SEARCH=`ldapsearch -xLLL -h ldap -b cn=$1,cn=group1,cn=INTERNAL,cn=DHCP\ Config,dc=instituto,dc=extremadura,dc=es "dhcpHWAddress" 2> /dev/null`

# If fails, search in group 2
if [ "$?" -ne 0 ]; then
echo "Can't find $1 in the group 1."
echo "Searching $1 in group 2."
SEARCH=`ldapsearch -xLLL -h ldap -b cn=$1,cn=group2,cn=INTERNAL,cn=DHCP\ Config,dc=instituto,dc=extremadura,dc=es "dhcpHWAddress" 2> /dev/null`
fi

# If can't find, exit
if [ "$?" -ne 0 ]; then
echo "Can't find the hostname $1."
echo "No WakeOnLAN package was sended to the net."
exit
fi

MAC=`echo $SEARCH | grep -o '[^ ]*$'`

echo "Sending WakeOnLan package to $1 with MAC: $MAC"
wakeonlan $MAC

0 comments on commit 0e89af8

Please sign in to comment.