sudo nano /usr/bin/stime.sh
встав
#!/bin/bash
# victor00000 (c) 2019-06-08 15:56:03
n=`date -d"00:00:00" +%s`
ds=`stat -c "%Z" /var/log/lightdm/lightdm.log`
db=`stat -c "%Z-%X" /var/log/boot.log`
db1=`echo "$db" | tr '-' ' ' | \
awk '{print $NF}'`
d1=`echo "$db" | bc`
#n="$d+$n"
((n1=d1+n))
#echo $n
echo -ne "boot: \t"
date -d@$n1 +%T
echo -ne "All: \t"
((n1=(ds-db1)+n))
date -d@$n1 +%T
выход
sudo chmod +x /usr/bin/stime.sh
stime.sh
у меня ubuntu 14.04 Pentium 4.
boot: 00:00:18
All: 00:00:30
Пользователь добавил сообщение 09 Июня 2019, 02:03:19:
======================
C
// stime.c
// victor00000 (c) 2019-06-09 01:54:16
// ~$ gcc -Wall stime.c -o stime.run || echo "Err: $?"
// ~$ ./stime.run
#define _GNU_SOURCE
#define _XOPEN_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>
char boot[]="/var/log/boot.log";
char ldm[]="/var/log/lightdm/lightdm.log";
//====================m0
int main (int ia, char *ca[]){
static char c[200];
struct tm tm;
struct stat st;
lstat (boot,&st);
int m = (int) st.st_mtime;
int a = (int) st.st_atime;
int ma = m - a;
lstat (ldm,&st);
int lm = (int) st.st_mtime;
int la = (int) st.st_atime;
int lma = lm - la;
lma = lm - a;
int t = (int) time (0) - a;
bzero (&tm,sizeof (struct tm));
// time_t now;
// time (&now);
// localtime_r (&now,&tm);
sprintf (c,"2010-01-01 00:00:00");
strptime (c,"%F %T",&tm);
strftime (c,200,"%s",&tm);
// puts (c);
// return 0;
int a0 = atoi (c);
int boot0 = a0 + ma;
int all0 = a0 + t;
all0 = a0 + lma;
sprintf (c,"%d",boot0);
strptime (c,"%s",&tm);
strftime (c,20,"%T",&tm);
printf ("boot: %s\n",c);
sprintf (c,"%d",all0);
strptime (c,"%s",&tm);
strftime (c,20,"%T",&tm);
printf ("All: %s\n",c);
return 0;
}