Skip to content
Advertisement

Compare A Variable Regularaly Using Linux Scripts and Cron

I’m trying to check if a number differs from what it was last time it was checked, in this case checking a number every minute, using Linux scripts and cron.

eg:

JavaScript

But the problem I am having is that the variables aren’t accessible between scripts and using source (eg. source script.sh) runs the script again, hence getting the latest version, not the one from a minute ago.

The best I’ve got is running a first script which gets the current number, then sleeps for a minute, then runs a second script which is essentially the first two lines of the code above.

eg:

JavaScript

This seems inefficient to me and I’d like to know if there is a better solution if possible.

Advertisement

Answer

You could cache the previous number in a file:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement