No internet connection
  1. Home
  2. Technical Support

Character sending via cronjob doesnt work

By @tinyuser2022
    2022-11-21 23:35:24.053Z

    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 ?

    Solved in post #4, click to view
    • 4 replies
    1. C

      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 formatted crontab file or a permission error. Can you please confirm which user the crontab 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.

      1. T@tinyuser2022
          2022-11-22 07:46:23.593Z

          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/hidg

          i 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.

          1. 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 because cron might be using a different environment. I tested using my TinyPilot and it successfully sends h to the target machine every minute.

            ReplySolution
        • T
          In reply totinyuser2022:
          @tinyuser2022
            2022-11-22 17:17:59.440Z

            Indeed you are right - its working now - thank you.