Minus 5 minutes


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Minus 5 minutes
# 8  
Old 06-26-2014
Hi.

I agree. With perl available on almost all platforms, it is often the most portable.

If somewhat more flexibility in use (for date/time arithmetic) is desired, the code at https://www.unix.com/shell-programmin...bsd-linux.html by DGPickett could be used.

Here is an example:
Code:
#!/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. )

Last edited by drl; 08-03-2014 at 02:51 PM..
# 9  
Old 06-27-2014
Quote:
As usual YMMV;
Your Mileage May Vary?

Huh? Smilie


Robin
# 10  
Old 06-27-2014
Hi, Robin.
Quote:
Originally Posted by rbatte1
Your Mileage May Vary?

Huh? Smilie

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?"
-- Your mileage may vary definition of Your mileage may vary in the Free Online Encyclopedia.

I compiled and executed the code on Debian, but I didn't run it on other systems, hence
Quote:
... who *knows* what'll happen on your system? ...
It was an alternate method, suggestion, proof for something other than the perl solution.

Sometimes I do test solutions on systems that are close to the OP's system, but in cases where I don't, YMMV applies.

Best wishes ... cheers, drl
This User Gave Thanks to drl For This Post:
# 11  
Old 06-27-2014
So the same as caveat emptor then.

Thanks. I was very confused.


Robin
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check file creation Time minutes and if file older then 5 minutes execute some stuff

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)
Discussion started by: charli1
3 Replies

2. Shell Programming and Scripting

Grep a log file for the last 5 minutes of contents every 5 minutes

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)
Discussion started by: charli1
15 Replies

3. UNIX for Beginners Questions & Answers

How to convert days hours minutes seconds to minutes?

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)
Discussion started by: ramu.badugula
2 Replies

4. Shell Programming and Scripting

How to get a time minus 60 minutes?

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)
Discussion started by: Ramneekgupta91
3 Replies

5. Shell Programming and Scripting

Minus minus to plus

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)
Discussion started by: tobias1234
2 Replies

6. Solaris

How to show time minus 60 minutes?

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)
Discussion started by: s ladd
5 Replies

7. Shell Programming and Scripting

Minus of files

File 1 contains data : CALL_ID SOR_ID SEG_SEQ_NUM CHK_PNT_MENU_TYPE_CD PTNR_ID ACTVN_RTRN_CD PRIM_ACTVN_DCLN_REAS_CD SCNDRY_ACTVN_DCLN_REAS_CD ACTVN_SCCS_IND CARD_ACTVTD_IND MAX_ACTVN_FAILD_ATMP_IND EDW_PUBLN_ID File 2 contains data: PRIM_ACTVN_DCLN_REAS_CD... (3 Replies)
Discussion started by: ysvsr1
3 Replies

8. Shell Programming and Scripting

Minus of 2 files -- Please help

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)
Discussion started by: tipsy
7 Replies

9. UNIX for Dummies Questions & Answers

minus sign

why a minus sign is put for options in unix commands suggestions plz (2 Replies)
Discussion started by: trichyselva
2 Replies

10. Shell Programming and Scripting

Convert minutes to hours, minutes, seconds

How would you convert lets say a 1000 minutes to hours, minutes, seconds (1 Reply)
Discussion started by: Vozx
1 Replies
Login or Register to Ask a Question