@@ -16,27 +16,22 @@ local network, but any simple microcontroller that has HTTP capabilites will.
1616
1717``` bash
1818#! /bin/bash
19- # filename: wake_machine.sh
2019
20+ MACHINE_ID=1
21+ MACHINE_MAC_ADDRESS=' 90:80:bb:aa:8d:33'
22+ AUTHENTICATION_TOKEN=' DEFAULT'
23+ LOCAL_NETWORK_SUBMASK=' 192.168.178.255'
24+ API_HOST=' api.green-coding.io'
2125
22- # Install this script as a cronjob
23- # m h dom mon dow command
24- # 15\/* * * * * bash /home/pi/wake_machine.sh
2526
26- # # You need the wakeonlan and the jq package installed
27- # # sudo apt install wakeonlan jq -y
28-
29-
30- output=$( curl " https://api.green-coding.io/v1/jobs?machine_id=7&state=WAITING" --silent | jq ' .["data"] | length' )
27+ # Run your command and capture the output
28+ output=$( curl " https://${API_HOST} /v2/jobs?machine_id=${MACHINE_ID} &state=WAITING" -H ' X-Authentication: ${AUTHENTICATION_TOKEN}' --silent | jq ' .["data"] | length' )
3129
3230# Check if the output is a specific string
3331if [[ " $output " =~ ^[0-9]+$ && $output -ne 0 ]]; then
34- echo " Having waiting jobs. Sending Wake on LAN magic packet ..."
32+ echo " Having waiting jobs. Starting another program ..."
3533
36- # Please replace '80:1B:3E:A8:26:19' with your machines MAC address
37- # Using port 1234 will usually work. If you run into issues try port 9, 8 or 7 also
38- # Do not use the IP address of the machine, but the broadcast address (usually the last number block must be replaced by 255)
39- wakeonlan -i 10.1.0.255 -p 1234 80:1B:3E:A8:26:19
34+ wakeonlan -i $LOCAL_NETWORK_SUBMASK -p 1234 $MACHINE_MAC_ADDRESS
4035
4136 echo " Wake on LAN magic packet send!"
4237else
0 commit comments