从 Oracle 并发程序运行 UNIX shell 脚本时出现问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4257865/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Issue while running UNIX shell script from Oracle concurrent Program
提问by Arun Antony
I am trying to run a HOST script which I have build in KSH shell using an Oracle Concurrent Program.
我正在尝试运行我使用 Oracle 并发程序在 KSH shell 中构建的 HOST 脚本。
My Test script is as follows:
我的测试脚本如下:
echo "System Parameters passed by Concurrent Manager"
echo "+--------------------------------------------+"
XXWIN_PROGRAM=##代码##
XXWIN_LOGIN=
XXWIN_USERID=
XXWIN_USERNAME=
XXWIN_REQUEST_ID=
echo "XXWIN_PROGRAM :"$XXWIN_PROGRAM
echo "XXWIN_LOGIN :"$XXWIN_LOGIN
echo "XXWIN_USERID :"$XXWIN_USERID
echo "XXWIN_USERNAME :"$XXWIN_USERNAME
echo "XXWIN_REQUEST_ID :"$XXWIN_REQUEST_ID
shift 4
echo ""
echo "User Parameters passed by Concurrent Manager"
echo "+------------------------------------------+"
echo "1 :"
echo "2 :"
echo "3 :"
echo "4 :"
echo "5 :"
echo "6 :"
echo "7 :"
echo "8 :"
echo "9 :"
echo ""
# Generic Script Begins
# Declaring Constants, Data File Path, Control File Path etc
CTL_FILE_NAME= # Control File Name(s)
CTL_FILE_PATH= # Control File Path
DATA_FILE_NAME= # Data File Name(s)
DATA_FILE_PATH= # Data File Path
COMPONENT_NAME= # Interface Component Name
SEQ_VALIDATION= # Sequence Name
SUPPORT_EMAIL= # Support e-mail(s) List
# Printing the User Parameters
echo "1 :"$CTL_FILE_NAME
echo "2 :"$CTL_FILE_PATH
echo "3 :"$DATA_FILE_NAME
echo "4 :"$DATA_FILE_PATH
echo "5 :"$COMPONENT_NAME
echo "6 :"$SEQ_VALIDATION
echo "7 :"$SUPPORT_EMAIL
# Assigning the Archive, IN and Prog Dir Paths
ARCHIVE_DIR="$XXWIN_TOP/bin/TEMP/archive"
XXWIN_IN_DIR="$XXWIN_TOP/bin/TEMP/in"
XXWIN_PROG_DIR="$XXWIN_TOP"
# Printing the directories
echo "Archive Directory :" $ARCHIVE_DIR
echo "IN Directory :" $XXWIN_IN_DIR
echo "Program Directory :" $XXWIN_PROG_DIR
i=10
k=5
j=`expr $i + $k`
echo $j
echo $i
echo "Out of Concurrent Program"
Shell Script program name ends with ".prog"
Shell Script 程序名称以“.prog”结尾
I am running the concurrent request with the following parameters:
我正在使用以下参数运行并发请求:
The program completes normal but I am getting the following log messages.
该程序正常完成,但我收到以下日志消息。
If I am using #!/usr/bin/ksh
the program completes in error so I am running the host file with out that. From the log its clear that when ever a space is encountered in the script, its throwing an error saying "Command not found". Also as you can see that I am doing a simple addition, even that is also not recognized.
如果我正在使用#!/usr/bin/ksh
该程序会错误地完成,那么我将在没有它的情况下运行主机文件。从日志中可以清楚地看出,当脚本中遇到空格时,它会抛出一个错误,提示“找不到命令”。同样如您所见,我正在做一个简单的加法,即使这样也无法识别。
Any help in this regards is much appreciated.
非常感谢这方面的任何帮助。
Thanks :)
谢谢 :)
回答by JOTN
Did you happen to use an editor on a Windows system to create the script? It's puts a carriage return + line feed character at the end of every line instead of the Unix format of just having a line feed. That messes up the script execution. Unix systems usually have a command like "dos2unix" to convert the file.
您是否碰巧使用 Windows 系统上的编辑器来创建脚本?它在每一行的末尾放置了一个回车+换行符,而不是只有换行符的 Unix 格式。这搞乱了脚本的执行。Unix 系统通常有一个像“dos2unix”这样的命令来转换文件。
If that's not it, I would try running the script manually from the command line to make sure it works.
如果不是这样,我会尝试从命令行手动运行脚本以确保它正常工作。
回答by Arun Antony
When I tried to read the file using CAT -vt <filename>
, I could see that the file contains special characters such as ^M and ^I. This may be because of the file transfer mode(but I transferred in ASCII mode, still the special characters where appearing).
当我尝试使用 读取文件时CAT -vt <filename>
,我可以看到该文件包含特殊字符,例如 ^M 和 ^I。这可能是因为文件传输模式(但我以ASCII模式传输,仍然出现特殊字符)。
I opened a VI editor and pasted the same script. Save the file, tried to run the script, It was working fine.
我打开了一个 VI 编辑器并粘贴了相同的脚本。保存文件,尝试运行脚本,它工作正常。
I still didn't get how the special characters appeared. I used notepad++ as my editor.
我仍然不明白特殊字符是如何出现的。我使用记事本++作为我的编辑器。
回答by tvCa
When either VI or CAT displays specials characters, the conversion to Linux/Unix compatibility is not completely done. There's often many solutions, maybe Notepad++ is the cause here. Maybe not. Writing scripts on the OS itself, is not only faster (no need for FTP, which is already a big plus), but you don't have to face these annoying control-M characters. The ASCII conversion sometimes fails. You can also try another FTP program. Or avoid it all togheter, as mentioned above.
当 VI 或 CAT 显示特殊字符时,并没有完全转换为 Linux/Unix 兼容性。通常有很多解决方案,也许 Notepad++ 是这里的原因。也许不吧。在操作系统本身上编写脚本不仅速度更快(不需要 FTP,这已经是一个很大的优势),而且您不必面对这些烦人的 control-M 字符。ASCII 转换有时会失败。您也可以尝试另一个 FTP 程序。或者避免在一起,如上所述。