Hour display format

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Hour display format
# 8  
Old 07-12-2016
if it helps .. file is received hourly.. in the meantime, I'm countering "syntax error at line 14: `fi' unexpected" -- I must be doing something wrong..

Code:
#!/bin/sh
FILENAME_WANTED=`date +"HourlyDate_%Y%m%d_%H00.txt"`
echo "$FILENAME_WANTED"
FILENAME_CURRENT='HourlyData_20160708_1500.txt'
echo "$FILENAME_CURRENT"
if [ "$FILENAME_WANTED" == "$FILENAME_CURRENT" ]; then
    echo "file found"
else
    echo "file not found"
fi

# 9  
Old 07-12-2016
A bit strange: "syntax error at line 14" in a 10 line script...? When run with sh, it fails on the == operator. Try with single = only.
And, ...Date... won't match ...Data....
# 10  
Old 07-12-2016
still erring..

Code:
#!/bin/sh
FILENAME_WANTED=`date +"HourlyDate_%Y%m%d_%H00.txt"`
echo "$FILENAME_WANTED"
FILENAME_CURRENT='HourlyData_20160708_1500.txt'
echo "$FILENAME_CURRENT"
if [ "$FILENAME_WANTED" = "$FILENAME_CURRENT" ]; then
    echo "file found"
else
    echo "file not found"
fi

__________________________________________________________

output still has error

Code:
perseus.gasleak(/tmp/v_tst)% ls -l
total 40
-rw-r--r--   1 gasleak      2888 Jul 11 15:10 HourlyData_20160708_1500.txt
-rwxrwxrwx   1 gasleak        74 Jul 11 12:29 dt_tm_chk - v1.sh
-rw-r--r--   1 gasleak       229 Jul 11 15:13 dt_tm_chk- 07112016.sh
-rw-r--r--   1 gasleak       397 Jul 12 08:55 dt_tm_chk.sh
-rw-r--r--   1 gasleak       278 Jul 12 09:46 test.sh
perseus.gasleak(/tmp/v_tst)%
perseus.gasleak(/tmp/v_tst)%
perseus.gasleak(/tmp/v_tst)% sh test.sh
HourlyDate_20160712_0900.txt
HourlyData_20160708_1500.txt
test.sh: syntax error at line 10: `fi' unexpected
perseus.gasleak(/tmp/v_tst)%




Moderator's Comments:
Mod Comment Please use code tags as required by forum rules!

Last edited by RudiC; 07-12-2016 at 11:06 AM.. Reason: Added code tags.
# 11  
Old 07-12-2016
Worked for me as is. What's your OS/shell/editor version?
# 12  
Old 07-12-2016
i'm using Putty utility to run the shell script .. that is where I'm encountering error..

---------- Post updated at 11:16 AM ---------- Previous update was at 10:34 AM ----------

I used:
Code:
ls -t | head -n1

retrieve current file..

out for this is correct:
Code:
HourlyData_20160712_1000.txt

will I be able to use command:
Code:
 ls -t | head -n1

in a shell script?
Moderator's Comments:
Mod Comment PLEASE use CODE tags when displaying sample input, sample output, and code segments.

Last edited by Don Cragun; 07-12-2016 at 04:45 PM.. Reason: Remove BOLD tags; add CODE and ICODE tags.
# 13  
Old 07-12-2016
The error message you're getting makes no sense for the code you have shown us. Please show us the output (in CODE tags) from the command:
Code:
od -bc test.sh

# 14  
Old 07-13-2016
Good morning All -

Rodic,
I'm using notepad to write the shell script and invoke it using Putty utility
that is why I was encountering error "syntax error".. some of the echo lines I had embedded "`" symbol .. therefore, those lines seems to be displaying it ok..

So, I tried via "vi editor" from putty prompt and output displayed correctly for file comparison ( "file not found " ) .. but, editing via vi editor was not easy for me..

Qes. here is: can I use "notepad" to write the script and run it using putty interactively.. should I enclose all "echo" with this "`" symbol?

