Hi here is my script I need some feedback. I am using AIX (kshell) version 4
Here is what I want to do. I want to poll a folder on the server for *.dat files. For each file I want to store its name in a variable and rename the file.
Then call a script . This script generates a file namely cleansedfile. I want to rename it to the name in the variable.
Then send it to other server in the internal network. Only working solution will be awarded points.
Thanks for viewing this.
------------------
tempfile_name # declare a variable
loop 3 begin
ftpconnect("oracle07", 229, "uid", "pwd");
if(success eq ftpresult) begin
exitloop;
end else begin
waitsecs(10);
end
end
# Check if the ftpconnect command was successful.
# If the connect was not successful, print out an error
# message and end the script.
# NOTE: loop, if, and foreach statements must contain
# enclosing "begin" and "end" blocks.
if(success ne ftpresult) begin
print("ERROR: could not connect to server after 3 attempts");
endscript;
end
# Set the desired local and remote paths
# NOTE: "local" and "remote" are keywords used to denote the local
# and remote computers respectively.
# NOTE: Since "\" is also used as an escape character to specify
# printable quotes, local paths may be specified using a
# double backslash like "c:\\myfolder"
ftpsetpath(local, "..\tril6v0\\Projects\\dev
\\demo\\")
;
if(success ne ftpresult) begin
print("ERROR: could not set local path");
ftpdisconnect();
endscript;
end
ftpsetpath(remote, "\\oracle07\intfc\dj\sap\h
r\");
if(success ne ftpresult) begin
print("ERROR: could not set remote path");
ftpdisconnect();
endscript;
end
# If passive mode transfers are required, enable passive mode
enablepasv();
# List the contents of the remote folder. In order
# to be able to manipulate this list in the future,
# we store it in a variable.
# Any name can be chosen for this variable, but the first
# character must be "@". eg. @my_list
ftpgetlist(remote, @my_list);
if(success ne ftpresult) begin
print("ERROR: could not list the contents of the current path");
ftpdisconnect();
endscript;
end
#print out the number of items that are in the list
print("The remote folder contains ", @my_list.count, " items");
# Set the transfer type to auto. Valid keywords are "ascii",
# "binary" and "auto".
# Also, set the rules to use if a duplicate file already exists
# in the destination path. The files may be compared by size or
# by date. This is indicated by the keywords "bysize" or "bydate".
# The following rule keywords may be specified: "resume", "rename"
# "overwrite", and "skip". Refer the help manual for the syntax of
# the "setduperules" macro.
settransfertype(auto);
setduperules(bysize, overwrite, skip, skip);
# We can now pick each item in the list and decide whether we
# need to download it. This is accomplished by the "foreach"
# statement. Any name can be chosen for the variable that denotes
# each individual item, but the first character must be "$".
# eg. $my_item
# For each item, check if it is a file. If so, check if the name
# matches the wildcard "*.txt". If so, download the file to the
# local folder, and delete it from the remote server.
foreach $my_item in @my_list begin
if(false eq $my_item.isfolder) begin
if("*.dat" eq $my_item.name) begin
#ftpdownload(file, $my_item.name);
#if(success eq ftpresult) begin
# # ftpdelete(remote, file, $my_item.name);
#end else begin
# print($my_item.name, " ", "could not be downloaded");
#end
tempfile_name = $my_item.name #store the file name in a variable
rn $my_item.name sap_file.dat #rename the file to the projects required file name
sap_demo.sh #call the other script that generates the file "cleansedfile"
rn cleansedfile tmpfile_name #rename the cleansed file to a variable name
#now send this file to other server on the network.
end else begin
print($my_item.name, " ", "does not match *.dat");
end
end else begin
print($my_item.name, " is a folder");
end
end
# Finally, disconnect from the remote ftp server
ftpdisconnect();
# we can now finish the script. Since this script has been
# scheduled as a recurring task, it will be run again
# after 5 minutes.
endscript;