how to call a .bat file using KSH

Hi all,

I am a very new user for korn scripting and in a process of learning.
i have a .bat file that calls a .vbs file which calls a macro used to convert an excel spread sheet to .csv file...
Now i want to automate this process. I want to call this bat file using a korn script or a korn script that runs my .vbs file...
can anyone say me how to do that
the .bat and .vbs files are on windows. Even the created new .cvs file is also placed on windows.
Below code cotains my .bat and .vbs files

.bat

Code:
start /w wscript.exe [\\pb-a-024\xyz.vbs](file://pb-a-024/xyz.vbs)
.vbs

Code:
Dim xlApp, xlBook, xlSht Dim filenamefilename = "[\\pb-a-024\xyz.xls](file://pb-a-024/xyz.xls)"Set xlApp = CreateObject("Excel.Application")set xlBook = xlApp.WorkBooks.Open(filename)set xlSht = xlApp.activesheet'xlBook.Close FalsexlApp.Quit'always deallocate after use...set xlSht = Nothing Set xlBook = NothingSet xlApp = Nothing

I'm not sure if I understand that...
You have ksh from cygwin running on windows machine and want to execute external command (in this case a bat file)?

By adding ". ./file1.bat" in the shell script will execute file1.bat

Thanks... but can you be more detail... i dont a bit about Unix apart from how to execute a script...

can you say me how should i give the path of the batfile....since the bat file is on windows...
i just want a korn script that will trigger and start the bat file.... and the out put is also generated to windows.... so the korn script have to just trigger the bat file...
Please be detail as my knowledge is very low on Unix

Thanks!

I am sorry i dint understand what your question is...

Thanks!

What adderek asked you is the version of Unix you are using.

Cygwin is a desktop version of Unix.

Thanks!

I am sorry for not being clear...Well we dont have Cygwin and i dont i can get that also....

Actually the unix box and windows (windows XP Sp2, MS office 2003) are on different servers (I think so). I wrote a script to FTP a file form windows to unix and its working...

STEP_NUM="30"
STEP_NAME="FTP Files "
Log_Step_Begin
FTP_FILE_NAME="LTC*.csv"
FTP_DIR_NAME="ProviderReject"
ONE_MORE="Notification_Reports"
PRESENT_DIR=`pwd`
FTP_STATS="${LOG_DIR}/FTP_Provider_Rej.stats"
FTP_ERR="${LOG_DIR}/FTP_Provider_Rej.error"
ftp -nv ${SI_NOTIFICATION_FTP_IP} > ${FTP_STATS} 2> ${FTP_ERR} <<EOF 
user ${SI_NOTIFICATION_FTP_USER} ${SI_NOTIFICATION_FTP_PASSWORD}
cd ${ONE_MORE}
cd ${FTP_DIR_NAME} 
bin
lcd ${DATA_DIR}
pwd
dir
prompt off
mget ${FTP_FILE_NAME}  
mdelete ${FTP_FILE_NAME}
prompt on
dir
EOF
if [[ -f $FTP_ERR ]] && [[ ! -s $FTP_ERR ]]     
then                                            
  rm -f ${FTP_ERR}                              
fi                                              
CURRENT_DIR=`pwd`
echo 1
echo $`pwd`
cd ${DATA_DIR}
echo 2
echo $`pwd`
FTP_FILE_NAME=`ls | grep $FTP_FILE_NAME` 
UNIX_FILE_NAME="${FTP_FILE_NAME%.*}".dat
echo 3
echo $`pwd`
cd $CURRENT_DIR
echo 4
echo $`pwd`
if [[ ! -f ${DATA_DIR}/${FTP_FILE_NAME} ]]     
then
     print "\n FILE NOT  FOUND ! \n" >> ${SCRIPT_LOG_FILE}
     SUBJ="${SCRIPT_NAME} CSV FILE  NOT FOUND for ${CUR_MAINT_DATE}"
     MSG="File Not found .  Runtime=$(Elapsed_Time ${START_TIME})"
     echo "${MSG}" | mailx -s"${SCRIPT_RUN_ENV} - ${SUBJ}" `cat ${ANALYST_EMAIL_FILE}`
       
     if [ ! -d ${LOG_DIR}/${CUR_MAINT_DATE} ]  
     then                                       
       mkdir ${LOG_DIR}/${CUR_MAINT_DATE}     
     fi                                         
      mv -f ${SCRIPT_LOG_FILE} ${LOG_DIR}/${CUR_MAINT_DATE}
     exit 0
fi

Actually now i want add somemore to this script.... Before this script start i manually generate a LTC*.cvs on windows then run this script to ftp the .cvs file to unixbox.... Now i have decied to put it on cron so it automatically does the work at sheduled time.
On windows i have a maro that converts a .xls file into .cvs... which i run using a .bat and .vbs files... when i double click .bat file it asks me to select the file i want to convert into .cvs file and it converts. it save the converted file in a folder from where the unix script ftp the file.
I to make this manually work automaited i have to either convert the .xls file using unix script or using unix script to trigger .bat file....
I hope you understood what actually i want to do....Please sugesst me

Thanks!
Bhagya

To tell you the truth I was worried that you will write such an answer...

1) Do not use cron for such purposes. You might set a task in cron (task that would execute every minute)... But this is not the purpose of cron. Use it to execute some periodic scripts like cleanup that is performed once a day.
Of course you can use cron like you do - but there are many reasons why you shouldn't... I'll give you only one here:
Checking your mail manually every hour by going to the post office is a bad idea - instead there is a postman that would bring it to you when a new mail is present.
In the software world: you should not execute this code every minute. You should use some event based mechanism instead.

2) Different boxes => you cannot() execute an application on the remote host
(
) - in fact you can but you shouldn't

3) I would suggest a simple application (JAVA, C#, whatever) that is running as a service (get a service template from the web) and is listening on some network port. When your *.vbs, *.exe, *.whatever should be started - you just send a notification to the windows box (which acts as a server).
Example solution (probably not the best but simple one):
Some web server with server-side scripts support (like python... or php... or perl). The script is executing the .vbs file. You don't need bat file in that case.
According to my tiny humble experience you will use perl scripts or something similar (personally I do not like perl because it is way too easy to make the code unmaintainable).

Thanks... You mean to say these no one way i can do what i actually have to do... I dont know perl and i dont think its there on my unix box...
How can i see if perl is there on my Unix box,... i mean how can i know i can use,...
If i can use perl on my unix box can you say me what commands i need to use to trigger my .vbs file so it does it work...

Thanks

You do not understand me.
I'm telling that you shouldn't do the thing that you wanted to do (like you should not shoot in your head... but you have a free will and you can do whatever you like).

In the example (crappy, terrible, dishonored and worthless) solution that I gave:

  1. Windows box is running a web service
  2. Unix box is running anything (can be shell script + wget).

Example web service is some web client with perl support. You can grab activeperl for windows. Web server of your choice.
perl script would be simple: something like

#!perl -w
system('start command.vbs');

(Note that I do not like perl and syntax of SYSTEM is probably different)
Shell script would call something like "wget my.windows.box.com/hack_me_cause_this_software_is_easy_to_hack.pl"

Thanks a lot... i tried to see if my system have perl and found that i dont have anyways i want a suggestion. can i use cron to trigger a .bat file

EG: 30 14 * * 4 \\pbhp-oa-001\Temp bhagya.bat
the bat file is bhagya.bat, at \\pbhp-oa-001\Temp (on windows server) and must on every thursday at 14:30PM

can i do this?? can i trigger a bat file using cron... please suggest me

Thanks

It is a little difficult for me to understand what you are writing - sorry for telling this but you should work more on your English (I know that mine is not perfect either).
To execute *.bat, *.vbs, *.exe, or any other file on windows box you need to execute it on the windows box, not unix box.
You can use CRON - but you should not.
Seems like you could use windows "at" command (but again: that is not the correct solution). You can install cygwin as well and try cron from there (again: that is incorrect approach).

My advice: you need to read about event driven software and its pros over things like cron. Or at least about multitasking. Never write code that works in an endless loop with "delay" in every loop execution.

I am sorry if i dint explain you properly,.... Actually you know that a .bat file shouldnt be called from cron ( though its possible in some way which i am tring to firgure out) and from you i came to know that if i do there will be a security issue... but my team lead doesnt know that....after i say her she doesnt care,... she just want it to work and by this thursday...
First of all i dont know how to do it, next i have no other way to do and i dont fine any kind of information on how to do it...
I just want to schedule it using cron or use a Ksh script to run it....as i dont want to lose my job in a market like this. so try to help me plzzz

Thanks

Yes you can run a .BAT from Cygwin cron. It's a dumb solution but do-able. First of all you have to set up the Cygwin cron. Do a web search or read the Cygwin manual for how to do that. Then you need to create the correct cron entry to call your .BAT file on the required schedule. Then you probably need to modify your .BAT file to ensure that it has the right paths, etc. so that it can run successfully under cron.

We dont have cygwin in our systems...

You can install cygwin. If you cannot then most probably you cannot install anything else as well. If you cannot install anything else then most probably you won't complete your task before Thursday (it seems that someone requested from you more than you can do).

Thx.... i dont know it always happens that they ask to do something more then i can do...Thats because i am still a learner