Hello Don,
This is the file list for today :
Code:
perseus.gasleak(/opt/gsoscada/GSO_SCADA)% ls -l Hourl*20160713*.txt
-rw-r--r--   1 gsoscada     1868 Jul 13 00:18 HourlyData_20160713_0000.txt
-rw-r--r--   1 gsoscada     2471 Jul 13 01:18 HourlyData_20160713_0100.txt
-rw-r--r--   1 gsoscada     1732 Jul 13 02:18 HourlyData_20160713_0200.txt
-rw-r--r--   1 gsoscada     2484 Jul 13 03:18 HourlyData_20160713_0300.txt
-rw-r--r--   1 gsoscada     1788 Jul 13 04:18 HourlyData_20160713_0400.txt
-rw-r--r--   1 gsoscada     2484 Jul 13 05:18 HourlyData_20160713_0500.txt
-rw-r--r--   1 gsoscada     1788 Jul 13 06:18 HourlyData_20160713_0600.txt
-rw-r--r--   1 gsoscada     2648 Jul 13 07:18 HourlyData_20160713_0700.txt

using putty retrieved latest file for today -
Code:
perseus.gasleak(/opt/gsoscada/GSO_SCADA)% ls -t | head -n1
HourlyData_20160713_0700.txt


So, my question was that can I use this syntax in the shell script to pull
latest file and stored in a variable for compassion?

by the way, this is what I see for -
Code:
perseus.gasleak(/tmp/v_tst)% od -bc test.sh
0000000 043 041 057 142 151 156 057 163 150 015 012 106 111 114 105 116
           #   !   /   b   i   n   /   s   h  \r  \n   F   I   L   E   N
0000020 101 115 105 137 127 101 116 124 105 104 075 140 144 141 164 145
           A   M   E   _   W   A   N   T   E   D   =   `   d   a   t   e
0000040 040 053 042 110 157 165 162 154 171 104 141 164 145 137 045 131
               +   "   H   o   u   r   l   y   D   a   t   e   _   %   Y
0000060 045 155 045 144 137 045 110 060 060 056 164 170 164 042 140 015
           %   m   %   d   _   %   H   0   0   .   t   x   t   "   `  \r
0000100 012 145 143 150 157 040 042 044 106 111 114 105 116 101 115 105
          \n   e   c   h   o       "   $   F   I   L   E   N   A   M   E
0000120 137 127 101 116 124 105 104 042 015 012 106 111 114 105 116 101
           _   W   A   N   T   E   D   "  \r  \n   F   I   L   E   N   A
0000140 115 105 137 103 125 122 122 105 116 124 075 047 110 157 165 162
           M   E   _   C   U   R   R   E   N   T   =   '   H   o   u   r
0000160 154 171 104 141 164 141 137 062 060 061 066 060 067 060 070 137
           l   y   D   a   t   a   _   2   0   1   6   0   7   0   8   _
0000200 061 065 060 060 056 164 170 164 047 015 012 145 143 150 157 040
           1   5   0   0   .   t   x   t   '  \r  \n   e   c   h   o
0000220 042 044 106 111 114 105 116 101 115 105 137 103 125 122 122 105
           "   $   F   I   L   E   N   A   M   E   _   C   U   R   R   E
0000240 116 124 042 015 012 151 146 040 133 040 042 044 106 111 114 105
           N   T   "  \r  \n   i   f       [       "   $   F   I   L   E
0000260 116 101 115 105 137 127 101 116 124 105 104 042 040 075 040 042
           N   A   M   E   _   W   A   N   T   E   D   "       =       "
0000300 044 106 111 114 105 116 101 115 105 137 103 125 122 122 105 116
           $   F   I   L   E   N   A   M   E   _   C   U   R   R   E   N
0000320 124 042 040 135 073 040 164 150 145 156 015 012 040 040 040 040
           T   "       ]   ;       t   h   e   n  \r  \n
0000340 145 143 150 157 040 042 146 151 154 145 040 146 157 165 156 144
           e   c   h   o       "   f   i   l   e       f   o   u   n   d
0000360 042 015 012 145 154 163 145 015 012 040 040 040 040 145 143 150
           "  \r  \n   e   l   s   e  \r  \n                   e   c   h
0000400 157 040 042 146 151 154 145 040 156 157 164 040 146 157 165 156
           o       "   f   i   l   e       n   o   t       f   o   u   n
0000420 144 042 015 012 146 151 015 012 167 150 151 154 145 040 162 145
           d   "  \r  \n   f   i  \r  \n   w   h   i   l   e       r   e
