Coder Social home page Coder Social logo

inactive's Introduction

Command inactive

go.dev reference Go Report Card Latest Version Latest Version Go

Command line tool that can be used to determine if a computer has not been active recently. I use it to make sure my machines don't get left on when I am not using them.

The basics of how it works:

  • looks at all files named: /tmp/stayawake.*, if any of the files have been modified in the last 25 minutes the command exits with a status of 1.
  • if the computer has an uptime of less than 5 minutes the command exits with a status of 1.
  • if neither of the above are true the command exits with a status of 0.

As a result in order to keep your computer awake you just need to touch a file that looks like /tmp/stayawake.\*, in my case I use my bash prompt to automatically touch a file of that sort.

Example usage in a crontab (I have it run every 3 minutes):

*/3 * * * * /root/inactive && \
    ( test -f /run/nologin || /sbin/shutdown -h +5 ) || /sbin/shutdown -c

To install you can simply run go get github.com/nthnca/inactive.

NOTES:

  • This command doesn't actually shut down the computer because of possible permission issues and different OSes may have different ways to shut the computer down.
  • The check for /run/nologin is to see if a shutdown has already been scheduled, if so we don't want to schedule another shutdown since it will cancel the first shutdown ... basically resulting in a denial of service for shutting down... oops. :-)
  • On my system to get the shutdown -h +5 command to work I had to run sudo apt install --reinstall dbus

inactive's People

Contributors

nthnca avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.