If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > How to execute a Unix Shell command from a remote Windows application

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-07-09, 05:16
Wim Venema Wim Venema is offline
Registered User
 
Join Date: Jun 2004
Location: Lichtenvoorde, Netherlands
Posts: 53
Exclamation How to execute a Unix Shell command from a remote Windows application

Hi,

We have an ERP system running on Compaq Tru64 UNIX V5.1A (Rev. 1885).
I am able to run ERP commands (Macro recorded script files to invoke e.g. the invoice process) from the Unix command shell.
To automise this, I'd like to run these commands from a remote Windows application e.g. SQL Server (with VB Scripts).
Does anyone have an idea how to do this?

Thanks in advance,

Wim Venema

Last edited by Wim Venema; 09-07-09 at 15:40.
Reply With Quote
  #2 (permalink)  
Old 09-08-09, 11:28
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,448
This is commonly done by SSH (e.g. http://www.chiark.greenend.org.uk/~sgtatham/putty/), rsh, or rexec. The latter two are included with Windows but are typically frowned upon (or disallowed altogether) by system administrators because of security concerns.
Reply With Quote
  #3 (permalink)  
Old 09-16-09, 17:51
kitaman kitaman is offline
Papabi's friend
 
Join Date: Sep 2009
Location: Ontario
Posts: 626
You might also consider having the VB Script create a set of instructions for a Unix cron job to process, and drop the VBS instructions into a shared folder/directory
Reply With Quote
  #4 (permalink)  
Old 09-16-09, 17:52
Wim Venema Wim Venema is offline
Registered User
 
Join Date: Jun 2004
Location: Lichtenvoorde, Netherlands
Posts: 53
Hi Kitaman,

Can you please provide me with examples?

Thanks in advance,

Wim
Reply With Quote
  #5 (permalink)  
Old 09-16-09, 19:37
kitaman kitaman is offline
Papabi's friend
 
Join Date: Sep 2009
Location: Ontario
Posts: 626
Lets assume that you have some common directory/folder, using either NFS or Samba, or even ftp.
On the Windows side have the application create a request file containing named pairs as:

APPLICATION=invoicing\; export APPLICATION
DATE=20090915\; export DATE
NAME="John Doe"\; export NAME

The back slashes are required to escape any unix meta characters. The quotes are required for variables with embedded spaces. Do not leave any white space around the equal sign.
edit: On second reading, the backslashes will not be required unless a unix meta character is embedded within the variable value, such as NAME="Michael O\'Connor"; export NAME :edit

Save the file in the common directory, known as "/u/spool/in" on the unix side.

On the unix side, write a script like the following:

!#/bin/ksh
if [ -r lock.file ]
then
echo `cat $lock.file` is still running >log.file edit: probably should be >>
exit 1
fi
echo $$ >lock.file
list=`ls /u/spool/in`
for file in $list
do
. /u/spool/in/$file
echo $APPLICATION $DATE $NAME >>log.file
my_real_process
mv /u/spool/in/$file /u/spool/out
done
rm lock.file

Some caveats:
Add a routine to /etc/rc2.d to clear any lock files on system start up.
Add a second file to the out folder showing the results of the process.
The windows file will probably have carriage returns and line feeds at the end of each line. If this becomes a problem, use 'tr -d "\r" <infile >outfile' to eliminate them (or dos2unix if you have that)
If you use ftp to transfer the file, send two files for each request, the first containing the data as above, the second as a semaphore file to say that the transfer is complete. Unix will see the text file as soon as it is opened for writing, and may try to process it before the transfer is complete.
edit: When creating a file naming convention, consider the possibility of duplicates, and the options available for the ls command so that jobs are processed in the desired sequence.


Jack

Last edited by kitaman; 09-17-09 at 06:46.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On