how to get complete startup time on solaris - solaris

I'm struggling to find a command or even a way to find the complete startup time on my Solaris(sun4u sparc SUNW,Netra-T12) box
Solaris
who -b gives me Jun 22 11:09 but no year
same with last reboot | head -n 1
However in my Linux(GNU/Linux x86_64) boxes i'm able to get the full startup time
Linux
who -b gives me 2014-08-23 11:09
Any help?
EDIT
output of apptrace uptime 2>&1
-> uptime -> libc.so.1:int atexit(int (*)() = 0xff3c59ec)
<- uptime -> libc.so.1:atexit()
-> uptime -> libc.so.1:int atexit(int (*)() = 0x10ae8)
<- uptime -> libc.so.1:atexit()
-> uptime -> libc.so.1:char * setlocale(int = 0x6, const char * = 0x10af8 "")
<- uptime -> libc.so.1:setlocale() = 0xfefdb25e
-> uptime -> libc.so.1:char * textdomain(const char * = 0x10afc "SUNW_OST_OSCMD")
<- uptime -> libc.so.1:textdomain() = 0x22b58
-> uptime -> libc.so.1:sysinfo(0x202, 0xffbff97f, 0x1) ** NR
-> uptime -> libc.so.1:void * malloc(size_t = 0x73)
<- uptime -> libc.so.1:malloc() = 0x23158
-> uptime -> libc.so.1:sysinfo(0x202, 0x23158, 0x73) ** NR
-> uptime -> libc.so.1:const char * getexecname(void)
<- uptime -> libc.so.1:getexecname() = 0xffbfffc5
-> uptime -> libc.so.1:strlen(0xffbfffc5, 0x23158, 0x10800) ** NR
-> uptime -> libc.so.1:void * malloc(size_t = 0x82)
<- uptime -> libc.so.1:malloc() = 0x231d8
-> uptime -> libc.so.1:strcpy(0x231d8, 0xffbfffc5, 0xffbfffd4) ** NR
-> uptime -> libc.so.1:char * strrchr(const char * = 0x231d8 "/usr/bin/uptime", int = 0x2f)
<- uptime -> libc.so.1:strrchr() = 0x231e0
-> uptime -> libc.so.1:strlen(0x231d8, 0x2f, 0x231eb) ** NR
-> uptime -> libc.so.1:char * strtok(char * = 0x23158 "sparcv9+vis2 sparcv9+vis sparcv9 sparcv8plus+vis2 sparcv8plus+vis sparcv8plus sparcv8 sparcv8-fsmuld sparcv7 sparc", const char * = 0x10b60 " ")
<- uptime -> libc.so.1:strtok() = 0x23158
-> uptime -> libc.so.1:strcpy(0x231e1, 0x23158, 0x231e1) ** NR
-> uptime -> libc.so.1:char * strcat(char * = 0x231e1 "sparcv9+vis2", const char * = 0x10b64 "/")
<- uptime -> libc.so.1:strcat() = 0x231e1
-> uptime -> libc.so.1:char * strcat(char * = 0x231e1 "sparcv9+vis2/", const char * = 0xffbfffce "uptime")
<- uptime -> libc.so.1:strcat() = 0x231e1
-> uptime -> libc.so.1:access(0x231d8, 0x1, 0x231f1) ** NR
-> uptime -> libc.so.1:char * strtok(char * = 0x0 <NULL>, const char * = 0x10b84 " ")
<- uptime -> libc.so.1:strtok() = 0x23165
-> uptime -> libc.so.1:strcpy(0x231e1, 0x23165, 0x231f1) ** NR
-> uptime -> libc.so.1:char * strcat(char * = 0x231e1 "sparcv9+vis", const char * = 0x10b64 "/")
<- uptime -> libc.so.1:strcat() = 0x231e1
-> uptime -> libc.so.1:char * strcat(char * = 0x231e1 "sparcv9+vis/", const char * = 0xffbfffce "uptime")
<- uptime -> libc.so.1:strcat() = 0x231e1
-> uptime -> libc.so.1:access(0x231d8, 0x1, 0x231f0) ** NR
-> uptime -> libc.so.1:char * strtok(char * = 0x0 <NULL>, const char * = 0x10b84 " ")
<- uptime -> libc.so.1:strtok() = 0x23171
-> uptime -> libc.so.1:strcpy(0x231e1, 0x23171, 0x231f0) ** NR
-> uptime -> libc.so.1:char * strcat(char * = 0x231e1 "sparcv9", const char * = 0x10b64 "/")
<- uptime -> libc.so.1:strcat() = 0x231e1
-> uptime -> libc.so.1:char * strcat(char * = 0x231e1 "sparcv9/", const char * = 0xffbfffce "uptime")
<- uptime -> libc.so.1:strcat() = 0x231e1
-> uptime -> libc.so.1:access(0x231d8, 0x1, 0x231ec) ** NR
-> uptime -> libc.so.1:execve(0x231d8, 0xffbff9e4, 0xffbff9ec) ** NR
ld.so.1: uptime: warning: /usr/lib/abi/sparcv9/apptrace.so.1: open failed: illegal insecure pathname
ld.so.1: uptime: warning: /usr/lib/abi/sparcv9/apptrace.so.1: audit initialization failure: disabled
3:26pm up 270 day(s), 13:42, 2 users, load average: 2.08, 2.07, 2.07

