Sponsored Content
Top Forums Shell Programming and Scripting Use of expr to calc differenc ein to epoch values Post 303016661 by jonnyd on Tuesday 1st of May 2018 07:33:55 PM
Old 05-01-2018
Use of expr to calc differenc ein to epoch values

Hi folks,

I have a script where i am trying to calc the difference between two epoch dates and then have a condition based on the resultant value.

When I run the script it keeps complaining;

Code:
expr: syntax error
./testdiff.sh: line 11: syntax error in conditional expression
./testdiff.sh: line 11: syntax error near `-a'
./testdiff.sh: line 11: `if [[ ${DATE_DIFF} -gt 4000 -a ${DATE_DIFF} -lt 6000 ]]'

Code:
#!/bin/bash

export CHECK_DATE_1=`date +%s`
export FILE1=/tmp/longrunmon.out

export DATE_DIFF=`expr ${CHECK_DATE_1} - ${INSERT_TIME}`

while IFS=, read INSTANCE SESS_COUNT INSERT_TIME
do

if [[ ${DATE_DIFF} -gt 4000 -a ${DATE_DIFF} -lt 6000 ]]
then
echo Critical Alert: $DATE_DIFF

elif [[ ${DATE_DIFF} -lt 600 ]]
then
echo Major Alert: $DATE_DIFF

#else
#echo not less than 600
#echo instance: $INSTANCE
#echo session_count: $SESS_COUNT
#echo date_diff: $DATE_DIFF
#echo insert_time: $INSERT_TIME
#echo check_date: $CHECK_DATE_1

fi
done < ${FILE1}

The content of /tmp/longrunmon.out

is;

testinst,10,1525186184


Any help much appreciated.

jd

Last edited by Scrutinizer; 05-02-2018 at 12:33 AM.. Reason: Additional code tags
 

5 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Differenc between print and echo

can anyone explain me what is the difference between echo and print in shell programming? (3 Replies)
Discussion started by: chandhar
3 Replies

2. UNIX for Dummies Questions & Answers

Differenc between ps -ef and top

First of all i really thankful to all those people who have created this site. unix.com rocks man!! I am bit confused about the two commands which are 'top' and 'ps -ef'.:confused: My requirement is that i want to monitor the CPU usage of Operating system and if the CPU usage is more than 90%... (2 Replies)
Discussion started by: Amey Joshi
2 Replies

3. Shell Programming and Scripting

test expr VS [ expr ]

What is the difference between test expr VS . For example : if test 5 -eq 6 echo "Wrong" and if echo "Wrong" bot will give the same output as Wrong. Now, what is the difference between these two? though they are producing the same result why we need two? Any answer will be... (2 Replies)
Discussion started by: ashok.g
2 Replies

4. Shell Programming and Scripting

Calc max of a column

In C that was easy with a for and if. Iam trying to learn a litle more in bash. Example Ronaldo:5800 Figo:4000 Rafael:2321 Kaka:1230 I want the max of the $2 and the output will be: The max value is 5800 from Ronaldo. How can i do this in shell? Thanks for all, folks. (11 Replies)
Discussion started by: rafazz
11 Replies

5. Shell Programming and Scripting

date calc

Hi, I need subtract two date values (which are in day of the year format) and the output would give the remaining days. using the command date +"%j" i would get today's 'day of the year' i.e., > date +"%j" 256 Next, i need to take input of a previous date in the format 09/05/2012 and then... (4 Replies)
Discussion started by: sam_bd
4 Replies
echo(3XCURSES)						  X/Open Curses Library Functions					    echo(3XCURSES)

NAME
echo, noecho - enable/disable terminal echo SYNOPSIS
cc [ flag... ] file... -I /usr/xpg4/include -L /usr/xpg4/lib -R /usr/xpg4/lib -lcurses [ library... ] c89 [ flag... ] file... -lcurses [ library... ] #include <curses.h> int echo(void); int noecho(void); DESCRIPTION
The echo() function enables Echo mode for the current screen. The noecho() function disables Echo mode for the current screen. Initially, curses software echo mode is enabled and hardware echo mode of the tty driver is disabled. The echo() and noecho() functions control soft- ware echo only. Hardware echo must remain disabled for the duration of the application, else the behavior is undefined. RETURN VALUES
Upon successful completion, these functions return OK. Otherwise, they return ERR. ERRORS
No errors are defined. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ |MT-Level |Unsafe | +-----------------------------+-----------------------------+ SEE ALSO
getch(3XCURSES), getstr(3XCURSES), initscr(3XCURSES), libcurses(3XCURSES), scanw(3XCURSES), attributes(5), standards(5) SunOS 5.11 5 Jun 2002 echo(3XCURSES)
All times are GMT -4. The time now is 11:12 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy