Get the time with shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get the time with shell script
# 1  
Old 03-20-2010
Get the time with shell script

when I get time
some times it like
Code:
$hwclock -r
Mon 07 Jul 2008 20:01:48 PM GMT  -0.486264 seconds

some times it like
Code:
$hwclock -r
Mon Jul  7 20:01:48 2008  -0.547393 seconds

the sequence is not the same all the time and I just want to use "hwclock" not "date" to get time

I want just get 200148, how to get it.

Last edited by yanglei_fage; 03-20-2010 at 11:54 AM..
# 2  
Old 03-20-2010
Code:
 date +%H%M%S

# 3  
Old 03-20-2010
Quote:
Originally Posted by jim mcnamara
Code:
 date +%H%M%S

nonono ,I just want to use hwclock -r to get
# 4  
Old 03-20-2010
Code:
hwclock -r |  awk '{ if($5 ~/:/ ) {print $5} else {print $4} }'

Consider reading the man page for hwclock and date.
# 5  
Old 03-20-2010
Quote:
Originally Posted by jim mcnamara
Code:
hwclock -r |  awk '{ if($5 ~/:/ ) {print $5} else {print $4} }'

Consider reading the man page for hwclock and date.
not very good, if the time not just to row 4 or row 5
# 6  
Old 03-20-2010
I don't usualy argue with posters, but:
the the date command is identical to hwclock -r -- per the manpage for hwclock

So what you are doing is demonstrating that you have not bothered to read documentation and then complaining because you don't understand. I'm not answering any more - find some else to complain to.
# 7  
Old 03-20-2010
Quote:
Originally Posted by yanglei_fage
not very good, if the time not just to row 4 or row 5
You gave two data samples and they did indeed have the time as either the 4th or 5th word. If other permutations are possible, you should make that clear.

Code:
sed 's/.*\(..\):\(..\):\(..\).*/\1\2\3/'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Shell Script to run in given time

Hi All, Would like to write a Script which will run between 11am to 3 pm and send the results to output.txt. Please suggest. (2 Replies)
Discussion started by: vasuvv
2 Replies

2. Shell Programming and Scripting

Capture run time of python script executed inside shell script

I have bash shell script which is internally calling python script.I would like to know how long python is taking to execute.I am not allowed to do changes in python script.Please note i need to know execution time of python script which is getting executed inside shell .I need to store execution... (2 Replies)
Discussion started by: Adfire
2 Replies

3. Shell Programming and Scripting

Terminate shell script after a specified time

I have a shell script that checks a file state.txt, deletes fit.bin if state.txt is empty. I cron this at 2am, I will want the script to stop by 8am irrespective of the value of state.txt, any ideas? #!/usr/bin/ksh while true; do if ] ; then echo else rm ~/fit.bin exit ... (8 Replies)
Discussion started by: aydj
8 Replies

4. Shell Programming and Scripting

Date and Time comparison using shell script

Hi, I'm having two fields in the file F1|F2 20111220|102000 F1 ->YYYYMMDD F2 ->HHMMSS Now, I need to compare this with current date & time and need to return the difference value in hours. Already, I checked with datecalc from the forum. So, need hints from Shell Gurus. Thanks (10 Replies)
Discussion started by: buzzusa
10 Replies

5. Shell Programming and Scripting

Shell script to convert epoch time to real time

Dear experts, I have an epoch time input file such as : - 1302451209564 1302483698948 1302485231072 1302490805383 1302519244700 1302492787481 1302505299145 1302506557022 1302532112140 1302501033105 1302511536485 1302512669550 I need the epoch time above to be converted into real... (4 Replies)
Discussion started by: aismann
4 Replies

6. Shell Programming and Scripting

Time Diff in shell script

Hi all , i am trying to calculate time difference btw the script execution I am using solaris start_time=`date +%s` sleep 2 end_time=`date +%s` duration=`expr $end_time - $start_time` when i try to subtract i get the error line 13: %s - -time : syntax error: operand expected... (3 Replies)
Discussion started by: posner
3 Replies

7. Shell Programming and Scripting

Time Manipulation in shell script

Hi all, I have a script that requires time comparisons and sending out an email alert only if the specified interval has been completed. The script runs in Cron tab every 5 mins. For ex: If the interval is set to 2 hrs (Dynamic & varies ) My script should execute and if it finds any error... (1 Reply)
Discussion started by: praseecg
1 Replies

8. Solaris

epoch time in shell script

how can I get the current standard epoch time (seconds from 1970) in a shell script? I know I could do this with a bit of perl of even c++ but i want to do it in Bourne shell..... (14 Replies)
Discussion started by: robsonde
14 Replies

9. Shell Programming and Scripting

Help with time comparison shell script for HP-UX

I am using Korne Shell in HP-Ux. Can someone give me and idea on how I can write a shellscript on how to do this please:- On our HP-UX server, a batch file is run every evening at about 6:30pm. The first step of this batch file will touch an empty "flag" file to indicate that the batch has... (6 Replies)
Discussion started by: gummysweets
6 Replies

10. Shell Programming and Scripting

C shell script for time matching

Write a C shell script called greetings which will print out one of Good morning, Good afternoon or Good evening depending on the time of day. . (1 Reply)
Discussion started by: Ringo
1 Replies
Login or Register to Ask a Question