Git Product home page Git Product logo

syno_autoshutdown's Issues

Calculation of longrunners is not correct

have a look at the time values (6:50->7:43->40mins?). config is set to NOTIFY_ON_LONGRUN_EVERY=120, so the warning should be written after 2h and not after 40mins...

  • wrong point of time
  • wrong time calculation
12.11.2019 07:43:43 [18739] [I] - Sending notification (MESSAGE_LONGRUN)
12.11.2019 07:43:43 [18739] [D] - DS2413
12.11.2019 07:43:43 [18739] [D] - Das System ist bereits seit 12.11.2019 06:50:24 für 0d:0h:40m:0s online. Weiterhin erforderlich?

Use local variables to improve maintainability/documentation

Although it is perfectly fine to use parameters as $1and $2 in the code like here...

notification()
{
# $1: system (myname)
# $2: message
if [ "x$IFTTT_KEY" != "x" ]; then
if [ "x$IFTTT_EVENT" != "x" ]; then
if [ "x$1" != "x" ]; then
MY_NAME=$1
MY_STATUS=$2
writelog "D" "$MY_NAME"
writelog "D" "$MY_STATUS"

... I suggest to always assign those to local variables as first thing in every function. This is a measure to make the code speak more for itself (instead having comments do that - have comments explain the non-trivial stuff).

Example

 notification() 
 { 
 	local system=$1    # myname
        local message=$2
 
 	if [ "x$IFTTT_KEY" != "x" ]; then 
 		if [ "x$IFTTT_EVENT" != "x" ]; then 
 			if [ "x$system" != "x" ]; then 
 				MY_NAME=$system 
 				MY_STATUS=$message
 				writelog "D" "$MY_NAME" 
 				writelog "D" "$MY_STATUS" 

Set default values

Every necessary variable should have a default value which is set if no config definition is set.

enhanced code documentation

The code must be documented as comprehensively and meaningful as possible. Important lines/blocks in the code should be sufficiently commented and all functions should be provided with an appropriate header which describes the function, the input variables as well as the output variables.

Handle multiple instances in a proper way

Several instances of the script must be checked and handled correctly depending on the future scope of functions.

Starting the script from within itself requires at least several instances for a short time (2). Also, later parameterized calls to terminate all instances or other functions implemented in a single script could lead to several instances being (temporarily) executed at the same time.

Nevertheless, it should be considered whether the permanent execution of multiple instances makes sense. In particular, logging in different logs under different PIDs is not useful.

Detect systems in standby/sleep state

Systems in standby or sleep state (e.g. Macbook) are detected as valid marker system and the system won't shutdown. Implement a fix to detect systems in standby and shutdown the NAS.

Use bash as interpreter

The shebang


suggest a POSIX (-only) shell interpreter, but the code contains at least here strings (a bashism) like in this case.
if grep -q "$FOUND_IP " <<< "$CHECKHOSTS"; then

This does not produce an error since on most Linux systems, sh is usually a symlink to bash or dash or some other "way more advanced then pure POSIX sh"-shell, but it's still wrong.

Fixing is easy: use #!/usr/bin/env bash as shebang.
(This also uses environment lookup).

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.