background

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Use Anonymous Ads

[Share] My shell script that mine with xmr-stak in macOS depends on idle/busy.

This is my script on macOS, that using CPU-mining when working, and automatically switch to GPU-mining when idle for 3 minutes. Wish it's useful for someone. Save the file as idle-miner.command and double click to run:

#!/usr/bin/env perl

my $idle_seconds_command = 'ioreg -c IOHIDSystem | awk \'/HIDIdleTime/ {print $NF/1000000000; exit}\'';

print "Counting seconds of inactivity... Command + Period (.) to quit\n\n";

my $idle_timeout_seconds = 180; # 3 minutes
my $idle_ignore_players_seconds = 10800; # 3 hours
my $check_seconds = 5;

my $child = fork();
my $is_idle = 0;

while(1) {

    if ($child) {

        my $idle_seconds = `$idle_seconds_command`;
        chomp($idle_seconds);
        print "Idle for $idle_seconds seconds.\n";

        if (!$is_idle && $idle_seconds > $idle_timeout_seconds) { # From active to inactive

            # Check if VL, 5KPlayer and Firefox opened
            my $player_running = `pgrep VLC || pgrep 5KPlayer || pgrep firefox`;
            chomp($player_running);

            if (!$player_running || $idle_seconds > $idle_ignore_players_seconds) { # Run as idle, only when no players running, or idle time more than 3 hours

                print "Start Inactive.\n";

                # Kill the current child process first
                system('pkill xmr-stak');
                kill 9, $child;
                waitpid $child, 0;
                $child = 0;

                $is_idle = 1;
                $child = fork();

            }

        } elsif ($is_idle && $idle_seconds < 1) { # From inactive to active

            print "Start Active.\n";

            system('pkill xmr-stak');
            kill 9, $child;
            waitpid $child, 0;
            $child = 0;

            $is_idle = 0;
            $child = fork();

        }

    } else {

        chdir ("/Applications/xmr-stak-amd");

        if ($is_idle) {

            # system './xmr-stak -C pools-noAMD.txt --noCPU';
            system './xmr-stak';

        } else {

            system './xmr-stak -C pools-noAMD.txt --noAMD';

        }

    }

    sleep($check_seconds);

}

Note: I put xmr-stak-amd into Applications folder, change that accordingly if yours is not.
Note2: I ignore the idle status when Firefox, VLC or 5KPlayer are opened, so it won't do GPU-mining and lag my mac while I'm watching YouTube or videos.

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file