UNIX automation

Hello People,
I have an outstanding issue with me
I have 5 files at location /usr/abc called

1.DE 1.TXT
2.DE 2.TXT
3.DE 3.TXT
4.DE 4.TXT
5.Fe.ok

My work involves few manual process like
transfer
1.DE 1.TXT and
5.Fe.ok to
/usr/dob location and run one script(for example - my_script.ksh) which executes both above 2 files. As soon as that is finish, i need to transfer
2.DE 2.TXT AND
5.Fe.ok to /usr/dob location and run one script again.
This process continues until the last file called
4.DE 4.TXT and 5.Fe.ok are not completed.

Here
5.Fe.ok is the common file which need to be transferred all the time.

I want a automated script which will do the above process.

Automated script process -

Transfer
1.DE 1.TXT and
5.Fe.ok to
/usr/dob location from /usr/abc and run my_script.ksh.
If success transfer next set
2.DE 2.TXT AND
5.Fe.ok
and so on.................

If fails throw an ERROR...

Please help...

---------- Post updated at 04:39 PM ---------- Previous update was at 04:33 PM ----------

sorry missed one more thing..
Also if first set fails it should not transfer the second set, it should throw an error and come out of the loop.Same goes on with 2nd 3rd and 4th..

Please state:
What Operating System you have.
What Shell you are using.
What is in the scripts.
What you type to execute those scripts, making it clear which computer you are typing on at the time if there is more than on computer involved.
Any error messages. Please report error messages exactly not just as "error".

Its Linux OS...
Its pure Unix scripting i was talking about...

When you "transfer" what do you actually type?

from /usr/abc prompt i type

cp 1.DE 1.TXT 5.Fe.ok /usr/dob 

Perhaps this is the sort of script you are looking for. Script is untested.
Note that "break" stops the whole process. If you want to try the next pair of files, replace "break" with "continue".

I have assumed that you have a Bourne-type script like "bash".

for filename in "1.DE 1.TXT" "2.DE 2.TXT" "3.DE 3.TXT" "4.DE 4.TXT"
do
        if [ ! -f "${filename}" ]
        then
                echo "File missing: ${filename}"
                break
        fi
        filename2="5.Fe.ok"
        if [ ! -f "${filename2}" ]
        then
                echo "File missing: ${filename2}"
                break
        fi
        #
        cp "${filename}" /usr/dob
        cp "${filename2}" /usr/dob
        /pathname/my_script.ksh; ERROR=$?
        if [ ! ${ERROR} -eq 0 ]
        then
                echo "Error from /pathname/my_script.ksh"
                break
        fi
done

The above script doesnt work.
What i mean to say is if i execute the above code without

/pathname/my_script.ksh; ERROR=$?
        if [ ! ${ERROR} -eq 0 ]
        then
                echo "Error from /pathname/my_script.ksh"
                break
        fi

Your script simply transfer all the files 1.DE 1.txt" "2.DE 2.txt" "3.DE 3.txt" "4.DE 4.txt and 1.DE 1.txt" "2.DE 2.txt" "3.DE 3.txt" "4.DE 4.txt to the location 1.DE 1.txt" "2.DE 2.txt" "3.DE 3.txt" "4.DE 4.txt.
I dont want this to happen..

Are you intending to automate the run of "my_script.ksh" or run it manually? The script I posted assumes that you will run it automatically.
I guess that "my_script.ksh" will need to take filenames as parameters.

It would help id we could see "my_script.ksh".

Its just that i need to transfer the set, then run my_script.ksh.
My script will only check it the 2 files are available or not...if yes it will finish and exit..
Then again i cp second set and again run my_script.ksh..

Yes ofcourse my_script is taking 2 filenames as it parameter...

I hope this will help you...

In my posted script the call of "my_script.ksh" is inside the do-done loop and will be executed each time a each pair of files are copied.
I thinks that all you need to do is to adjust the call to "my_script.ksh", though it does depend on what is in the script and whether it contains relative or absolute pathnames.

---------- Post updated at 12:40 ---------- Previous update was at 11:15 ----------

I might be understanding the problem.

Are there actually 9 files ? i.e. Are say "1.DE" and "1.TXT" separate file names?

@ Methyl

could be shorten a little like

for i in 1 2 3 4
do
    if [ ! -f "$i".DE || ! -f "$i".TXT} ]
    then
        echo "Err : file missing"
        break
    fi
    cp "$i".{DE,TXT} 5.Fe.ok /usr/dob
    if ( ! /pathname/my_script.ksh >/dev/null )
    then
        echo "Err : my_script.ksh execution error"
        break
    fi
done

I think that crsgnb has cracked it. We must assume that there are 9 files (not 5 files) and that the O/P has a modern "bash" Shell.
(the ".ksh" is omninous).

Thanks Methyl...The for loop script is working pretty fine..
Just another question on the same front...
It will be ok is i have 3 or 4 file, so as per your script we can put 3 file names in the for loop but its not fesible if there are more then 50 or rather 100 files. It will be highly impossible to put all the file names in the for loop.. Any suggestion in the regards or may be the script if u have.......