Here is a hackish way to get the boot time on Solaris 10 under ksh or bash:
perl -le "print scalar localtime hex(\"$(apptrace -v getutxent uptime 2>&1 | nawk '
/ut_type:/ {if($3=="0x2"){boot=1}}
boot == 1 && $0 ~ ".*tv_sec:.*" {sub("0x","",$3);print $3;exit}')\")"
Note that you need to be root to run it on Solaris 10 but not on Solaris 11.
Edit:
Here is a much simpler way that doesn't requires root privileges:
perl -le "print scalar localtime $(kstat -pn system_misc -s boot_time|cut -f 2)"

Related

How can i define such a macro in spin?

I wrote the following model:
#define inc(sn)if :: sn < 255 -> sn = sn + 1; ::else -> sn = 1; fi;
#define inc_twice(sn) if :: sn+2 >255 -> sn= sn-253; ::else -> sn=sn+2; fi;
active proctype monitor()
{
byte sn = 255;
assert (inc(sn) ==1);
}
But the compiler fails as follows:
spin: test2.pml:9, Error: syntax error saw 'keyword: if' near 'if'
spin: test2.pml:9, Error: syntax error saw 'token: ::'
spin: test2.pml:9, Error: syntax error saw 'keyword: fi' near 'fi'
spin: test2.pml:11, Error: aborting (ana_stmnt)
child process exited abnormally.
How can i solve it?
I have met the same problem . And you can solve it by change your code into this :
#define inc(sn)if \\
:: sn < 255 -> sn = sn + 1 \\
::else -> sn = 1 \\
fi;
#define inc_twice(sn) if \\
:: sn+2 >255 -> sn= sn-253 \\
::else -> sn=sn+2 \\
fi;
I don't know what causes this issue, but I solve it by the above method.

use numba to speed up binary processing

I have a binary file containing information of different types. I know the types and have written a parsing script to extract the information:
import numba as nb
import numpy as np
def fread(fid, nelements, dtype):
if dtype is np.str:
dt = np.uint8 # WARNING: assuming 8-bit ASCII for np.str!
else:
dt = dtype
data_array = np.fromfile(fid, dt, nelements)
data_array.shape = (nelements, 1)
return data_array
fid = open('./binary_information.bts', 'rb');
nffc = 3
fileFmt = 'int16'
nz = fread( fid, 1, np.int32); # the number of grid points vertically, INT(4)
ny = fread( fid, 1, np.int32); # the number of grid points laterally, INT(4)
nPts = ny*nz;
nv = nffc*nPts; # the size of one time step
velocity = np.zeros([int(s) for s in (nt,nffc,ny,nz)])
for it in range(1, nt):
ip = 1
v_cnt = fread( fid, int(nv), fileFmt )
for iz in range(1, nz):
for iy in range(1, ny):
for k in range(1, nffc):
velocity[it,k,iy,iz] = ( v_cnt[ip] - Voffset[k])/Vslope[k]
ip = ip + 1
My for loop takes a large amount of time. I want to speed it up with numba. I tried to do this, and got a weird error, posted below. Is there any way I can speed up this reading process with numba? What went wrong here? Why is it raising this range issue?
#nb.jit(nopython=True)
def main(velocity, v_cnt):
ip = 1
for iz in xrange(1, nz):
for iy in xrange(1, ny):
for k in xrange(1, nffc):
velocity[it,k,iy,iz] = ( v_cnt[ip] - Voffset[k])/Vslope[k]
ip = ip + 1
return velocity
for it in range(nt):
ip = 0
v_cnt = fread( fid, int(nv), fileFmt )
velocity = main(velocity, v_cnt)
Traceback (most recent call last):
File "bts_read.py", line 66, in <module>
velocity = main(velocity, v_cnt)
File "/usr/local/lib/python2.7/site-packages/numba/dispatcher.py", line 330, in _compile_for_args
raise e
numba.errors.TypingError: Caused By:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/numba/compiler.py", line 235, in run
stage()
File "/usr/local/lib/python2.7/site-packages/numba/compiler.py", line 449, in stage_nopython_frontend
self.locals)
File "/usr/local/lib/python2.7/site-packages/numba/compiler.py", line 805, in type_inference_stage
infer.propagate()
File "/usr/local/lib/python2.7/site-packages/numba/typeinfer.py", line 767, in propagate
raise errors[0]
TypingError: Invalid usage of Function(<built-in function range>) with parameters (int64, readonly array(int32, 2d, C))
Known signatures:
* (int32,) -> range_state_int32
* (int32, int32) -> range_state_int32
* (int32, int32, int32) -> range_state_int32
* (int64,) -> range_state_int64
* (int64, int64) -> range_state_int64
* (int64, int64, int64) -> range_state_int64
* (uint64,) -> range_state_uint64
* (uint64, uint64) -> range_state_uint64
* (uint64, uint64, uint64) -> range_state_uint64
File "bts_read.py", line 56
[1] During: resolving callee type: Function(<built-in function range>)
[2] During: typing of call at bts_read.py (56)
Failed at nopython (nopython frontend)
Invalid usage of Function(<built-in function range>) with parameters (int64, readonly array(int32, 2d, C))
Known signatures:
* (int32,) -> range_state_int32
* (int32, int32) -> range_state_int32
* (int32, int32, int32) -> range_state_int32
* (int64,) -> range_state_int64
* (int64, int64) -> range_state_int64
* (int64, int64, int64) -> range_state_int64
* (uint64,) -> range_state_uint64
* (uint64, uint64) -> range_state_uint64
* (uint64, uint64, uint64) -> range_state_uint64
File "bts_read.py", line 56
[1] During: resolving callee type: Function(<built-in function range>)
[2] During: typing of call at bts_read.py (56)

Java 8 LocalDateTime round to next X minutes

I want to convert Java 8 LocalDateTime to nearest 5 minutes. E.g.
1601 -> 1605
1602 -> 1605
1603 -> 1605
1604 -> 1605
1605 -> 1605
1606 -> 1610
1607 -> 1610
1608 -> 1610
1609 -> 1610
1610 -> 1610
I would like to use existing functionality of LocalDateTime or Math api. Any suggestions?
You can round towards the next multiple of five minutes using:
LocalDateTime dt = …
dt = dt.withSecond(0).withNano(0).plusMinutes((65-dt.getMinute())%5);
You can reproduce your example using
LocalDateTime dt=LocalDateTime.now().withHour(16).withSecond(0).withNano(0);
for(int i=1; i<=10; i++) {
dt=dt.withMinute(i);
System.out.printf("%02d%02d -> ", dt.getHour(), dt.getMinute());
// the rounding step:
dt=dt.plusMinutes((65-dt.getMinute())%5);
System.out.printf("%02d%02d%n", dt.getHour(), dt.getMinute());
}
→
1601 -> 1605
1602 -> 1605
1603 -> 1605
1604 -> 1605
1605 -> 1605
1606 -> 1610
1607 -> 1610
1608 -> 1610
1609 -> 1610
1610 -> 1610
(in this example, I clear the seconds and nanos only once as they stay zero).
Alternatively to what Holger suggests, you can create a TemporalAdjuster, which will allow you to write something like date.with(nextOrSameMinutes(5)):
public static void main(String[] args) {
for (int i = 0; i <= 10; i++) {
LocalDateTime d = LocalDateTime.of(LocalDate.now(), LocalTime.of(16, i, 0));
LocalDateTime nearest5 = d.with(nextOrSameMinutes(5));
System.out.println(d.toLocalTime() + " -> " + nearest5.toLocalTime());
}
}
public static TemporalAdjuster nextOrSameMinutes(int minutes) {
return temporal -> {
int minute = temporal.get(ChronoField.MINUTE_OF_HOUR);
int nearestMinute = (int) Math.ceil(1d * minute / minutes) * minutes;
int adjustBy = nearestMinute - minute;
return temporal.plus(adjustBy, ChronoUnit.MINUTES);
};
}
Note that this doesn't truncate the seconds/nanos from the original date. If you want that, you can amend the end of the adjuster to:
if (adjustBy == 0
&& (temporal.get(ChronoField.SECOND_OF_MINUTE) > 0 || temporal.get(ChronoField.NANO_OF_SECOND) > 0)) {
adjustBy += 5;
}
return temporal.plus(adjustBy, ChronoUnit.MINUTES)
.with(ChronoField.SECOND_OF_MINUTE, 0)
.with(ChronoField.NANO_OF_SECOND, 0);

