Problem In Shell Script

Hi,

I'm new to Shell script. Can anyone tell me where is the wrong in my code?

And, my code is --

echo "Enter Start Date(YYYY-MM-DD): "
read stdt 


echo "Enter End Date(YYYY-MM-DD): "
read endt 

echo "Enter Flight Number(Optional): "
read fln


echo "Enter Output XML File Name(Including Extension): "
read dst

#if [ $fln eq "" ] then
#if [ "$fln" = "" ] then

if [ $? -lt 3 ] then
   java DailyScheduleExport $stdt $endt> $dst
else
   java DailyScheduleExport $stdt $endt $fln> $dst
fi

Waiting for your reply.:mad:

And the error is --

ods@awhq6640[/prod/ods/sqlj/ods_services]>sh DailyScheduleExport_q.ksh
DailyScheduleExport_q.ksh[2]: ^M: Execute permission denied.
DailyScheduleExport_q.ksh[4]: ^M: Execute permission denied.
DailyScheduleExport_q.ksh[6]: ^M: Execute permission denied.
DailyScheduleExport_q.ksh[8]: ^M: Execute permission denied.
DailyScheduleExport_q.ksh[9]: ^M: Execute permission denied.
DailyScheduleExport_q.ksh[12]: ^M: Execute permission denied.
DailyScheduleExport_q.ksh[13]: ^M: Execute permission denied.
Enter Start Date(YYYY-MM-DD):
2007-01-01
DailyScheduleExport_q.ksh[16]: ^M: This is not an identifier.
DailyScheduleExport_q.ksh[17]: ^M: Execute permission denied.
DailyScheduleExport_q.ksh[18]: ^M: Execute permission denied.
Enter End Date(YYYY-MM-DD):
2007-09-21
DailyScheduleExport_q.ksh[20]: ^M: This is not an identifier.
DailyScheduleExport_q.ksh[21]: ^M: Execute permission denied.
Enter Flight Number(Optional):
DailyScheduleExport_q.ksh[23]: fln^M: This is not an identifier.
DailyScheduleExport_q.ksh[24]: ^M: Execute permission denied.
DailyScheduleExport_q.ksh[25]: ^M: Execute permission denied.
Enter Output XML File Name(Including Extension):
DailyScheduleExport_q.ksh[27]: dst^M: This is not an identifier.
DailyScheduleExport_q.ksh[28]: ^M: Execute permission denied.
DailyScheduleExport_q.ksh[31]: ^M: Execute permission denied.
DailyScheduleExport_q.ksh[32]: Syntax error at line 32 : `if' is not matched.
ods@awhq6640[/prod/ods/sqlj/ods_services]>

And, the file status is --

-rwxrwxrwx   1 ods        ods            800 Sep 24 06:28 DailyScheduleExport_q.ksh

What might be the problem? Any suggestion?

Regards.

Satyaki De.

Can you post the output of this command

head -1 <your_shell_script_name> | od -a

Perhaps that must be because of the ctrl-m characters in the shell script. Run a dos2unix on your shellscript and then run it.

Also put #! /bin/ksh as the first line of your shell script.

Hi thanks for your reply. But, it is showing error message --

ods@awhq6640[/prod/ods/sqlj/ods_services]>tput clear
ods@awhq6640[/prod/ods/sqlj/ods_services]>head -1 DailyScheduleExport_q.ksh | od -a
od: illegal option -- a
Usage: od [-v] [-A base] [-j skip] [-N count] [-t type_string]... [file...]
ods@awhq6640[/prod/ods/sqlj/ods_services]>

I've already added this line in my shell -

#!/usr/bin/ksh

Regards.

Satyaki De.

Hi,

Looks like you may have extraneous "Control-M" characters in your file. Open it in vi to see. This occurs sometimes when porting a DOS/Windows file to Unix. You can delete them one by one or run the command: dos2unix. If your OS doesn't have this command look for one by typing: man -k dos.

Hope this helps,

John

Which OS are you on ? Post the output of uname -a.

Do you have dos2unix on your machine ? If so, try running dos2unix on the shellscript.

Thanks for your reply. OS information is as follows -


HP-UX awhq6640 B.11.11 U 9000/800 665379313 unlimited-user license

Regards.

Satyaki De.

So you must be having dos2ux on your system. Run

dos2ux DailyScheduleExport_q.ksh

and then try running the script.

Ya you are right there is Ctrl+M character in my shell file, basically i import these file from windows. And, i don't have dos2unix installed in this os. Now, can you show me how to delete these character from my shell file?

Regards.

Satyaki De.

dos2ux scriptname > newname

Thanks for your suggestion. Ctrl+M character is removed now.

Regards.

Satyaki De.

Hi!

Now i'm facing problem in my shell - can you pls rectify it?


ods@awhq6640[/prod/ods/sqlj/ods_services]>vi DailyScheduleExport_q.ksh
"DailyScheduleExport_q.ksh" 24 lines, 603 characters
#!/usr/bin/ksh

CLASSPATH=""

CLASSPATH=.:$ORACLE_HOME/sqlj/lib/translator.jar:$ORACLE_HOME/sqlj/lib/runtime12.jar:$ORACLE_HOME/jdbc/lib/classe
s12.jar:$CLASSPATH

CLASSPATH=.:/opt/mqm/java/lib/com.ibm.mq.jar:/opt/mqm/java/lib/connector.mq:$CLASSPATH


#-------compiling-------------------
#sqlj -warn=nonulls DailyScheduleExport.sqlj


#--------exceution-----------------

if [ $? -eq 3 ]; then
   print firstone
   java DailyScheduleExport $1 $2 $3
elif [ $? -lt 3 ]; then
  print secondone
  java DailyScheduleExport $1 $2
else
   echo "tart_date(YYYY-MM-DD) end_date(YYYY-MM-DD) flt_nbr(Optional)"
fi
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
"DailyScheduleExport_q.ksh" 24 lines, 604 characters

When i'm running this with -


ods@awhq6640[/prod/ods/sqlj/ods_services]>sh DailyScheduleExport_q.ksh
secondone

It is looking for wrong option - whereas it should display the third message. Where is my fault?

Regards.

Satyaki De.

Can anyone tell me where am i doing wrong in my code? Help is needed.


if [ $1 -eq "" and $2 -eq ""]; then
   print "Usage start_date(YYYY-MM-DD) end_date(YYYY-MM-DD) flt_nbr(Optional)"
elif [ $1 -ne "" and $2 -ne "" and $3 -eq ""]; then
   print secondone
   java DailyScheduleExport $1 $2
else
   print firstone
   java DailyScheduleExport $1 $2 $3
fi

I'm newbi to Shell.

Regards.

Satyaki De.:mad: