How to Validate

Login or Register for Dates, Times and to Reply

Thread Tools Search this Thread
# 8  
Ghost Thanks for your quick response !!
Now I am using that date with in my script
echo -n "Enter Time schedule in the following format [HH:MM],[HH:MM],..:"
read Ext_Sch
date -d $Ext_Sch
count=`echo $?`
if [ $count -eq 0 ]
echo Valid
echo Wrong
[Sanjaytmp]$ sh
Enter Time schedule in the following format [HH:MM],[HH:MM],..:28:33
date: invalid date `28:33'
[Sanjaytmp]$Enter Time schedule in the following format [HH:MM],[HH:MM],..:23:45
Thu Sep 27 23:45:00 IST 2007

Here I am getting the message in my output(show in bold letter) as well that I dun want.
Could you help me how I will ignore it.

# 9  
Perhaps something like this.

[/tmp]$ cat try.ksh
#! /bin/ksh


echo $str | tr ',' '\n' | while IFS=: read hour min
    if [[ $hour = *[:alpha:]* ]] ; then
        echo "$hour:$min is invalid"
    elif [[ $hour -lt 0 || $hour -gt 23 || $min -lt 0 || $min -gt 60 ]] ; then
        echo "$hour:$min is wrong"
        echo $hour:$min
[/tmp]$ ./try.ksh
a:23 is invalid
25:67 is wrong

# 10  
Originally Posted by SanjayLinux
Could you help me how I will ignore it.
# date -d "18:99" > /dev/null 2>&1
# echo $?

# 11  
Bingo !!!! Smilie

Ghost It wokring for me perfect ...
Thanks a lot !!

Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #883
Difficulty: Easy
A computer security vulnerability is a weakness in design, implementation, operation or internal control.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Please help me validate script

Hi Guys, Im a newbie to scripting and have a small assignment. can someone please confirm if the script i have written would work fine as we dont have a test server to test :( Scenario - copy 2 files from an ftp server (windows) to a linux machine (a perticular folder). run 2 different... (0 Replies)
Discussion started by: nishantvshah
0 Replies

2. Shell Programming and Scripting

validate timestamp

How to validate the user supplied timestamp? Ther requirement is as follows. While invoking the script, the parameters passed to the script are minimum and maixmum timestamps. let's say min_tstmp and max_tstmp ksh abc.ksh 2011-09-01-00:00:00 2011-12-01-00:00:00 so... (3 Replies)
Discussion started by: kmanivan82
3 Replies

3. Shell Programming and Scripting

Need to validate that all 24 hr are in a table

I have a table that looks like this, but for a whole year: Hourly weather history for XXX 7 Jun 0:00 Clear weather 28 1:00 Clear weather 23 2:00 Clear weather 21 3:00 Clear weather 22 4:00 Clear weather 22 5:00 Clear weather 22 6:00 Clear weather 23 7:00 Clear... (12 Replies)
Discussion started by: paulyester
12 Replies

4. Shell Programming and Scripting

Validate and Calculate

Hi, i am trying to validate 2 variables and then subtract, the following code works well in AiX but when i try in Solaris it doesnt work. ((TIME1>TIME2)) && ((TIME2=TIME2+864)) ((DIF=TIME2-TIME1)) echo difference = $DIF Seconds is there any way the validation can be done using... (2 Replies)
Discussion started by: Shellslave
2 Replies

5. Shell Programming and Scripting

validate input

the user inputs names that have to be inside square brackets I want to check if the user puts the brackets and if not ask him to re-enter the names (9 Replies)
Discussion started by: DDoS
9 Replies

6. Shell Programming and Scripting

How to validate a column?

Dear guru's, I am learning shellscripting and now I 'm struggeling with this problem: When the number in the left column is equal or higer then 200, I want to send an email to "postmaster" @ the corresponding domain in the right column. 220 217 209 ... (11 Replies)
Discussion started by: algernonz
11 Replies

7. Shell Programming and Scripting

Validate date

Hi I am beginner to UNIX. I wanted to help for how to write script to validate date. Please help me. (2 Replies)
Discussion started by: giridher2000
2 Replies

8. Shell Programming and Scripting

validate against a file

Hello all, I am having problem in writing a if condition for the following: I have a file Instance.dat which has: #Server Environment server1 dev server2 dev server3 sit #!/bin/ksh ENV=dev for i in $( cat Instances.dat | grep -v '#' |awk {'print $2'} ) do if ]... (7 Replies)
Discussion started by: chiru_h
7 Replies

9. Shell Programming and Scripting

validate the file name

write a shell script that check file name like pstat_24.txt (up to 5 digits) i mean to say this digit can be range from 1 to 99999 only correct file name are pstat_10000.txt pstat_12345.txt pstat_14569.txt wrong file name are pstat_1234567.txt pstat_1a2345.txt... (2 Replies)
Discussion started by: maykap100
2 Replies

10. Shell Programming and Scripting


hi need help here, a bit of code im doing requires a number to be enetered i have got validation and loop if its outside a ceratain range, but was wondering what code i need to validate if a character has been entered. cheers (3 Replies)
Discussion started by: ruffenator
3 Replies

Featured Tech Videos