If you have sample ASPECT code that you would like to share with the public, please send it to me in an email and I will post it to this page with you attributed as the author. First, be sure to view the various sample scripts that were previously available on the Quarterdeck FTP server at this page. You will also want to look at the samples in the \Samples\ASPECT directory on your version 4.8 CD. If your CD is not handy, you can download the samples from Symantec here. This script is an example of how to receive a file using the Zmodem transfer protocol and demonstrates how to properly monitor the value of the $XFERSTATUS system variable when performing a file transfer. Similar logic can be used when sending a file. The example scripts for getfile and sendfile in the ASPECT help file do not show how to structure the script to check for the value of $XFERSTATUS when the transfer is complete. This information is important to have because the value of $XFERSTATUS is cleared when the variable is accessed after a file transfer has completed. This example, a modification of the above script, shows how to rename a downloaded file when using the Zmodem or Kermit protocols. These two file transfer protocols pass the name of the file to be transferred during the initial negotiation and ASPECT does not let you specify a filename for the downloaded file, as can be done with the other file transfer protocols. By monitoring the value of the $XFERFILE system variable, the script can learn the name of the file being downloaded and then copy it or rename it to a different value specified in the script. This script is a further modification of the above two scripts and shows how to handle and rename batch Zmodem or Kermit downloads, or can be used to continuously monitor for a download. This sample, provided by Hank Campbell from the Tek-Tips forum, shows how to perform Kermit downloads via an ASPECT script. Some people have encountered problems with $XFERSTATUS not returning the correct values with Kermit downloads, and Hank's script is a modification of another script that provided a workaround for this problem. This script provides a more in-depth example of scripting an FTP connection than the example in the help file or on Symantec's support site. The primary point of this script is to show how to verify a file was uploaded to the FTP site. This is because $FTPSTATUS does not necessarily return the true nature of the transfer with the FTP server. This script uploads a user-specified file to the FTP server, then retrieves the file listing and parses that text file for the file that was just uploaded. If the file is not found in the file list, then we know the transfer was not successful and error mitigation steps must be performed. Before running this script, you will need to assign values to the sConnection, sFile, and sPath string variables. This sample shows how to download all files from a specified directory on an FTP server by retrieving a file list and then downloading each file in succession. Before running this script, you will need to assign values to the sConnection and possibly the sPath (if downloading from a non-default directory on the FTP server) string variables. This script shows how to upload all files in a local directory to an FTP server. Before running this script, you will need to assign values to the sConnection and sLocalPath string variables. You may also need to assign a value to the sRemotePath variable and change the value of the sFileMask variable.. This script shows how to take the current date and create a filename of the format YYYYMMDD.TXT. The use of the %02d format specifier forces the day and month to always be two digits by adding a leading zero, if necessary. If you need to add or subtract a day from the current date, you can add or subtract 86400 from the value of $LTIME (after assigning the value of $LTIME to a long) before using the ltimeints command. Here is another date-related script. This sample requires that two strings be defined with the start and end dates you are interested in. The script computes each date between the start and end date, then transmits each date in MMDDYY format, one date per line. This is yet another sample script showing how to perform date manipulations. This file contains two functions that both return strings of the format MMDDYY. The first function accepts an integer argument and returns the date that many days in the past. The second function returns the first day of the previous month. Here is another script that shows how to perform some standard operations with dates. It includes functions that return the previous month in MMYY format and the first and last days of the previous month in MMDDYY format. This script is a modification of an example that can be found in the ASPECT help file. It reads data from columns 1 and 2 of an already-loaded Excel spreadsheet and terminates whenever the string "exit" is found in the first column of the row being accessed. This sample is based on the above script. It reads data from the first column of an Excel spreadsheet, then writes that data to the second column. It will exit whenever an empty cell is read from the spreadsheet. This example from Hank Campbell illustrates how to transfer data from a text file to an Excel 97 spreadsheet using DDE, as well as some Excel-specific DDE commands in action. This particular script is parsing OMPR227 log messages from a Nortel Network DMS 100 phone switch. Here is another DDE script from Hank for use with a DMS 100 switch. This particular example looks for OMPR 201 log messages, then transfers them to Excel via DDE. If you are performing DDE operations with Excel, you will want to review this script. Hank has also provided another sample script that illustrates DDE operations. This new example shows how to transfer data from an Excel spreadsheet to a text file using DDE. Here is one final example illustrating DDE operations. The script launches a second instance of Procomm Plus, which the first instance then makes a DDE connection with and requests the second instance run the hints script. This script was slightly modified from the script located in this technical bulletin. If you have further interest in this topic, I recommend reading item nine of this file. Please note that this script will only work with version 4.8 due to the the DDE server name changing from PW4 to PW5 with version 4.8. One problem with the way Procomm Plus is architected is that it is difficult to know which instance of the program you are communicating with if there are multiple windows in existence. Using the above script as a starting point, this example shows how one script run in a "parent" Procomm Plus window can launch two additional windows, then command each "child" window to run a script using DDE. This example, provided by Josh Buedel, accepts up to three strings and returns which of the three strings was first received during a specified time. It works by having three when target commands active at the same time. This is a great script to use if you are expecting more than one possible response from the system you are accessing. Bill Hillman sent in this script that can be used to capture output to a filename based on the date. The capture file is closed at midnight and then a new one is opened with the next day's date. You will need to modify the argument in the dial data command to be the Connection Directory entry that is dialed, as well as assign the proper values to fname and the set capture path command (if you wish the capture files to go somwhere else than Procomm's capture directory). Another ASPECT user recently sent me two additional scripts for working with DMS switches. The first script adds up to 640 line paks, or rts's up to 24 trunks at a time on the Nortel DMS-10. It is menu-driven. You will need a loop plug on your serial port to test it. This second script is for DMS-100 users that have an SDM and Telnet capability to the CM. It logs in to the SDM root user, telnets to the CM, logs in user "LOGS2" and automatically starts recording of cm, ms, pm, ext, and sdm logs. Easily modified to the logs of your choice. Some editing is required to put in userids and passwords in your SDM/DMS. Note that you must make a c:\tempfolder directory or change the path in the script. This script also starts an appending capture file that is stored in c:\tempfolder\tempDMSLOGS.txt. One question I see asked now and then is how to access a list of phone numbers or telnet connections listed in a text file. Here is an example script that shows how to open a text file, loop through line by line, and make a connection to each entry in the list. The fopen command references the file numbers.txt in the ASPECT directory, so you will need to modify this value to point to your data file. This script, provided by Ken Gentry, shows how to create a date-based filename for a capture file, open that capture file, and send a line of text containing the current date and time to the screen each minute, essentially adding a date and time stamp to the capture file output. This example also shows how to make use of the when userexit command to detect when a user has stopped the script and handle any necessary cleanup activities before the script is halted. This script demonstrates the mapisend command a bit more fully than the sample script in the ASPECT help file. This sample demonstrates how to send an email through Outlook rather than Procomm's mail client. Here is another mapisend sample, provided by Stuart Pearson. This example prompts for the necessary information using several dialog boxes, then sends the generated emails via Outlook 97. This sample is an example of how to create and send an email message through Procomm's mail client via an ASPECT script. ASPECT does not have a direct method to send an email, so you have two options. The first is to use the sendkey and sendkeystr commands to bring up the compose window while in mail mode and fill out the various fields. The other, slightly quicker, option is to use the dial command to compose a message to an email address already in your Connection Directory. That is the avenue I have chosen in the script above. This script assumes that Procomm Plus is already in mail mode when run. This script is a quick example of how to read data from a file which contains lines of tab-delimited fields and divide each field into a separate string. The example shows how to read records with three fields, but it can be easily modified to read records with more or less fields. Here is another example script from Hank Campbell. This sample shows how to read a structured text file, then output the various fields from the first file in a different order to a second file. You can also choose to skip certain fields as well. One question I see now and then is how to have a script open a capture file and close it later when the machine is unattended. This script is one way to perform this task. This script uses the waituntil command to pause the script until the specified time (4:30 PM in this case) arrives. It then opens the capture file, uses a second waituntil command to pause until 5:00, close the capture files, and the script then exits. This method works if you are not able to use the waitfor or when target commands to key off data that appears just before or in the beginning of the information you are wishing to capture. Bill Hillman sent in this script which captures the current screen to a unique filename every 60 seconds. This is another sample having to do with reading data from a file. This example uses the fread command to read a 2-byte field from records stored in a text file. This can be handy if the file in question is longer than what can be handled by a string in ASPECT (256 characters). The fseek command is used to position the file pointer at the correct offset into the file, fread is used to get the two characters, then a second fseek command is used to advance the file pointer to the two bytes in the next record. One thing to keep in mind when using this method is to account for the carriage return and line feed at the end of each line in the text file. One other gotcha I discovered is that no errors are reported when fread goes beyond the end of the file. To workaround this problem, the script checks if the string read from the file is null. If so, the end of the file has been reached. A recent project I worked on required me to be able to create and dial Dialup Networking connections on a few different version of Windows. Another ASPECT user once asked me if data structures could be created in ASPECT. They cannot directly, but you can "roll your own" by allocating a block of memory, saving different variables to assigned locations in that memory block, then reading them back when desired. See this page for some of the solutions I attempted. In the future, I will expand this so that linked lists can be easily used in ASPECT scripts. This sample looks to see if a particular Excel spreadsheet is loaded. If so, it brings the spreadsheet to the foreground. If not, and Excel is already running, then the Excel menus are manually driven using the sendkey and sendkeystr commands. If Excel is not active, then Excel and the spreadsheet are launched via the run command. The first two elseif clauses are not needed due to the third elseif clause being a more general case of those two specific cases. However, I decided to leave these cases in the script for demonstration purposes. This script was written on a machine with Excel 2000, so the script may need to be tweaked slightly for other versions of Excel. This example searches the Windows task list to find Outlook, brings it to the foreground, opens a new message, and places the focus in the Subject line. If Outlook is not running, the script launches it (using the default install location for Office 2000), then performs the same steps as above. You may need to adjust the value of the three pause commands so that the script either does not take too long or proceeds too quickly when run on your system. This script demonstrates how to read a text file, insert two separate strings to the end of a line of data using the fseek, finsblock, and fwrite commands, and then save the modified file. And here is a complementary script that shows how to delete a duplicate line (the two strings must be one after another) from a text file. This example, provided by Hank Campbell, offers another illustration of how to use the fseek command. The script reads a text file, reads each line of data, and compares it to previously-read data. An output file is created that contains each unique line of data from the input file, as well as the number of times each unique line occurred. The output is similar to the format used by the Unix uniq command. The script reads data from one file, then deletes identical lines from a second text file. Here is a function that strips all leading spaces from a string. If you use the strrev command to reverse the order of the string before calling this function and then use strrev again on the returned result, this function can then be used to strip all trailing spaces in a string. The strfind command only allows you to search for one string within another string. This function accepts a string of data you wish to search, a string containing a variable number of substrings to search for, the delimiter of the substrings string, and the number of substrings you are passing. A 1 is returned if a match was found, otherwise a 0 is the returned result. This function is very extensible as none of the values are hardcoded. This example is an enhanced version of the original mstrfind.was script. This update will pass back the index of the matched substring (if a match was found), so that the calling procedure can determine which of the various substrings was located instead of just knowing that a match was made. Here is yet another sample script from Hank Campbell. From the readme file "This script is used to perform DACS Conversions in a Telco Central Office. The System will require Verification of the Existing Crosspoints and then the Disconnect of the Old Configuration and then the Connect of the New Configuration." It also demonstrates some dialogbox functionality that may be of use to those who would like additional information. This example demonstrates how to make a manual connection to an FTP server that is not in your Connection Directory. It also serves to illustrate how to access Procomm's menu items from within a script. This script demonstrates some operations with both the Connection Directory and dialog boxes. The script reads all telnet entries from the current Connection Directory, then displays the names in a listbox in a dialog box. The user selects an entry, enters a password, and clicks on the Dial button to connect to the chosen entry. Further scripting of the connection process would be necessary for this script to have any use beyond a learning tool. It is possible to attempt a connection to all specified data entries using the CONNECTALL flag with the dial command, but this does not work with telnet entries. Based on code from the above script, I whipped up this quick script that shows how to iterate through all of the telnet entries in the Connection Directory and make a connection attempt to each of them. Here is another example involving the Connection Directory. This script accesses each data Connection Directory entry, turns on dialentry for that entry, then retrieves several settings for that entry using fetch commands. This information could then be transmitted to another machine, saved to a text file, and so forth. Using the set and fetch dialentry commands can be confusing at first, so this script is a handy example on how to use these commands. This script shows how to run the ipconfig command, save the output to a text file, and get the IP number of the machine the script is running on. Stuart Pearson provided this sample, which illustrates a method to allow easier detection of file errors in large scripts where many files are accessed during the script operation. It was designed to report errors in a script that contains over 13000 lines. The script adds an incrementing counter text string [debugcount=%d] prior to any file access statements (fgets or fputs) before recompiling the specified .was file. As long as the script processed by add debug.was contains a line to call an error procedure on result of the $errornum variable changing, it is possible to write the contents of the debugcount integer to an error file for further analysis. As the scripts uses strfind statements to identify the fputs or fgets, it is easy to change to allow detection of other aspect commands. The ZIP file contains three files - one which modifies the original script (add debug.was), the original file (debug1.was), and the modified script (debug2.was). Hank Campbell provided this script that takes a text file then splits into separate files that contain the number of lines specified in the code. Here is another sample from Hank Campbell. This script reads a text file, extracts a particular field from each line, sorts the lines of data based on the first letter of that field using a bubble sort, then saves the results to a new file. As Hank mentions in his readme file, the output is not necessarily in alphabetical order as the script just sorts based on the first letter in the string. Here is another example script from Hank that performs a similar function to the prior script, but the output is sorted based on the entire numeric field that the script is keying on. Mike Carl sent in this example that shows how to compare two text files, one containing "expected" results and the other containing "actual" results, then writes any differences to a third text file. If you would like your script to have the ability to create a ZIP file (using the PWZIP executable shipped with Procomm Plus), then this script is for you! This sample takes all .WAS files in your ASPECT directory and places them in C:\My Documents\BACKUP.ZIP. There is also a corresponding script that demonstrates how to uncompress a ZIP file. Both of these examples were inspired by code in the hostutil script. When zipping files, PWZIP is not able to handle spaces in the source path (this limitation is not present when unzipping files). To workaround this problem, you can use the shortpath command to convert the path to its 8.3 format equivalent. The first sample script does this if you would like to see an example. When modifying these scripts for your own use, be careful that you have the proper amount of backslashes separating the paths and files in the sCmdLine string variable. In other words, make sure you have the backslash defined in either the sCmdLine string (separating the %s format variables for path and file) or that you have the backslash in one of the path or filename string variables. When scripting Procomm Plus, there is not truly a good way to determine if Procomm Plus has access to the modem. This is mostly due to the program communicating to the modem through Windows' TAPI layer. This script offers a workaround to make sure that Procomm Plus is able to access a specified modem. It works by first using the set modem connection command to tell Procomm Plus to use a particular modem. It then turns on modem command mode to talk directly with the modem. If the commandmode command is successful, then we know we can access the modem. This example shows how to iterate through the modems installed on a system, displays a list of modems in a dialog, and lets one be selected. This companion script does away with the list of modems and just grabs the first available connection. Occasionally I am asked if it possible to have Procomm Plus disconnect or exit after a set period of time, either from when the program was started or if no data is received for a certain amount of time. This script will exit Procomm Plus ten minutes after it was run, while this script will close the program if no data is received within ten minutes. To disconnect instead of exit the program, change the pwexit command to disconnect. You can change the timeout values by replacing 600 in the when commands with the desired number of seconds. This example sends a carriage return when no data has been received after five minutes. It can be handy to "keep alive" a connection to a host with an inactivity timer. This script closes Procomm Plus when a telnet or data connection has been disconnected. This short script can be run if you want to keep Procomm Plus from closing as it normally would when a user exits the program. All the script does is loop endlessly, but the fact it is running at all will cause a message box to be displayed when the program is told to shut down. This message box will ask if all active scripts should be closed. If the user answers yes, then Procomm Plus will exit. However if they answer no, the script (and Procomm Plus) will continue running. A second option is to use the set aspect control on command, which will keep a user from closing a script or Procomm at all, short of rebooting the machine. This example from Hank Campbell demonstrates several useful pieces of functionality, including the use of the strtok and fstrfmt commands. This sample script from Gary Abott shows how to let a user specify the text on title bar of the current Procomm Plus window from within a script. This can be useful to differentiate one Procomm Plus session from another. Here is another example from Hank Campbell. It illustrates how to conditionally include functions from a .INC file. This script shows how to take the contents of a string and shift each character (A-Z and a-z) to the left, one at a time (A shifts to Z and a to z). This script is expecting only alphabetic data, so you would need to add additional checking so you did not convert a non-alphabetic character. This example searches the specified directory and deletes all but the latest file contained in that directory. Here is another example script from Hank Campbell. This sample shows how to print a text file via an ASPECT script. This function checks to see if a string contains only numeric characters or not, which can be useful for verifying phone numbers. This line of code can be used to check if a character whose ASCII value is stored in the integer variable iVal is a letter or not (values from 65 to 90 are uppercase, while 97 to 122 are lowercase): if (((iVal >=65) && (iVal <=90)) || ((iVal >=97) && (iVal <=122))) |
|
This document maintained by
John Schultz. Material
Copyright © 2002-2017 |