Shell script to store high water mark for uptime.
I wrote a small shell script that reads /proc/uptime and prints it in human viewable time. I'd like to somehow store the longest uptime. Here's what I've got so far.
Code:
#!/bin/csh |
I think the simplest method would be to store the current max value in a text file (I'd probably select a dotfile but that is a personal choice) and compare it to the current value, overwriting the data in the text file if the current value is greater.
If you're asking about the details of the comparison, I'd suggest using eval or bash/csh builtin arithmetic comparisons. I'm sure myself or others could give you examples of that sort of thing if that's what you're after. hth |
Wouldn't just converting both values to epoch and subtracting be easier?
|
This just stores the higher numeric value of what's already stored or the first field of proc uptime. If nothing is there when the script is ran it will store the contents of field 1 of /proc/uptime. Note the file location /home/ed/.myuptime will need to be altered for your system.
I attempt no manipulation of the values simply storing the larger of the two. Any manipulation can be done by a display routine - something like your script. Code:
#!/bin/bash |
Thanks! I was able to finish my script using your suggestions. I had to do a little reading to understand what was happening with the bash script and apply that logic it to csh.
Code:
if ( -e .maxuptime ) then |
Quote:
|
All times are GMT -5. The time now is 02:56 PM. |