Article 53901 this script has been run N times since last host system reboot

this script has been run N times since last host system reboot

by
Skaperen
from LinuxQuestions.org on (#53901)
i want to determine how many times a script has been run since the last reboot. if two instances are started at nearly the same time, getting swapped numbers is OK because the goal is to have them be unique, especially which process gets the number 0. this needs to be done in bash (even in ".bashrc"), but it could invoke something written in another language (open source is essential), passing its name.

this is in the scope of each user. running the same script in a different user gets its own sequence of numbers starting at 0.

this is the first idea.

i'd start by making sure only one process of this script can run at one time by locking on "~/.name_of_script.lock". then i'd see if "~/.name_of_script.runs" already exists. if so, i'd read the number in it, add 1, and set N to the sum. if not, i'd set N to 0. then i would store N into "~/.name_of_script.runs". then i would unlock "~/.name_of_script.lock".

any better ideas? i'm thinking of making a module/command to do this in python and just using that from bash.latest?d=yIl2AUoC8zA latest?i=-2mPu5DGw8c:JmrgU2jMS4E:F7zBnMy latest?i=-2mPu5DGw8c:JmrgU2jMS4E:V_sGLiP latest?d=qj6IDK7rITs latest?i=-2mPu5DGw8c:JmrgU2jMS4E:gIN9vFw-2mPu5DGw8c
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments