• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 724
  • Last Modified:

How to execute a shell script on a UNIX box from VB & after it successfully completes, ftp output files


I am running a Visual Basic script in Visual Basic for Applications, from an Access database. I want to execute a shell script on a UNIX box from my VB code, test to see if it executed correctly, and then ftp the output files to my Windows box if the execution was successful.

Right now I am able to telnet to the UNIX box from my VB code, use SendKeys to execute the shell script, but I
1) can't tell if it executed successfully
2) am not sure how to then ftp the output files back

Would it be possible to get some sample code for this? Thanks.
Tom
0
tcorbley2
Asked:
tcorbley2
  • 5
  • 5
  • 3
  • +1
1 Solution
 
vinnyd79Commented:
Have you tried rexec? It would be much more reliable then telnet and sendkeys. The idea is to connect to the rexec port which is usually running on port 512 to logon and send commands.

http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=21145&lngWId=1

0
 
tcorbley2Author Commented:
thanks for getting back to me so fast vinnyd79. Think it was less than 10 minutes.

The problem is that I am trying to automate my entire process in a script - set up the code and then let it go without user intervention. What you sent me is good, but not amenable to a script approach. Unfortunately I'm still having difficulty finding the code underneath the gui interface of the rexec zip file you pointed me to.

I want to get a the actual code, so I can insert it/adapt it to my VB script. I'm a little weak on the ftp commands I need also.
0
 
[ fanpages ]IT Services ConsultantCommented:
Hi,

How do you manually (visually) tell the script has completed (successfully, or otherwise) on your Unix machine?  Do you have a return code or message that could be 'read'?  Or could you write back the result to a file on a mounted drive that your Windows application could open/read?

Additionally, do you have an FTP server running on your Windows machine that the Unix script can connect to?

BFN,

fp.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
EDDYKTCommented:
have you tried to use rsh and rcp?
0
 
EDDYKTCommented:
never mind
0
 
tcorbley2Author Commented:
I have a return code that can be read, and I'm assuming I have an FTP server running on my Windows machine, since I can FTP to the Unix box from the DOS prompt.
0
 
[ fanpages ]IT Services ConsultantCommented:
...if you can open an FTP connection to your Unix box, then you do not have a server on your Windows machine; you have one on your Unix machine.

However, so long as you can connection one way or another & send the file(s) you need, then this is probably sufficient.

Have you tried a GET from your Unix machine whilst using the Windows/DOS Prompt connection?

BFN,

fp.
0
 
EDDYKTCommented:
rsh and rcp is non secure method which means you don't require password to access unix system. setup a user on unix without password will work.

FTP is limited on certain directory while rcp doesn't
0
 
tcorbley2Author Commented:
fanpages, yes I have already successfully executed a ftp and telnet session from the DOS command prompt on the Windows server, to connect to the Unix box, and I was able to get files that way.

EDDYKT, I don't believe a user without a password on the Unix box is an option, with security considerations.
0
 
[ fanpages ]IT Services ConsultantCommented:
OK... I appreciate this question has been open a few days now, so let's rope in the specification so far...

You have a Unix script process that you wish to monitor that you invoke 'remotely' via Telnet using SendKeys from a VB application.

You cannot tell when the script is complete.

When it is complete (and successful) you wish to FTP files back to your Windows machine.



My thoughts...

Change you Unix script to create a 'trigger' file (with a pre-determined path & filename) that, upon completion, contains a 'flag' (say a 'Y' or a 'N', or a '1' or a '0', or whatever you choose) to indicate if the script was successful, or not.

Just before you launching the process via Telnet, either delete this 'trigger' file via the same Telnet session, or use FTP from your Windows machine & delete remotely.  [See below - this file may not already exist - this stage is in case the previous attempt to read/delete the file failed and left the file hanging around).

Monitor ('poll') for the presence of this file from your windows application, and when you find it exists, open it & read the contents.  You can 'poll' using native Windows Software Development Kit (SDK) Application Programming Interface (API) calls specificially for File Transfer Protocol (FTP...!!) commands, or the Microsoft FTP ActiveX, or another third-party, interface.  'Polling' should be every few seconds to every few minutes depending on the expected run-time of the script.  Sorry... you didn't mention how long it took to run.

From the value read from the file, determine if you need to use your FTP commands to retrieve the files from the Unix machine.  Delete the 'trigger' file when you have finished reading from it to be a) 'tidy', and b) ensure that the file doesn't exist the next time your process runs.

(I'm suggesting not deleting the file during the initial stages of script just in case you check for the presence of the file before the script has deleted it... and hence you'd read the contents of a previous session).

If you need specific FTP access & file GET commands via API calls, either search here at Experts Exchange for previous examples [I've contributed to a few threads if you just wish to search for 'FTP' & 'fanpages'] or write back & I'll send either some external links or code as appropriate.

Hope all that made sense.

If not, obviously let me know & I'll clarify when necessary.

BFN,

fp.
0
 
tcorbley2Author Commented:
fanpages,

Thanks for your advice on the approach to take. I agree and actually was already thinking about doing something like that.

The Unix script can produce a file on the Unix box of a certain name, perhaps, if successful, and then I can search for that name when I ftp to the Unix box.

The problem that I'm running into is how to communicate with the Unix box through my VB script. Maybe you cover this in some of the examples that you cite - but at the moment, I don't know how. I use SendKeys, but this has no connection to the Unix box as it were. I'm executing commands by sending keystrokes, but I'm not able to read the result that they produce.

How can I do this, and is it possible to read the exit code of the Unix shell script through my VB script? Please provide some code also. I'd much prefer to just use Visual Basic for Applications without having to obtain any additional software. Thanks.

0
 
[ fanpages ]IT Services ConsultantCommented:
Hi,

I wasn't suggesting that you could read the results of your keystrokes; I took it as read that you had already decided on this method & it's pitfalls (i.e. the Telnet application not receiving all the characters &/or the Unix script process never starting).

The Microsoft Winsock Control can handle communications on TCP/IP port 23 (Telnet).  So maybe you need not use SendKeys, but can send the actual commands you wish via the previously opened socket to your Unix machine.

See:
http://www.vbcity.com/forums/faq.asp?fid=10&cat=Winsock
or
http://www.freevbcode.com/ShowCode.Asp?ID=2839
or
http://www.15seconds.com/issue/990408.htm

Other controls do exist that can provide Telnet support, [ http://www.catalyst.com/products/sockettools/visual/index.html ], for example (although I have no experience of using this).

Instead of wading through my past comments, and indeed those made by other E-E contributors, here are some external links that should cover the use of API calls to retrieve files via FTP:

http://vbnet.mvps.org/index.html?code/internet/ftpdownload.htm
http://vbnet.mvps.org/index.html?code/internet/ftpdownloadcallback.htm


BFN,

fp.
0
 
tcorbley2Author Commented:
I feel like 300 points awarded is fair, given that althought links were provided, no actual customized code was given. Please let me know if you think I'm off on this. This is the first question I have posted.
0
 
[ fanpages ]IT Services ConsultantCommented:
Well, it's usually the case that answers/solutions evole over the life of a question and should you need further information you request it.  No, I didn't post any code, but neither was I aware we had reached a satisfactory point in our exchanges where you were happy with a proposed solution.  I am conscious of wasting time flooding reams of code in threads until I am satisfied that an agreed approach has been decided, but either way, I'm not unhappy, and you believe you have all you need, so that's fine.

Not a problem.

BFN,

fp.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 5
  • 5
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now