问题:linux中的shell脚本,如何改写为bat文件?

#!/bin/sh

if [ $# -ne 1 ]; then
echo 1>&2 Usage: $0 [config_file]
exit 127
fi

SOURCE=`awk -F"=" '/^database_name/ { print $2 }' $1`
SECONDS=`date +%s`
TARGET=$SOURCE"_"$SECONDS
DESTINATION=../$SOURCE.$DIALOG.$VERSION

echo Database: $SOURCE
echo Dialog ID: $DIALOG

#drop the target databse
psql -c "drop database $TARGET"

#create database objects
psql $TARGET < postgres_create.sql

#copy base tables
psql -c "copy (select * from message) to stdout" $SOURCE | psql -c "copy message from stdin" $TARGET

$TARGET
psql -c "copy (select * from qs_publicationstatustype) to stdout" $SOURCE | psql -c "copy qs_publicationstatustype from

stdin" $TARGET

#save the dialog
psql -c "copy (select * from q_dialog where q_dialog_id = $DIALOG) to stdout" $SOURCE | psql -c "copy q_dialog from stdin"

$TARGET

#create database objects
psql $TARGET < postgres_index.sql

#make the destination directory
mkdir -p $DESTINATION
mkdir -p $DESTINATION/cdd
mkdir -p $DESTINATION/corticon

#create readme files
echo "Note: Rules assets are owned by a different user and will have to be copied separately" >> $DESTINATION/cdd/README
echo "Note: Rules assets are owned by a different user and will have to be copied separately" >>

$DESTINATION/corticon/README

#export the database
pg_dump $TARGET > $DESTINATION/postgres_create.sql

#copy the import template to the destination
cp $TEMPLATE $DESTINATION/dialogsImport.sh
chmod +x $DESTINATION/dialogsImport.sh

#drop the temp database
psql -c "drop database $TARGET"

#append to the import config file
echo "database_name=$SOURCE" >> $DESTINATION/import.cfg

#append to the import README file

echo "*********************************************" >> $DESTINATION/README
echo "*" >> $DESTINATION/README
echo "* Program: dialogsImport" >> $DESTINATION/README
echo "*" >> $DESTINATION/README
echo "* Version 0.5" >> $DESTINATION/README
echo "*" >> $DESTINATION/README
echo "* Author: Dan Dreon" >> $DESTINATION/README
echo "*" >> $DESTINATION/README
echo "*********************************************" >> $DESTINATION/README

echo "* run this script as the database user - typically postgres" >> $DESTINATION/README
echo "* run this script from inside the dialogsImport folder" >> $DESTINATION/README
echo "* psql must be in your path" >> $DESTINATION/README
echo "* first edit the import.cfg script and enter the appropriate values" >> $DESTINATION/README
echo "* to run this script type ./dialogsImport import.cfg" >> $DESTINATION/README
echo "* Note: rules assets need to be copied separately" >> $DESTINATION/README

#archive the directory
tar -zcvf $DESTINATION.tar.gz $DESTINATION

#delete the original
rm -rf $DESTINATION

如何把这个shell脚本移植到windows 的bat中?各位大虾们,小弟现在有个棘手的问题,请大虾们给以帮助。

还有 “psql ”这样的命令?!,Windows里面没有可以实现这种功能的命令啊,估计自己写也没那么容易写出来啊!
要是一些简单的Shell ,改用Bat来写没有问题,这个有点高级啊! 我感觉 写不了,你还是死了这条心吧!
温馨提示:内容为网友见解,仅供参考
第1个回答  2011-07-15
awk在windows下实现不了
第2个回答  2011-07-15
- -!
有人拿linux的shell和windows的bat比。。。。
第3个回答  2011-07-14
bat是Windows的,你写的这些是Linux的命令。追问

是 ,我想 写成bat的 该如何去写

追答

不行的,你这些命令是Linux下的,在windows 下是用不了的

相似回答