Different epoch conversion result for bash and csh users


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Different epoch conversion result for bash and csh users
# 1  
Old 09-26-2012
Different epoch conversion result for bash and csh users

Hi there

I'm using this script to convert command line history with Epoch time stamp to human readable. While it works fine with users with /bin/csh shell, it fails to convert for users with /bin/bash shell. Why is this happening? I even changed and added * and [0-9] after the # but it still didnt work..any idea what I'm doing wrong?

Code:
cat /var/log/user_history/root_history  | while read line ; do  if [[ $line =~ '^#' ]]; then  date -d "@$(echo $line | cut -c2-)"; else echo $line ; fi; done

This is how the original history log look like:

Code:
tail /var/log/user_history/root_history
#1348524075
exit
#1348565492
crontab -e
#1348609978
df -kh
#1348610010
exit
#1348644767
df -h

These are my failed attempts

Code:
 do  if [[ $line =~ '^#[0-9]' ]]

 do  if [[ $line =~ '^#*' ]]

Meanwhile for csh users, I am getting converted logs

Code:
# tail /var/log/user_history/Epoch_Convert/upbadm
#+1345026511
exit
#+1345093905
Date is: Thu Aug 16 15:11:45 EST 2012
#+1345097660
Date is: Thu Aug 16 16:13:47 EST 2012
#+1345097660
Date is: Thu Aug 16 16:14:20 EST 2012
#+1345097669
Date is: Thu Aug 16 16:14:29 EST 2012

Could it be because the csh users' history logs have a plus sign "+" but the bash users' dont have the "+" sign?
# 2  
Old 09-26-2012
Drop the quotes around ^#. In bash, the second operand for =~ is a pattern. Since you've quoted the pattern, it is not being treated as a pattern but as a string. Hence, only the else statement is executed.
This User Gave Thanks to elixir_sinari For This Post:
# 3  
Old 09-26-2012
MySQL SOLVED

thanks alot

xxx

i love this forum!

Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Python conversion to epoch time

Hi. I have timestamps that I am trying to convert to epoch time. An example: I am trying to convert this to an epoch timestamp but have one little glitch. I have this: import time date_time = '' pattern = '' epoch = int(time.mktime(time.strptime(date_time, pattern))) print epoch... (1 Reply)
Discussion started by: treesloth
1 Replies

2. Shell Programming and Scripting

Shell Script for Epoch Time Conversion

Hi there I came across this script online to convert Epoch time to proper date format, but I am receiving the following error Also, I have HISTTIMEFORMAT set in user's .profile so that their history output shows time stamps. Additionally I have changed their .history location to a dedicated... (9 Replies)
Discussion started by: hedkandi
9 Replies

3. Shell Programming and Scripting

Epoch & Unix Timestamp Conversion Tools

Hi All, Please read the below data carefully. I need an unix command for converting unix timestamp to Epoch timestamp. I need to daily convert this today's unix(UTC) time to epoch time, so i am thinking to make a shellscript for this. Please help me for this by providing... (3 Replies)
Discussion started by: aish11
3 Replies

4. Shell Programming and Scripting

Date conversion from Standard/given format to seconds/epoch

I am trying get time difference of two dates in secs. Initially I want to convert a standard date format to epoch for two dates and then subtract the two epoch dates. Example : date -d "2007-09-01 17:30:40" '+%s' But this gives me below error date: illegal option -- d Usage: date OS: AIX... (6 Replies)
Discussion started by: bpaac
6 Replies

5. Shell Programming and Scripting

epoch conversion

I need to convert an epoch time from a file into a standard UTC time and output it in the same format but I'm not sure what's the best approach here's the input file and the bold part is what I need to convert. 1,1,"sys1",60,300000 2,"E:",286511144960 3,1251194521,"E:",0,0... (2 Replies)
Discussion started by: satchy321
2 Replies

6. Shell Programming and Scripting

In a csh script, can I set a variable to the result of an SQLPLUS select query?

Can someone tell me why I'm getting error when I try to run this? #!/bin/csh -f source ~/.cshrc # set SQLPLUS = ${ORACLE_HOME}/bin/sqlplus # set count=`$SQLPLUS -s ${DB_LOGIN} << END select count(1) from put_groups where group_name='PC' and description='EOD_EVENT' and serial_number=1;... (7 Replies)
Discussion started by: gregrobinsonhd
7 Replies

7. Shell Programming and Scripting

csh script to search for files and display result

Hello all. I'm a long time browser, first time poster...Be gentle :-) I don't use csh much, but have been asked to make a small script for our HP-UX systems to search for a report file(s) or summary file and display the result (I was using vuepad, but this probably is just complicating... (4 Replies)
Discussion started by: neillsm
4 Replies

8. Shell Programming and Scripting

Sending/append result from CSH script to xls file

Hi, 1st post... Done a quick search for this so apologies if I've missed it. Basically I want to output and and append several values generated by a csh script direct to an xls openoffice file, rather than send to txt file and then physically copy and paste to xls file. Already I send... (4 Replies)
Discussion started by: scottyjock
4 Replies

9. Shell Programming and Scripting

csh -> ksh conversion question

Having been a long-time csh person I now need to convert a lot of stuff to run under ksh. Can anyone tell me how to do a ksh equivalent of the csh history substitution !* that can be used in an alias, ie how would I do: alias cd "cd \!*; pwd" alias find "find . -name... (2 Replies)
Discussion started by: jonnywilkins
2 Replies

10. Shell Programming and Scripting

conversion from EPOCH timestamp to local time zone

hello gurus, i want a perl/shell script which once invoked should convert a set of EPOCH timestamps to local time ( IST..i want) . how does it work ,i have an idea on that..but writing a perl/shell script for it is not possible for me...so i need help for the same. my exact requirement is... (2 Replies)
Discussion started by: abhijeetkul
2 Replies
Login or Register to Ask a Question