The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Convert date to unix time funksen Shell Programming and Scripting 4 03-23-2009 06:34 AM
Convert Epoch Time to Standard Date and Time & Vice Versa DrivesMeCrazy Shell Programming and Scripting 5 02-07-2009 01:40 AM
Convert Epoch time format to normal date time format in the same file rk4k Shell Programming and Scripting 3 11-19-2008 10:04 PM
Convert milliseconds to standard time chiru_h Shell Programming and Scripting 1 07-19-2007 02:45 PM
Convert from standard epoch time from a shell script? LordJezo Shell Programming and Scripting 4 09-19-2005 12:48 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-22-2009
mrlayance mrlayance is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 20
Convert Unix Time to Standard Time

I have a list of interfaces and time the interface was last active. I can't figure out how to convert the time in the second column,

PHP Code:
Fa1/14 0
Se0
/0/0 0
Fa1
/11 0
Fa1
/9 0
Fa1
/0 0
Se0
/0/1 1240401408
Gi1
/0 0
Fa0
/0 1240401408
Fa1
/3 0
Fa1
/8 0
Fa1
/15 0
Fa1
/13 0
Fa1
/10 0
Fa1
/1 0
Fa1
/12 1240401408
Fa0
/1 1240401408
Fa1
/5 1240401408
Fa1
/6 0
Se0
/0/0.1 0
Fa1
/7 0
Fa1
/2 0
Lo0 0
Fa1
/4 1240401408 
Can this be done with shell?
  #2 (permalink)  
Old 04-22-2009
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,128
many ways to skin that cat.
if you're Solaris:
Code:
#!/bin/ksh

file='interfaces.txt'

while read inter time
do
   printf "%s %s\n" "${inter}" "$(echo "0t${time}=Y" | /usr/bin/adb)"
done < "${file}"
  #3 (permalink)  
Old 04-22-2009
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Wink This works, although not sure what you want to do with the 0 (ZERO) values

The zero values give an unusual (although technically correct) answer.

Code:
> cat proc13.sh
#/usr/bin/bash

while read param etime
   do
   echo $param $(date '+%Y-%m-%d' -d @$etime)
done <file13

> proc13.sh
Fa1/14 1969-12-31
Se0/0/0 1969-12-31
Fa1/11 1969-12-31
Fa1/9 1969-12-31
Fa1/0 1969-12-31
Se0/0/1 2009-04-22
Gi1/0 1969-12-31
Fa0/0 2009-04-22
Fa1/3 1969-12-31
Fa1/8 1969-12-31
Fa1/15 1969-12-31
Fa1/13 1969-12-31
Fa1/10 1969-12-31
Fa1/1 1969-12-31
Fa1/12 2009-04-22
Fa0/1 2009-04-22
Fa1/5 2009-04-22
Fa1/6 1969-12-31
Se0/0/0.1 1969-12-31
Fa1/7 1969-12-31
Fa1/2 1969-12-31
Lo0 1969-12-31
Fa1/4 2009-04-22
  #4 (permalink)  
Old 04-23-2009
mrlayance mrlayance is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 20
Thanks for the replys.

I went about this a different way. But now I have a different issue.

Here is my code.

Code:
#!/bin/bash
file='file.txt'
while read inter time
do
   printf "%s %s\n" "${inter}" "perl -e 'print scalar localtime("${time}") . "\n";"
done < "${file}"
This is the result.

Code:
Fa1/14 perl -e 'print scalar localtime(0) . n;
Se0/0/0 perl -e 'print scalar localtime(0) . n;
Fa1/11 perl -e 'print scalar localtime(0) . n;
Fa1/9 perl -e 'print scalar localtime(0) . n;
Fa1/0 perl -e 'print scalar localtime(0) . n;
Se0/0/1 perl -e 'print scalar localtime(1240421065) . n;
Gi1/0 perl -e 'print scalar localtime(0) . n;
Fa0/0 perl -e 'print scalar localtime(1240421065) . n;
Fa1/3 perl -e 'print scalar localtime(0) . n;
Fa1/8 perl -e 'print scalar localtime(0) . n;
Fa1/15 perl -e 'print scalar localtime(0) . n;
Fa1/13 perl -e 'print scalar localtime(0) . n;
Fa1/10 perl -e 'print scalar localtime(0) . n;
Fa1/1 perl -e 'print scalar localtime(0) . n;
Fa1/12 perl -e 'print scalar localtime(1240421065) . n;
Fa0/1 perl -e 'print scalar localtime(1240421065) . n;
Fa1/5 perl -e 'print scalar localtime(0) . n;
Fa1/6 perl -e 'print scalar localtime(0) . n;
Se0/0/0.1 perl -e 'print scalar localtime(0) . n;
Fa1/7 perl -e 'print scalar localtime(0) . n;
Fa1/2 perl -e 'print scalar localtime(0) . n;
Lo0 perl -e 'print scalar localtime(0) . n;
Fa1/4 perl -e 'print scalar localtime(1240421065) . n;
I tried running perl -x script.sh but that does not work.
  #5 (permalink)  
Old 04-23-2009
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,128
Code:
#!/bin/bash
file='file.txt'
while read inter time
do
   printf "%s %s\n" "${inter}" "$(perl -e 'print scalar localtime("${time}") . "\n";')"
done < "${file}
  #6 (permalink)  
Old 04-23-2009
mrlayance mrlayance is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 20
Quote:
Originally Posted by vgersh99 View Post
Code:
#!/bin/bash
file='file.txt'
while read inter time
do
   printf "%s %s\n" "${inter}" "$(perl -e 'print scalar localtime("${time}") . "\n";')"
done < "${file}

Hmm, different issue now? The $time variable is not being passed for some reason.

Code:
Fa1/14 Wed Dec 31 20:00:00 1969
Fa1/11 Wed Dec 31 20:00:00 1969
Se0/0/0 Wed Dec 31 20:00:00 1969
Fa1/9 Wed Dec 31 20:00:00 1969
Fa1/0 Wed Dec 31 20:00:00 1969
Fa1/3 Wed Dec 31 20:00:00 1969
Fa0/0 Wed Dec 31 20:00:00 1969
Gi1/0 Wed Dec 31 20:00:00 1969
Se0/0/1 Wed Dec 31 20:00:00 1969
Fa1/8 Wed Dec 31 20:00:00 1969
Fa1/15 Wed Dec 31 20:00:00 1969
Fa1/13 Wed Dec 31 20:00:00 1969
Fa1/10 Wed Dec 31 20:00:00 1969
Fa1/12 Wed Dec 31 20:00:00 1969
Fa1/1 Wed Dec 31 20:00:00 1969
Fa0/1 Wed Dec 31 20:00:00 1969
Fa1/6 Wed Dec 31 20:00:00 1969
Fa1/5 Wed Dec 31 20:00:00 1969
Se0/0/0.1 Wed Dec 31 20:00:00 1969
Fa1/7 Wed Dec 31 20:00:00 1969
Fa1/2 Wed Dec 31 20:00:00 1969
Lo0 Wed Dec 31 20:00:00 1969
Fa1/4 Wed Dec 31 20:00:00 1969
  #7 (permalink)  
Old 04-23-2009
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,128
sorry - my bad:

Code:
#!/bin/bash
file='file.txt'
while read inter time
do
   printf "%s %s\n" "${inter}" "$(perl -e 'print scalar localtime('"${time}"') . "\n";')"
done < "${file}
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:10 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0