Hi,
i want to stop a remote laptop to fall into sleep mode. Thats why i plan to send every 5 minutes a character via /dev/hidg0. Via command line it works like a charm but via Cron it doesnt work at all. I also created a cronjob with sudo - same result.
How can i make it work? Any better idea around ?
- CCharles Hague @cghague2022-11-22 00:29:10.338Z
Hi @tinyuser2022 - thanks for your question about keeping a laptop awake!
The most likely explanations for the command failing when ran via
cron
but working when ran manually would be either an incorrectly formattedcrontab
file or a permission error. Can you please confirm which user thecrontab
was created for and provide a copy of the contents?You might be interested in the mouse jiggler script. The script will move the mouse at predetermined intervals for as long as it is running and could be modified to simulate keyboard presses if that's required.
- T@tinyuser2022
Hi,
the cron is definitly correct:
*/1 * * * * echo -ne "\0\0\xb\0\0\0\0\0" > /dev/hidg0; echo -ne "\0\0\0\0\0\0\0\0" > /dev/hidgi created it with the user "pilot" and/or sudo cron -e ->so for root.
Basically the script is sending something to the remote computer since the laptop is not going to sleep. But it is sending a mouse command or something else but not the character it should been send.
I opened notepad on the remote and i do not see any character coming with cron but instead the right or left mouse key is always pressed which is kindly annoying since you need to first clear the appearing windows.- David @david2022-11-22 16:50:35.315Z
Thanks for sharing that info! Can you try this instead?
*/1 * * * * /bin/echo -e "\x00\x00\x0B\x00\x00\x00\x00\x00" > /dev/hidg0; /bin/echo -e "\x00\x00\x00\x00\x00\x00\x00\x00" > /dev/hidg0;
I think you have to specify the full path for
echo
becausecron
might be using a different environment. I tested using my TinyPilot and it successfully sendsh
to the target machine every minute.
- TIn reply totinyuser2022⬆:@tinyuser2022
Indeed you are right - its working now - thank you.