我在UNIX shell脚本编写中使用generate_vendor_info.ksh名称编写了以下代码。
#!/usr/bin/ksh
sqlplus -s tips/tips@tipstest<< EOS
SET NEWPAGE 0
SET SPACE 0
SET LINESIZE 135
SET PAGESIZE 0
SET ECHO OFF
SET FEEDBACK OFF
SET VERIFY OFF
SET HEADING OFF
SET WRAP OFF
SET MARKUP HTML OFF SPOOL OFF
spool vendor_info.dat
select 'B','|',to_char(sysdate,'YYYYDDMM') from dual;
select 'H','|',vendor_id,'|', case config_code when 'DASN' then 'ASNVENDOR' when 'VASN' then 'VCDVENDOR' END,'|', case config_value when 'Y' then 'Y' when 'N' then 'N' END,'|',to_char(updated_date,'YYYYDDMMHH24MISS') from tips_vendor_config_msi,dual where updated_date >= sysdate-19 and (config_code in ('DASN','VASN')) order by updated_date desc;
select 'E','|',ltrim(count(*)+2) from tips_vendor_config_msi,dual where updated_date >= sysdate-19 and (config_code in ('DASN','VASN'));
spool off;
spool store_info.lst
select distinct(ltrim(s.store)) from tips_store_config_msi s where s.store='3753' order by s.store;
spool off;
EOS
TIMESTAMP=`date +"%C%y%m%d%H%M%S"`
for StoreNO in `cat store_info.lst`
do
FILENAME="$(echo ${StoreNO}.${TIMESTAMP})"
ORIGINAL_FILE="vendor_info.dat"
NEW_FILE="$(echo ${ORIGINAL_FILE}.${FILENAME})"
cp $ORIGINAL_FILE $NEW_FILE
echo $NEW_FILE
done
当我执行shell脚本时,我得到如下结果。
TIPSTAPP (TIPS):/home/applprod/TMS/ASN/SCRIPTS:ksh generate_vendor_info.ksh [YOU HAVE NEW MAIL] B|20142608 H|79790|VCDVENDOR|Y|20141008231111 H|79790|ASNVENDOR|N|20141008231111 H|79818|VCDVENDOR|Y|20140908231111 H|79818|ASNVENDOR|N|20140908231111 E|6 3753 **generate_vendor_info.ksh[33]: cat: not found**
答案 0 :(得分:1)
出现错误消息表明您的shell脚本无法找到cat
命令。
要进行调试,请使用命令ksh -xv generate_vendor_info.ksh
在详细调试模式下运行ksh。
另外,您是否有理由在不必要的子shell中调用不必要的echo
命令?您撰写了FILENAME="$(echo ${StoreNO}.${TIMESTAMP})"
,但这可以更简单地表达为FILENAME="${StoreNO}.${TIMESTAMP}"
,并在您设置NEW_FILE
的位置进一步表达相同的两行。