任何人都可以指导我吗?我正在尝试将kshell脚本迁移到python。 如果有人可以指导我如何继续这项任务。我真的需要这个功能吗?我想让简洁易读。谢谢。 这是代码:
#!/bin/ksh
DB="BATCH_JOB_STAT"
LINE=$DB
export $DB
NoFile()
{
# no file
COLOR="clear"
LINE=$DB" NO BATCH_JOB ERROR FLAG FOUND"
echo $LINE
$BB $BBDISP "status ${MACHINE}.BATCH_JOB_STAT $COLOR `date` $LINE"
exit 1
}
MultiFile()
{
fail_flag=0
# Check more than One file
files=$(ls /opt/rh/flag/*)
for file in $files
do
if [ -f $file ] ; then
## echo "# Error. Flag File found: $file"
fail_flag=1
fi
done
## echo "-- Fail flag is : $fail_flag"
if [ $fail_flag -eq 0 ]; then
# no FAIL status means GOOD
COLOR="green"
LINE=$DB" OK"
echo $LINE
else
COLOR="red"
LINE=$DB" BATCH_JOB ERROR FLAG FILE FOUND. <P> -- $file -- </P> <P> Support <A HREF=http://johndoe/support.htm> Tech </A>"
echo $LINE
fi
$BB $BBDISP "status ${MACHINE}.BATCH_JOB_STAT $COLOR `date` $LINE"
}
# MAIN
file_count=$(ls -l /opt/rh/flag 2>/dev/null |grep -v total |wc -l)
case "$file_count" in
0) NoFile ;;
*) MultiFile ;;
esac
exit 0