Unix/Linux Go Back    


UNIX for Beginners Questions & Answers If you're not sure where to post a Unix or Linux question, post it here. All unix and Linux beginners welcome in this forum!

Can not determine end-of-file error

UNIX for Beginners Questions & Answers


Tags
date, mv, sh, solved

Reply    
 
Thread Tools Search this Thread Display Modes
    #8  
Old Unix and Linux 6 Days Ago
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 23 February 2017, 3:22 AM EST
Location: San Jose, CA, USA
Posts: 10,010
Thanks: 484
Thanked 3,448 Times in 2,945 Posts
Yes. That is an issue. The here-document started with the line:

Code:
       sqlplus /nolog <<EOF

does not end until there is a line that just contains the three characters EOF and a line terminating <newline> character. If you started the here document with <<-EOF instead of <<EOF, the here-document could be terminated by a line just containing zero or more leading <tab> characters, the three characters EOF, and a line terminating <newline> character. Any <space> characters before the here-document terminator string will cause that line to included in the here-document and keep it from being recognized as the terminator.
The Following User Says Thank You to Don Cragun For This Useful Post:
jim mcnamara (5 Days Ago)
Sponsored Links
    #9  
Old Unix and Linux 6 Days Ago
wisecracker's Unix or Linux Image
wisecracker wisecracker is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 21 February 2017, 9:42 AM EST
Location: Loughborough
Posts: 1,148
Thanks: 337
Thanked 299 Times in 231 Posts
Try:-

Remove the indent on line #12 to place the EOF token at the beginning of the line.
Sponsored Links
    #10  
Old Unix and Linux 5 Days Ago
V1l1h1 V1l1h1 is offline
Registered User
 
Join Date: Jul 2012
Last Activity: 22 February 2017, 9:59 AM EST
Posts: 27
Thanks: 0
Thanked 1 Time in 1 Post
ok.. to test further, I've removed all of the spaces and used <<EOF>> tag as suggested. I'v also used db connection login/pw.. this time it didn't prompt end-of-file error.. but file rename didn't work..
if I could I've two follow-up questions -


Code:
#!/bin/sh
#. /u01/app/oracle/local/bin/cron_env_$ORACLE_SID
file_name='./services.dat'
if [ -f $file_name ]; then
echo "file found " $file_name
sqlplus /nolog <<-EOF >./tst.log
connect test/test
set feedback off
set echo on
@./glspreltr.sql
exit
EOF
fi
mv $file_name $file_name_%m%d%Y
echo $file_name

output:
perseus.gasleak(/tmp/v_tst)% ./f2.sh
file found ./services.dat
./services.dat


qes1: in the file rename some how did not like "%m%d%Y" format.. why?
qes2: is there way to determine when the file was written mm-dd-yy-hh-mm and use that for the rename. if so, please suggest how to do that.
Attached Thumbnails
Can not determine end-of-file error-file_rn_issue-png  
    #11  
Old Unix and Linux 5 Days Ago
apmcd47 apmcd47 is offline
Registered User
 
Join Date: Feb 2011
Last Activity: 20 February 2017, 4:46 AM EST
Posts: 136
Thanks: 1
Thanked 22 Times in 22 Posts
Quote:
Originally Posted by V1l1h1 View Post
qes1: in the file rename some how did not like "%m%d%Y" format.. why?
qes2: is there way to determine when the file was written mm-dd-yy-hh-mm and use that for the rename. if so, please suggest how to do that.
As you are using /bin/sh you need to use the date program:


Code:
mv "${file_name}" "${file_name}"_$(date +'%m%d%Y')

You can get hold of the access time, modification time and change time of a file using stat if you have it:

Code:
stat -c "%y" "${file_name}"

Gnu date also has a switch to show the last modification timestamp of a file:

Code:
date -r "${file_name}"

which is probably the closest you will get on a Linux/Unix system to the creation time. So you could possibly use:

Code:
mv "${file_name}" "${file_name}"_$(date -c "${file_name}"  +'%m%d%Y')


Last edited by apmcd47; 5 Days Ago at 10:34 AM.. Reason: missed underscore in renamed filename
Sponsored Links
    #12  
Old Unix and Linux 5 Days Ago
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 22 February 2017, 5:48 PM EST
Location: Saskatchewan
Posts: 21,928
Thanks: 1,050
Thanked 4,095 Times in 3,794 Posts
Quote:
Originally Posted by V1l1h1 View Post
qes2: is there way to determine when the file was written mm-dd-yy-hh-mm and use that for the rename. if so, please suggest how to do that.
Not really, not reliably, especially with only two-digit years.
Sponsored Links
    #13  
Old Unix and Linux 5 Days Ago
V1l1h1 V1l1h1 is offline
Registered User
 
Join Date: Jul 2012
Last Activity: 22 February 2017, 9:59 AM EST
Posts: 27
Thanks: 0
Thanked 1 Time in 1 Post
yes I'm using "/bin/sh "

it won't let me use stat .. it prompts "not found..
also, I could not use switch with stat and also -r switch with date
the closet I can try was that
Code:
mv "${file_name}" "${file_name}"_`date +'%m%d%Y'`

at least this time renamed the file with date stamp..

Appreciate all your help. It is helping me learn shell scripting
Sponsored Links
    #14  
Old Unix and Linux 20 Hours Ago
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 22 February 2017, 5:48 PM EST
Location: Saskatchewan
Posts: 21,928
Thanks: 1,050
Thanked 4,095 Times in 3,794 Posts
Quote:
Originally Posted by V1l1h1 View Post
yes I'm using "/bin/sh "

it won't let me use stat .. it prompts "not found..
also, I could not use switch with stat and also -r switch with date
the closet I can try was that
Code:
mv "${file_name}" "${file_name}"_`date +'%m%d%Y'`

at least this time renamed the file with date stamp..

Appreciate all your help. It is helping me learn shell scripting
You could try my general purpose date script written in perl which supports many GNU date like options.
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to determine if there's a file in directory! nikki1200 Shell Programming and Scripting 1 11-02-2011 03:22 AM
Determine BL and RL of a file Linux-wannabe Shell Programming and Scripting 1 01-21-2010 05:57 PM
How to determine if a file is done copying husker_ricky UNIX for Advanced & Expert Users 2 05-22-2008 12:32 PM
determine owner of a file unibboy Shell Programming and Scripting 4 01-26-2008 02:39 PM
How to determine if a file is ASCII? popo UNIX for Dummies Questions & Answers 11 02-05-2002 05:00 PM



All times are GMT -4. The time now is 07:47 AM.