Checking numeric expression in .ksh script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Checking numeric expression in .ksh script
# 1  
Old 02-16-2015
Checking numeric expression in .ksh script

Gurus, Please need your help.

I'm saving a filetimestamp into $filetimestamp and
say....echo $filetimestamp gives 2015021612

I'm saving a cutoff_time into $cutoff_time
say....echo $cutoff_time gives 2015021514

now my requirement is to check if $filetimestamp is greater than $cutoff_time then we say "File to be zipped" else "The file does not exist".
This is how I coded.

Code:
if (( $filetimestamp -gt $cutoff_time ))
then
   echo "File to be zipped ",$file_name
else 
echo "The file does not exist"
exit
fi

Please correct me where I'm doing mistake as it is giving syntax error.



Thanks,
Srini

Last edited by Scrutinizer; 02-16-2015 at 12:11 PM.. Reason: code tags
# 2  
Old 02-16-2015
GNU find:
Code:
find /dir -cnewer cutoff.file


Last edited by Scrutinizer; 02-16-2015 at 03:44 PM.. Reason: code tags
# 3  
Old 02-16-2015
Try:
Code:
if ((filetimestamp > cutoff_time))
then
...

# 4  
Old 02-16-2015
Hi,
How to get filetimestamp if file doesn't exist ?

Regards.
# 5  
Old 02-16-2015
Quote:
Originally Posted by disedorgue
Hi,
How to get filetimestamp if file doesn't exist ?
logic error in your question.
This User Gave Thanks to agent.kgb For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Checking ksh script syntax

To check a bash script syntax without executing it we use: bash -n scriptname What should be the equivalent command for checking a ksh script? (8 Replies)
Discussion started by: proactiveaditya
8 Replies

2. Shell Programming and Scripting

regular expression in ksh

I am trying to test to see if the hostname of the computer I'm on starts with ne1dxdb - it can contain any characters after that. I have the following code, but it's not working - it's not falling into the if statement. Any ideas? boxname="unknown" function get_hosttype { ... (4 Replies)
Discussion started by: kittsi
4 Replies

3. Shell Programming and Scripting

Checking input for being numeric and integers

Hi, I'm trying to check to see that the arguments given to my script are both numeric and positive integers. I'm using tcsh. I figured out the positive part, but I am having trouble with the arguments being numeric and integers I have no idea where to get started with the checking them actually... (1 Reply)
Discussion started by: mistykz
1 Replies

4. UNIX for Dummies Questions & Answers

Ksh How to test if variable is numeric??

I'm trying to test and see whether a variable that is being extracted from a line in a file is numeric or not. I have tried everything that I can think of and I cannot figure out how to get it to work. I am trying to test and see if the string extracted contains 5 numeric digits. This is what I... (8 Replies)
Discussion started by: developncode
8 Replies

5. Shell Programming and Scripting

checking variable has value - ksh

hi all, i have a shell (ksh) script where i am reading line by line from a grep command and i wanted to check if the grep command actually returned something or was null. i can do this by using -z : if ; then ..... but this forces me to do something when $myVariable is null when i... (3 Replies)
Discussion started by: cesarNZ
3 Replies

6. UNIX for Dummies Questions & Answers

KSH Checking Previous Date**

How would I go about getting the previous date on the server? I'm out of ideas...I am thinking that I could do it using the date command, but I am unable to find any information on doing it. For example if the current date is April 17th 2008 it would be (20080417) <- (YYYYMMDD). I need the previous... (4 Replies)
Discussion started by: developncode
4 Replies

7. UNIX for Dummies Questions & Answers

ksh Checking if variable has 5 digits

How could I check if a numeric variable has 5 digits in KSH...I have a zipcode variable that I know will always be 5 digits, and I want to print out an error if it is less or more than 5 digits the problem is that I have it as: if ] but this won't work because the statement doesn't see 0001 as... (3 Replies)
Discussion started by: developncode
3 Replies

8. UNIX for Dummies Questions & Answers

Ksh Checking if string has 2 characters and does not contain digits?

How could I check if a string variable contains at least (or only) 2 characters, and check and make sure that the string does not contain any numeric digits?...I need to know how to do this as simple as possible. and I am using the Ksh shell. Thanks. (1 Reply)
Discussion started by: developncode
1 Replies

9. Shell Programming and Scripting

Checking numeric value

Hi, How can I check numeric value in shell? I am passing one parameter (integer) and I want to restrict any other characters except 0-9. ./script xyz 10 Here 2nd parameter (10) should be integer only. Can anyone help on this? Malay (6 Replies)
Discussion started by: malaymaru
6 Replies

10. Shell Programming and Scripting

KSH Expression

Quick question related to KSH expressions (not unix regular expressions). I am trying to craft a pattern that will correctly identify lines that match the following CSV text in a case statement: filename.txt, filename.txt, alpha, nnnn, nnnn, nnnn, Free form text Originally I simply used... (4 Replies)
Discussion started by: tmarikle
4 Replies
Login or Register to Ask a Question