#!/usr/bin/env bash
# @(#) s1 Demonstrate use of c date arithmetic code tm2tm.
# See post #4 at::
# https://www.unix.com/shell-programming-scripting/
# 146216-date-difference-between-freebsd-linux.html
# Utility functions: print-as-echo, print-line-with-visual-space, debug.
# export PATH="/usr/local/bin:/usr/bin:/bin"
LC_ALL=C ; LANG=C ; export LC_ALL LANG
pe() { for _i;do printf "%s" "$_i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
db() { ( printf " db, ";for _i;do printf "%s" "$_i";done;printf "\n" ) >&2 ; }
db() { : ; }
C=$HOME/bin/context && [ -f $C ] && $C tm2tm
# Set default adjustment if not specified.
ADJUST=${1-"-5M"}
D=$( date +"%Y-%m-%d-%H.%M.%S" )
pl " Results, for tm2tm, working on $D: adjustment is $ADJUST"
pe " ( For comparison, today is $(date))"
tm2tm "$D" "%Y-%m-%d-%H.%M.%S" "$ADJUST" "%Y-%m-%d-%H.%M.%S"
exit 0
producing:
Code:
$ ./s1
Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution : Debian 5.0.8 (lenny, workstation)
bash GNU bash 3.2.39
tm2tm - ( local: ~/executable/tm2tm, 2014-06-26 )
-----
Results, for tm2tm, working on 2014-06-26-11.15.16: adjustment is -5M
( For comparison, today is Thu Jun 26 11:15:16 CDT 2014)
2014-06-26-11.10.16
and for 5 days in the future:
Code:
$ ./s1 +5D
( ... )
-----
Results, for tm2tm, working on 2014-08-03-12.45.23: adjustment is +5D
( For comparison, today is Sun Aug 3 12:45:23 CDT 2014)
2014-08-08-12.45.23
I did get a compilation error initially, and DGP suggested:
Quote:
Substitute the literal '\0' for NULL
which fixed the problem. I got a segmentation fault at least once (noted by Corona688), so I recompiled with the 32-bit option gcc -o tm2tm tm2tm.c -m32 and that seemed to avoid the segfault.
Code:
$ file tm2tm
tm2tm: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.8, not stripped
As usual YMMV; best wishes ... cheers, drl
( Edit 1: correct garbled output from 2014-06-26-11.19.53. )
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 2,288
Thanks Given: 430
Thanked 480 Times in 395 Posts
Hi, Robin.
Quote:
Originally Posted by rbatte1
Your Mileage May Vary?
Huh?
Robin
I used YMMV in this sense:
Quote:
Your mileage may vary - (Standard disclaimer attached to EPA mileage ratings by American car manufacturers) A ritual warning often found in Unix freeware distributions and elsewhere. Translates roughly as "Hey, I tried to write this portably, but who *knows* what'll happen on your system?"
Hello all,
Info:
System RedHat 7.5
I need to create a script that based on the creation time,
if the file is older then 5 minutes then execute some stuff, if not exit.
I thought to get the creation time and minutes like this.
CreationTime=$(stat -c %y /tmp/test.log | awk -F" " '{ print... (3 Replies)
Hi all,
System Ubuntu 16.04.3 LTS
i have the following log
INFO 2019-02-07 15:13:31,099 module.py:700] default: "POST /join/8550614e-3e94-4fa5-9ab2-135eefa69c1b HTTP/1.0" 500 2042
INFO 2019-02-07 15:13:31,569 module.py:700] default: "POST /join/6cb9c452-dcb1-45f3-bcca-e33f5d450105... (15 Replies)
Hi, please help with below time conversion to minutes.
one column values:
2 minutes 16 seconds 420 msec
43 seconds 750 msec
0 days 3 hours 29 minutes 58 seconds 480 msec
11 seconds 150 msec
I need output in minutes(total elapsed time in minutes) (2 Replies)
Hello,
date --date '-60 min ago' +'%Y-%m-%d %H:%M:%S,%3N'
Above command gives the date and time minus 60 minutes
but the problem i am facing is, i do not want to hardcode the value 60
it is stored in a variable var=60
now if i run below command , i get error
date --date '-$var min... (3 Replies)
Hi there,
I have a problem with arithmetic ops in awk.
Here is what my script does right now.
while read nr val ; do
case $nr in
400) awk '$2~/eigenvectors/ {print $NF-'$val'};' input.txt >> output.txt;;
esac
done < frames.txtI have a file named frames.txt with two columns (nr and... (2 Replies)
In Redhat it is easy....
date --date="60 minutes ago"
How do you do this in Solaris?
I got creative and got the epoch time but had problems..
EPOCHTIME=`truss date 2>&1 | grep "time()" | awk '{print $3 - 900}'`
echo $EPOCHTIME
TIME=`perl -e 'print scalar(localtime("$EPOCHTIME")),... (5 Replies)
Hello people,
awk '{print $0}' input1.txt input2.txt |sort -u
Will give the union of the 2 files. Similarly what is command to get just the diff data (i.e minus) of the 2 files. Can I use the "diff" command to get just the diff data.
Please let me know.
Regards,
Tipsy. (7 Replies)