---------- Post updated at 04:40 PM ---------- Previous update was at 04:15 PM ----------

Sorry i didnt get you..Waht do u mean by "I think that crsgnb has cracked it."

instead of

for i in 1 2 3 4
do
...
done

go for a while loop

i=0
while [ $i -lt 100 ]
do
...
let i++
done

But if i go for a while loop how will the script come to know which file to pick
File as in

 1.DE 1.TXT
2.DE 2.TXT
3.DE 3.TXT
4.DE 4.TXT
5.Fe.ok 

IF i write a script like below it gives an error as File missing: 0

filename=0
while [ $filename -lt 100 ]
do
        if [ ! -f "${filename}" ]
        then
                echo "File missing: ${filename}"
                break
        fi
        filename2="5.Fe.ok"
        if [ ! -f "${filename2}" ]
        then
                echo "File missing: ${filename2}"
                break
        fi
        #
        cp "${filename}" /usr/dob
        cp "${filename2}" /usr/dob
        /pathname/my_script.ksh; ERROR=$?
        if [ ! ${ERROR} -eq 0 ]
        then
                echo "Error from /pathname/my_script.ksh"
                break
        fi
done

Pls comment....................

---------- Post updated at 12:41 PM ---------- Previous update was at 11:30 AM ----------

Any replies will be appreciated..

We are having trouble understanding what you want.

What do you expect to type at the keyboard, and what do you expect to happen?
Will there be one run of the script or many runs of the script?
Will all the files be present when the script starts?

OK let me explain again
I have 5or any number of files at location /usr/abc files name can be anything....
But there will be one fixed file called Fe.ok file.
I want to automate the below process...
Automated script process -

Transfer
1st file (any name) and
Fe.ok to
/usr/dob location from /usr/abc and run my_script.ksh.
If success transfer next set
2nd file AND Fe.ok
and so on.................

If fails throw an ERROR...

Earlier u gave me a solution where the file name where known with fixed name..
What if the file name changes but stil i want to pick those file one by one from top to botton with one fixed file Fe.OK transfer them to another directory and run my_script.ksh...Earlier solution was to put the file name in for loop..It is sensible if there are 6 files, i can put those file names in for loop, but what if there are 100 files then it becomes impossible for me to put 100 files name in the for loop...

Something like this ?

i=0
while [ $i -lt 100 ]
do
    filename=$i.DE
    filenametgt=$i.TXT

        if [ ! -f "${filename}" ]
        then
                echo "File missing: ${filename}"
                break
        fi
        filename2="5.Fe.ok"
        if [ ! -f "${filename2}" ]
        then
                echo "File missing: ${filename2}"
                break
        fi

        cp "${filename}" /usr/dob/${filenametgt}
        cp "${filename2}" /usr/dob

        if ( ! /pathname/my_script.ksh >/dev/null 2>&1 )
        then
                echo "Error from /pathname/my_script.ksh"
                break
        fi
    let i+=1
done

If you don't want to process files in an incremental way, you can just scan the files that are present, sort them by "number" and process them.
something like

ls -1 !(*.Fe.ok) | sort -k 1n | while read a
do
        [[ $(ls *.Fe.ok 2>/dev/null | wc -l) -ne 1 ]] && echo "no uniq *.Fe.ok file found" && break
        cp $a *.Fe.ok /usr/dob/
        if ( ! /pathname/my_script.ksh >/dev/null 2>&1 )
        then
                echo "Error from /pathname/my_script.ksh"
                break
        fi
done

i apolize,
the file name i mention was a bit wrong because of that you wrote
filename=$i.DE
filenametgt=$i.TXT

My files are like

1.DE.1.TXT
2.DE.2.TXT
3.DE.3.TXT
4.DE.4.TXT
5.Fe.ok

The file may increase it can be 10 as well or 20 as well...
What if the files are in sequence and suddenly found that after 10. directly 12 and so on files are available.

Can you please provide a proper code for the same

I didn't test it but maybe something like

chk_file(){
RC=0
[[ ! -f "$1" ]] && echo "File missing: $1" && RC=1
return $RC
}

i=0
while [ $i -lt 100 ]
do
    filename="$i.DE.$i.TXT"
    filename2=$(ls *.Fe.ok | tail -1)
        
    chk_file "${filename}" || break
    chk_file "${filename2}" || break

    cp "${filename}" "${filename2}" /usr/dob

    if ( ! /pathname/my_script.ksh >/dev/null 2>&1 )
    then
            echo "Error from /pathname/my_script.ksh"
            break
    fi

    let i+=1
done

if you have

0.DE.0.TXT
1.DE.1.TXT
...
10.DE.10.TXT
12.DE.12.TXT

when processing for i from 0 to 10, it should go fine, then let i+=1
so i=11
so it will try to process the loop for i=11
chk_file will find $filename (11.DE.11.TXT) is missing and will return 1 so the script will break out of the while loop

and the script will finish without processing the 12.DE.12.TXT (even if present)