Check if time format is valid


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Check if time format is valid
# 8  
Old 10-20-2015
Are you sure above will match e.g. 15:10:10?
# 9  
Old 10-20-2015
Quote:
Originally Posted by RudiC
Are you sure above will match e.g. 15:10:10?
Yeah, i figured that when i was testing it thoroughly.
# 10  
Old 10-20-2015
That awk statement can be simplified:
Code:
echo $1 | awk '/([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]/{print "good";exit 0} {print "bad";exit 1}'

but there is no need to fire up awk for this at all:
Code:
#!/bin/ksh
case "$1" in
([01][0-9]:[0-5][0-9]:[0-5][0-9]|2[0-3]:[0-5][0-9]:[0-5][0-9])
	echo okay;;
(*)	echo invalid
	exit 1;;
esac
echo 'Continuing in script after time verification.'

This User Gave Thanks to Don Cragun For This Post:
# 11  
Old 10-21-2015
Quote:
Originally Posted by Don Cragun
That awk statement can be simplified:
Code:
echo $1 | awk '/([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]/{print "good";exit 0} {print "bad";exit 1}'

but there is no need to fire up awk for this at all:
Code:
#!/bin/ksh
case "$1" in
([01][0-9]:[0-5][0-9]:[0-5][0-9]|2[0-3]:[0-5][0-9]:[0-5][0-9])
    echo okay;;
(*)    echo invalid
    exit 1;;
esac
echo 'Continuing in script after time verification.'

Thanks!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Valid separator in time and date format

Hello. I can use any particular (stupid or not) format when using bash date command. Example : ~> date --date "now" '+%Y-%m-%d %H!%M!%S' 2019-06-03 12!55!33or ~> date --date "now" '+%Y£%m£%d %H¤%M¤%S' 2019£06£03 12¤57¤36 or ~> date --date "now" '+%Y-%m-%d %H-%M-%S' 2019-06-03 12-58-51 ... (4 Replies)
Discussion started by: jcdole
4 Replies

2. Shell Programming and Scripting

Bash script accepting variables in valid number format

Hi Experts I would like to ask if there is a way to validate if the variable passed is in this kind of sample format "06-10" or "10-01". It was really a challenge to me on how to start and echnically the "6-10" stands for "June 10" and "10-01" stands as "October 1", overall it needs to have ... (3 Replies)
Discussion started by: ersan-poguita
3 Replies

3. Shell Programming and Scripting

Check for valid hostnames

Hello, I am trying to develop a script to check for valid hostnames. Below are the prerequisites for a valid hostname which I got from wiki : Hostnames are composed of series of labels concatenated with dots, as are all domain names. For example, "en.wikipedia.org" is a hostname. Each label... (8 Replies)
Discussion started by: rahul2662
8 Replies

4. UNIX for Dummies Questions & Answers

How to check if file contains valid strings?

Hi All, I am a newbie...I would like to have a function which ll check if a file contains valid strings before "=" operator. Just to give you my requirement: assume my file has content: hello= gsdgsd sfdsg sgdsg sgdgdg world= gggg hhhh iiiii xxxx= pppp ppppp pppp my... (5 Replies)
Discussion started by: rtagarra
5 Replies

5. Shell Programming and Scripting

how to check for valid password

I need to check if an account has a valid password. Would something like this work? read ACCNAME if grep -q "^$ACCNAME:\$6:" /etc/shadow; thenI noticed every entry in my shadow file that has a password starts with $6 ... it works for my current setup, but would it always work? I can't test... (4 Replies)
Discussion started by: ADay2Long
4 Replies

6. Homework & Coursework Questions

Bash shell - Check if value is valid directory.

1. The problem statement, all variables and given/known data: The script usage will be as follows: library.third source_directory - Your script will display an appropriate error message and exit with status 3 if no parameters are given - Your script will display an appropriate error... (2 Replies)
Discussion started by: netmaster
2 Replies

7. Shell Programming and Scripting

How create function valid birthday format dd-mm-yyyy

I write a small shell script create Payroll System my trouble is valid format birthday dd-mm-yyyy when you enter birthday if your value enter not match with format dd-mm-yyyy system will display "Fail Format Please re-enter Birthday with format dd-mm-yyyy" but i don't know how create function... (3 Replies)
Discussion started by: kency
3 Replies

8. Shell Programming and Scripting

to check whether a directory or filename path is valid or not

the script on excution should take a directory path from useran a numric input and it should check indicate whether its write or not? if the cmmd sh<script-name>,dir/path.<500>" is greater than 500 in size should be copied to dir ,temp in pwd and display the mesage'files of 2000 bytes hav been... (4 Replies)
Discussion started by: arukr
4 Replies

9. Shell Programming and Scripting

Convert Epoch time format to normal date time format in the same file

I have a file named "suspected" with series of line like these : {'protocol': 17, 'service': 'BitTorrent KRPC', 'server': '219.78.120.166', 'client_port': 52044, 'client': '10.64.68.44', 'server_port': 8291, 'time': 1226506312L, 'serverhostname': ''} {'protocol': 17, 'service': 'BitTorrent... (3 Replies)
Discussion started by: rk4k
3 Replies

10. Shell Programming and Scripting

How to check for a valid numeric input

Hi Folks, I'm using bash script. I would like to check whether input is a number or not.(Only positive numbers).. if space or non numeric is entered, it should say "invalid input". pls help.. thanks in adv. Br/// Vijay. (1 Reply)
Discussion started by: Vijayakumarpc
1 Replies
Login or Register to Ask a Question