To match multiple lines of the snmpwalk result

Below is the snmpwalk command which I am issuing, and the result whatever it displayed, is what I have to match.
When I tried to store the result in an array and then try to match it din't work.
It goes like this:
snmpwalk -mALL -v2c -cpublic 10.126.143.249 ifname **=====>command which i issue**
This is the result it gives (which I have to match)
IF-MIB::ifName.2 = STRING: port ethernet 1/1
IF-MIB::ifName.3 = STRING: port ethernet 1/2
IF-MIB::ifName.67108865 = STRING: SKB
IF-MIB::ifName.67108866 = STRING: i1
IF-MIB::ifName.134217732 = STRING: LINK
IF-MIB::ifName.134217735 = STRING: port ethernet 1/1 dot1q pvc 200 1/2/7
===========================================================================================
Below is the code i tried : sub snmpwalk_ifName() {
my $rs;
my #array=("IF-MIB::ifName.* = STRING: port ethernet *
IF-MIB::ifName.* = STRING: port ethernet *
IF-MIB::ifName.* = STRING: SKB
IF-MIB::ifName.* = STRING: i1
IF-MIB::ifName.* = STRING: LINK
IF-MIB::ifName.* = STRING: port ethernet * dot1q pvc 200 *");
my %out= $::device2->send_cmds("snmpwalk -mALL -v2c -cpublic $::DEVICE1{ADMIN_IP} ifname");
$rs = Match::Match_Output (
OUTPUT => $out{OUTPUT},
EXP_RESULT => #array);
$::test->checkPoint( RESULT => $rs,
MSG => "CHECKPOINT for verifying snmpwalk output");
}
Not sure what you are trying to match but here is a oneliner to hopefully get you thinking (and it is fun to play):
Initial output:
snmpwalk -mALL -v2c -c lab 192.168.1.65 ifname ~
IF-MIB::ifName.4 = STRING: lsi
IF-MIB::ifName.5 = STRING: dsc
IF-MIB::ifName.6 = STRING: lo0
IF-MIB::ifName.7 = STRING: tap
IF-MIB::ifName.8 = STRING: gre
IF-MIB::ifName.9 = STRING: ipip
IF-MIB::ifName.10 = STRING: pime
IF-MIB::ifName.11 = STRING: pimd
IF-MIB::ifName.12 = STRING: mtun
IF-MIB::ifName.16 = STRING: lo0.0
IF-MIB::ifName.21 = STRING: lo0.16384
IF-MIB::ifName.22 = STRING: lo0.16385
IF-MIB::ifName.248 = STRING: lo0.32768
IF-MIB::ifName.501 = STRING: pp0
IF-MIB::ifName.502 = STRING: st0
IF-MIB::ifName.503 = STRING: ppd0
IF-MIB::ifName.504 = STRING: ppe0
IF-MIB::ifName.505 = STRING: vlan
IF-MIB::ifName.506 = STRING: ge-0/0/0
IF-MIB::ifName.507 = STRING: ge-0/0/1
IF-MIB::ifName.508 = STRING: ge-0/0/0.0
IF-MIB::ifName.509 = STRING: sp-0/0/0
IF-MIB::ifName.510 = STRING: sp-0/0/0.0
IF-MIB::ifName.511 = STRING: gr-0/0/0
IF-MIB::ifName.512 = STRING: sp-0/0/0.16383
IF-MIB::ifName.513 = STRING: ip-0/0/0
IF-MIB::ifName.514 = STRING: lsq-0/0/0
IF-MIB::ifName.515 = STRING: mt-0/0/0
IF-MIB::ifName.516 = STRING: lt-0/0/0
IF-MIB::ifName.517 = STRING: ge-0/0/1.0
IF-MIB::ifName.518 = STRING: ge-0/0/2
IF-MIB::ifName.519 = STRING: ge-0/0/2.0
IF-MIB::ifName.520 = STRING: ge-0/0/3
IF-MIB::ifName.521 = STRING: ge-0/0/4
IF-MIB::ifName.522 = STRING: ge-0/0/3.0
Put the interface name into an array with a one liner:
snmpwalk -mALL -v2c -c lab 192.168.1.65 ifname | \
perl -wnE 'push #each_line,(split " ",$_)[-1];END {say $_ for #each_line}'
Output:
lsi
dsc
lo0
tap
gre
ipip
pime
pimd
mtun
lo0.0
lo0.16384
lo0.16385
lo0.32768
pp0
st0
ppd0
ppe0
vlan
ge-0/0/0
ge-0/0/1
ge-0/0/0.0
sp-0/0/0
sp-0/0/0.0
gr-0/0/0
sp-0/0/0.16383
ip-0/0/0
lsq-0/0/0
mt-0/0/0
lt-0/0/0
ge-0/0/1.0
ge-0/0/2
ge-0/0/2.0
ge-0/0/3
ge-0/0/4
ge-0/0/3.0
Or Index + name:
snmpwalk -mALL -v2c -c lab 192.168.1.65 ifname |
perl -wnE 'say "index = $1 , Int Name = $2" if /ifName\.(\d+).*?:\s(.*)/'
Output:
index = 4 , Int Name = lsi
index = 5 , Int Name = dsc
index = 6 , Int Name = lo0
index = 7 , Int Name = tap
index = 8 , Int Name = gre
index = 9 , Int Name = ipip
index = 10 , Int Name = pime
index = 11 , Int Name = pimd
index = 12 , Int Name = mtun
index = 16 , Int Name = lo0.0
index = 21 , Int Name = lo0.16384
index = 22 , Int Name = lo0.16385
index = 248 , Int Name = lo0.32768
index = 501 , Int Name = pp0
index = 502 , Int Name = st0
index = 503 , Int Name = ppd0
index = 504 , Int Name = ppe0
index = 505 , Int Name = vlan
index = 506 , Int Name = ge-0/0/0
index = 507 , Int Name = ge-0/0/1
index = 508 , Int Name = ge-0/0/0.0
index = 509 , Int Name = sp-0/0/0
index = 510 , Int Name = sp-0/0/0.0
index = 511 , Int Name = gr-0/0/0
index = 512 , Int Name = sp-0/0/0.16383
index = 513 , Int Name = ip-0/0/0
index = 514 , Int Name = lsq-0/0/0
index = 515 , Int Name = mt-0/0/0
index = 516 , Int Name = lt-0/0/0
index = 517 , Int Name = ge-0/0/1.0
index = 518 , Int Name = ge-0/0/2
index = 519 , Int Name = ge-0/0/2.0
index = 520 , Int Name = ge-0/0/3
index = 521 , Int Name = ge-0/0/4
index = 522 , Int Name = ge-0/0/3.0
Anyways, perl is great for cool quick oneliner parsing.

Convert timestamp to datetime in erlang

How can I convert a timestamp (number of milliseconds since 1 Jan 1970..., aka epoch) to Date or DateTime format in Erlang? Something like {Year,Month,Day}.
Roughly:
msToDate(Milliseconds) ->
BaseDate = calendar:datetime_to_gregorian_seconds({{1970,1,1},{0,0,0}}),
Seconds = BaseDate + (Milliseconds div 1000),
{ Date,_Time} = calendar:gregorian_seconds_to_datetime(Seconds),
Date.
It just so happens that I have a github gist with a bunch of datetime utilities for exactly this purpose: http://gist.github.com/104903. Calendar has most of the low level plumbing for this stuff.
-module(date_util).
-compile(export_all).
epoch() ->
now_to_seconds(now())
.
epoch_hires() ->
now_to_seconds_hires(now())
.
now_to_seconds({Mega, Sec, _}) ->
(Mega * 1000000) + Sec
.
now_to_milliseconds({Mega, Sec, Micro}) ->
now_to_seconds({Mega, Sec, Micro}) * 1000
.
now_to_seconds_hires({Mega, Sec, Micro}) ->
now_to_seconds({Mega, Sec, Micro}) + (Micro / 1000000)
.
now_to_milliseconds_hires({Mega, Sec, Micro}) ->
now_to_seconds_hires({Mega, Sec, Micro}) * 1000
.
epoch_gregorian_seconds() ->
calendar:datetime_to_gregorian_seconds({{1970,1,1}, {0,0,0}})
.
now_to_gregorian_seconds() ->
epoch_to_gregorian_seconds(now())
.
epoch_to_gregorian_seconds({Mega, Sec, Micro}) ->
epoch_to_gregorian_seconds(now_to_seconds({Mega, Sec, Micro}));
epoch_to_gregorian_seconds(Now) ->
EpochSecs = epoch_gregorian_seconds()
, Now + EpochSecs
.
gregorian_seconds_to_epoch(Secs) ->
EpochSecs = epoch_gregorian_seconds()
, Secs - EpochSecs
.
date_to_epoch(Date) ->
datetime_to_epoch({Date, {0,0,0} })
.
datetime_to_epoch({Date, Time}) ->
gregorian_seconds_to_epoch(
calendar:datetime_to_gregorian_seconds({Date, Time}))
.
is_older_by(T1, T2, {days, N}) ->
N1 = day_difference(T1, T2)
, case N1 of
N2 when (-N < N2) ->
true;
_ ->
false
end
.
is_sooner_by(T1, T2, {days, N}) ->
case day_difference(T1, T2) of
N1 when N > N1 ->
true;
_ ->
false
end
.
is_time_older_than({Date, Time}, Mark) ->
is_time_older_than(calendar:datetime_to_gregorian_seconds({Date, Time})
, Mark);
is_time_older_than(Time, {DateMark, TimeMark}) ->
is_time_older_than(Time
, calendar:datetime_to_gregorian_seconds({DateMark, TimeMark}));
is_time_older_than(Time, Mark) when is_integer(Time), is_integer(Mark) ->
Time < Mark
.
day_difference({D1, _}, D2) ->
day_difference(D1, D2);
day_difference(D1, {D2, _}) ->
day_difference(D1, D2);
day_difference(D1, D2) ->
Days1 = calendar:date_to_gregorian_days(D1)
, Days2 = calendar:date_to_gregorian_days(D2)
, Days1 - Days2
.
is_time_sooner_than({Date, Time}, Mark) ->
is_time_sooner_than(calendar:datetime_to_gregorian_seconds({Date, Time})
, Mark);
is_time_sooner_than(Time, {DateMark, TimeMark}) ->
is_time_sooner_than(Time
, calendar:datetime_to_gregorian_seconds({DateMark, TimeMark}));
is_time_sooner_than(Time, Mark) when is_integer(Time), is_integer(Mark) ->
Time > Mark
.
subtract(Date, {days, N}) ->
New = calendar:date_to_gregorian_days(Date) - N
, calendar:gregorian_days_to_date(New)
.
add(Date, {days, N}) ->
New = calendar:date_to_gregorian_days(Date) + N
, calendar:gregorian_days_to_date(New)
.
OTP 21.0 added this function
calendar:system_time_to_universal_time(Time, TimeUnit) -> datetime()
Types
Time = integer()
TimeUnit = erlang:time_unit()
Converts a specified system time into universal date and time.
Example:
> os:system_time(1000).
1598512151718
> calendar:system_time_to_universal_time(1598512151718, 1000).
{{2020,8,27},{7,9,11}}
Refrence: https://erlang.org/doc/man/calendar.html#system_time_to_universal_time-2