0000440 141 144 040 114 111 116 105 073 015 012 144 157 015 012 040 040
           a   d       L   I   N   E   ;  \r  \n   d   o  \r  \n
0000460 145 143 150 157 040 042 044 114 111 116 105 042 015 012 144 157
           e   c   h   o       "   $   L   I   N   E   "  \r  \n   d   o
0000500 156 145 040
           n   e
0000503


Vani

Last edited by V1l1h1; 07-13-2016 at 11:34 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Hange display format

I have a file , the file content will be modified regularly , its structure as below, the lines are begins with "A" and "B" . #vi file1 this is testing file A aaaaa B bbbbb A ccccc B ddddd A eeeee B fffff A ggggg B hhhhh I would like to have a script to use the... (3 Replies)
Discussion started by: ust3
3 Replies

2. Shell Programming and Scripting

How to convert 24 hour time to 12 hour timing?

Hi friends, I want to convert 24 hour timing to 12 hour please help me... my data file looks like this.. 13-Nov-2011 13:27:36 15.32044 72.68502 13-Nov-2011 12:08:31 15.31291 72.69807 16-Nov-2011 01:16:54 15.30844 72.74028 15-Nov-2011 20:09:25 15.35096 ... (13 Replies)
Discussion started by: nex_asp
13 Replies

3. Shell Programming and Scripting

Changing display format

Hi, My file cat a.txt Sat Nov 27 00:02:00 2010 00:02:00 Usr 27: Login by edi on batch. (452) 00:02:09 Usr 27: Logout by on batch. (453) 00:02:09 Usr 27: Login by edi on batch. (452) 00:02:22 Usr 27: Logout by on batch. (453) 00:02:22 Usr 27: Login by edi on batch.... (3 Replies)
Discussion started by: ganeshanbu
3 Replies

4. UNIX for Dummies Questions & Answers

How do i set time in 24 hour format?

Currently whenever i run date command output is shown like Mon Apr 12 05:17:21 IST 2010 When its 17:17 Here. How would i change it so that it should show. Mon Apr 12 17:17:21 IST 2010 (8 Replies)
Discussion started by: pinga123
8 Replies

5. UNIX for Dummies Questions & Answers

Date format Display Help

I have tried various arguments to get the date display as "Mar 10". I have tried date +"%c" -------> Wed Mar 10 11:51:21 EST 2010 date +"%b%d%Y_%H%M%S" --------> Mar102010_115121 date +"%b%d" -------> Mar10 date +"%t%b%e" ... (3 Replies)
Discussion started by: moveaix
3 Replies

6. UNIX for Dummies Questions & Answers

Date Display Format

Hello People, How can I display the date in a continuous format along with the time as below : 20091001_154547 i.e yyyymmdd_hhmmss format. Thanks. (3 Replies)
Discussion started by: sushant172
3 Replies

7. UNIX for Advanced & Expert Users

ls -l timestamp display format

The time stamp format using "ls -l" is either mmm dd hh:mm or mmm dd yyyy. For later case, how can I know the hh:mm as well. Thanks. (3 Replies)
Discussion started by: pok.fung
3 Replies

8. Shell Programming and Scripting

ls command format display

Hi I have 3 files $ ls -l -rw-r--r-- 1 osbadmin osbadmin 427701 Apr 22 12:06 SANITY_TEST -rw-r--r-- 1 osbadmin osbadmin 427701 Apr 22 12:06 Success 123333 -rw-r--r-- 1 osbadmin osbadmin 427701 Apr 22 12:06 Success 123333 (1) I need to see this "SANITY_TEST" "Success 123333" "Success... (6 Replies)
Discussion started by: mnmonu
6 Replies

9. Shell Programming and Scripting

display the files in a folder which are older than 1 hour

Hi, I have some files in a folder with different time stamps and I want to display the files which are older than 1 hour. i tried with find. need urgent help. (7 Replies)
Discussion started by: vgs
7 Replies

10. UNIX for Dummies Questions & Answers

display the files in a folder which are older than 1 hour

Hi, I have some files in a folder with different time stamps and I want to display the files which are older than 1 hour. i tried with find. need urgent help. (3 Replies)
Discussion started by: vgs
3 Replies
Login or Register to Ask a Question