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.


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.