I was thinking if it's possible to use what's inside /Logs/log.txt as a start command to do an action. Something like this, that if I download a file and the package name is NAS Rebootthen the NAS reboots.
tail -f /opt/etc/pyload/Logs/log.txt | while read LOGLINE
do
printf "\rNAS rebooting, please wait ... ${marks[i++ % ${#marks[@]}]}"
sleep 0.1
[[ "${LOGLINE}" == *"Added package NAS Reboot"* ]] && (pkill -P $$ tail; printf "\rNAS rebooting, please wait ... Done.\n";)
done
Is it possible or is there a much simpler way to do a remote reboot?
Something like this?
tail -f /opt/etc/pyload/Logs/log.txt | while read LOGLINE
do
sleep 0.1
[[ "${LOGLINE}" == *"Added package NAS Reboot"* ]] && (pkill -P $$ tail; printf "\rNAS rebooting, please wait ...\n"; reboot;)
done
I tried but it doesn't work. More precisely this is what I've done:
# pyLoad Install - ExternalScript.sh - Download Finished
mkdir -p /opt/etc/pyload/scripts/download_finished
mkdir -p /opt/etc/pyload/scripts/download_finished/SCRIPTS
cat <<"EOM" >/opt/etc/pyload/scripts/download_finished/ExternalScript.sh
#!/bin/bash
sh /opt/etc/pyload/scripts/download_finished/SCRIPTS/NASReboot.sh
EOM
chmod +x /opt/etc/pyload/scripts/download_finished/ExternalScript.sh
# End of pyLoad Install - ExternalScript.sh - Download Finished
# pyLoad Install - ExternalScript.sh - NASReboot
cat <<"EOM" >/opt/etc/pyload/scripts/download_finished/SCRIPTS/NASReboot.sh
#!/bin/bash
tail -f /opt/etc/pyload/Logs/log.txt | while read LOGLINE
do
sleep 0.1
[[ "${LOGLINE}" == *"Added package NASReboot"* ]] && (pkill -P $$ tail; printf "\rNAS rebooting, please wait ...\n"; reboot;)
done
EOM
chmod +x /opt/etc/pyload/scripts/download_finished/SCRIPTS/NASReboot.sh
# End of pyLoad Install - ExternalScript.sh - NASReboot
But when I create a package called NASReboot with any file, it hangs (checking status) and not only it doesn't reboot, but also I cannot cancel that download nor add any new download.
06.06.2016 23:33:58 INFO Added package NASReboot containing 1 links
579 06.06.2016 23:33:59 INFO Download starts: https://pbs.twimg.com/profile_images/3233483519/3635addbbd442a03df6f47351a87e982_400x400.png
580 06.06.2016 23:33:59 INFO ADDON ExternalScripts: Executing scripts in folder `download_preparing`...
581 06.06.2016 23:33:59 WARNING HOSTER BasePlugin[1]: Plugin may be unstable
582 06.06.2016 23:33:59 INFO HOSTER BasePlugin[1]: Grabbing link info...
583 06.06.2016 23:33:59 INFO HOSTER BasePlugin[1]: Link name: 3635addbbd442a03df6f47351a87e982_400x400.png
584 06.06.2016 23:33:59 INFO HOSTER BasePlugin[1]: Link size: N/D
585 06.06.2016 23:33:59 INFO HOSTER BasePlugin[1]: Link status: starting
586 06.06.2016 23:33:59 INFO HOSTER BasePlugin[1]: Processing url: https://pbs.twimg.com/profile_images/3233483519/3635addbbd442a03df6f47351a87e982_400x400.png
587 06.06.2016 23:34:05 INFO HOSTER BasePlugin[1]: File saved
588 06.06.2016 23:34:05 INFO HOSTER BasePlugin[1]: Checking download...
589 06.06.2016 23:34:05 INFO HOSTER BasePlugin[1]: File is OK
590 06.06.2016 23:34:05 INFO Download finished: 3233483519/3635addbbd442a03df6f47351a87e982_400x400.png
591 06.06.2016 23:34:05 INFO ADDON ExternalScripts: Executing scripts in folder `download_finished`...
EDIT: probably I have to change the start action? Don't know, maybe download_preparing or download_processed?
Maybe It time for you to learn how to create hook plugins..,
That way you would be able to watch for links_added event, act upon that and then delete the package
See how I did it in https://github.com/pyload/pyload/blob/stable/module/plugins/hooks/TransmissionRPC.py
Probably you are right. I'm giving a look at the hook; first thing I see is
__pattern__ = r'https?://.+\.torrent|magnet:\?.+' and other things that I can adapt or delete; I am hoping it is not too difficult but I want to try.
__pattern__ is not needed in hook plugins
Beware not to use Tab character in .py file, only spaces.
Closing this..