I need help as to how to write a script in Unix for the following:
We have 3 servers;
The mainframe will FTP them to a folder. In that folder we will need the script to look and see if the specific file name is there and load it to the correct table.
If you have bash shell you could try something like this:
#!/bin/bash
FOLDER=./folder
TABLEA="File1|File2|File3"
TABLEB="File 4|File5|File6"
cd $FOLDER
shopt -s extglob
for file in *
do
case $file in
@($TABLEA))
echo "Load $file into table A"
# Process file here
;;
@($TABLEB))
echo "Load $file into table B"
# Process file here
;;
esac
done
eg:
$ ls folder
File 4 File1 File6
$ ./doload.sh
Load File 4 into table B
Load File1 into table A
Load File6 into table B
And if you have bash 4.0 you can use associative arrays:
FOLDER=./folder
declare -A proc
proc=( [File1]="A" [File2]="A" [File3]="A"
[File 4]="B" [File5]="B" [File6]="B" )
cd $FOLDER
for file in *
do
if [[ ${proc[$file]} ]]
then
echo "Load $file into table ${proc[$file]}"
# Process file here
fi
done