Buonasera, vorrei inviare un magic packet all'avvio del computer appena la rete è collegata per accendere il NAS che è collegato alla stessa rete. Ho installato wakeonlan e il WOL funziona da terminale. Recuperato uno script bash che funzionava su vecchia versine di xubuntu ma che non pare funzionare su Ubuntu 20.10 #! /bin/sh
# MAC address of backend
SERVER_MAC=XX:XX:XX:XX:XX:XX
#
case "$1" in
start)
echo "WakeOnLan of "$SERVER_MAC
# Issue wakeonlan at intervals until our own network interface
# is active and the magic packet is successfully sent.
#
until /usr/bin/wakeonlan $SERVER_MAC > /dev/null 2>&1 ; do
sleep 1
done
;;
*)
esac
exit 0
|
per gli sh, usa system.d: Create a Custom systemd Service Create a script or executable that the service will manage. This guide uses a simple Bash script as an example: File: test_service.sh
1
2
3
4
5
6
7
8
DATE= while : do echo "Looping..."; sleep 30; done This script will log the time at which it is initialized, then loop infinitely to keep the service running. Copy the script to /usr/bin and make it executable: sudo cp test_service.sh /usr/bin/test_service.sh sudo chmod +x /usr/bin/test_service.sh Create a Unit file to define a systemd service: File: /lib/systemd/system/myservice.service [Unit] Description=Example systemd service. [Service] Type=simple ExecStart=/bin/bash /usr/bin/test_service.sh [Install] WantedBy=multi-user.target This defines a simple service. The critical part is the ExecStart directive, which specifies the command that will be run to start the service. Copy the unit file to /etc/systemd/system and give it permissions: sudo cp myservice.service /etc/systemd/system/myservice.service sudo chmod 644 /etc/systemd/system/myservice.service For more information about the unit file and its available configuration options, see the systemd documentation. Start and Enable the Service Once you have a unit file, you are ready to test the service: sudo systemctl start myservice o crontab, fai crontab -e e come ultima riga fai @crontab /percorso/nomedelprogramma.sh |
Grazie ad entrambi, ho risolto. Se vedete qualcosa che non è propriamente corretto correggete pure :) 1 - Creato script wolNAS.sh posizionato in /usr/bin e reso eseguibile con chmod +x
2 - Creato wolNAS.service in /etc/systemd/system e date permission con chmod 644
3 - abilitato il servizio con sudo systemctl start myservice |
Segui questa domanda
Via email:Una volta eseguito l'accesso potrai iscriverti a tutti gli aggiornamenti qui
Via RSS:Basi di markdown
- *corsivo* o __corsivo__
- **grassetto** o __grassetto__
- collegamento:[testo](http://url.com/ "titolo")
- immagine?
- elenco numerato: 1. Foo 2. Bar
- per aggiungere un'interruzione di riga, aggiungi due spazi a fine riga e premi «Invio»
- è supportato anche semplice HTML
Tag:
domanda posta: 24 Oct '20, 19:29
domanda visualizzata: 221 volte
ultimo aggiornamento: 26 Oct '20, 22:20
ti puo aiutare?
https://www.html.it/pag/369832/eseguire-un-comando-allavvio/