Pls help me with the below script.
Its returning an error No such file or Directory.
#!/bin/ksh
cd /enip/enipapp/cbp/AOC2511201
for file in `cat filename.txt | head -1 | tr -d '\r'`
do
for i in `cat '$file' | tr -d '\r'`
do
echo "-----script start `date` for $file----" >>log.txt
echo "$i" | mdsql
echo "-----script end `date` for $file----" >>log.txt
done
sleep 60
done
Thanks Methyl. let me try. But the issue now is when I pass through the script, lines are getting splitted like below... but when i cat that file, its in proper format.. Pls help me...
#!/bin/ksh
cd /enip/enipapp/cbp/AOC2511201
for file in `head -1 filename.txt | tr -d '\r'`
do
for i in `tr -d '\r' "${file}"`
do
echo "-----script start `date` for $file----" >>log.txt
echo "$i" | mdsql
echo "-----script end `date` for $file----" >>log.txt
done
sleep 60
done
If I understood your post, what is below probably works:
#!/bin/ksh
cd /enip/enipapp/cbp/AOC2511201
for file in `head -1 filename.txt | tr -d '\r'`
do
while read updateDML
do
echo "-----script start `date` for $file----" >>log.txt
echo "${updateDML}" | mdsql
echo "-----script end `date` for $file----" >>log.txt
done < "${file}"
sleep 60
done
This line will only give you the first line of filename.txt. Are you intending to process every filename in filename.txt ?
Just out of interest, what is "mdsql" ? It seems very inefficient to start a process for every line of SQL. Can the process read the entire program directly.
Well I'll say it if nobody else will!
You are clearly processing text files which were prepared on a Microsoft platform and contain the MSDOS line terminator <carriage-return><line-feed> rather than a standard unix text file which contains just the line terminator <line-feed>.
You will make your whole life easier if you convert the files from MSDOS format to UNIX format first. There are standard utilities with unix but the name varies with the unix version. Usually "dos2ux" or "dos2unix". See your "man" pages or tell us what Operating System you have.
Ps. I'm still concerned that you will be invoking "mdsql" once for every line of SQL. This appears to be grossly inefficient.