UNIX automation


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting UNIX automation
# 15  
Old 01-11-2011
But if i go for a while loop how will the script come to know which file to pick
File as in
Code:
 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
Code:
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..
# 16  
Old 01-11-2011
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?
# 17  
Old 01-12-2011
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...
# 18  
Old 01-12-2011
Something like this ?

Code:
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

Code:
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


Last edited by ctsgnb; 01-12-2011 at 05:36 AM..
# 19  
Old 01-12-2011
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
Code:
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

Last edited by Franklin52; 01-14-2011 at 05:26 AM.. Reason: corrected code tags
# 20  
Old 01-12-2011
I didn't test it but maybe something like

Code:
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

Code:
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)

Last edited by ctsgnb; 01-12-2011 at 06:33 AM..
# 21  
Old 01-12-2011
@j_panky
Please clarify if

1.DE.1.TXT is a 1 file
or 2 files 1.DE & 1.TXT
or 1 file DE.1.TXT

so in this case
Quote:
1.DE.1.TXT
2.DE.2.TXT
3.DE.3.TXT
4.DE.4.TXT
5.Fe.ok
its 4 .TXT + 1 Fe.ok
or 4 .DE + 4 .TXT + 1 Fe.ok ?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Automation using bots in Linux/UNIX ?

Hi folks, has any one attempted using bots for performing tasks in unix?please share if you faced any challenges thanks (1 Reply)
Discussion started by: tommy812
1 Replies

2. Post Here to Contact Site Administrators and Moderators

UNIX automation

I am using netteza server and i have a list of table names. I need to fetch all the data from these tables and need to create seperate zip files and store in a folder in the server. How can we automate this process. (1 Reply)
Discussion started by: nikhilthms97
1 Replies

3. Shell Programming and Scripting

Unix fdisk -l Automation

Hello Folks - Need help really ASAP. Iam trying to run this Shell command to get all the lists of partitions and disks from across all the servers. #!/bin/ksh _servers="" _out="/tmp/output.$$" _ssh=/usr/bin/ssh >$_out for s in $_servers do $_ssh $s fdisk -l >> $_out done ... (8 Replies)
Discussion started by: bkilaru
8 Replies

4. Homework & Coursework Questions

Mail Automation in UNIX

Hi Sir, I need unix code which will read data present in .xls file and should send an automated mails .when i place the .XLS file in a specific folder and run ***.sh from unix box Attached Excel file contains Subject , To , CC , Body (Paragraph 1) , Body (Paragraph 2) , Signature When i... (2 Replies)
Discussion started by: chaitanyaS
2 Replies

5. Shell Programming and Scripting

creating an automation process in unix .

hi i need shell script in ksh for the automation process in informtica. The automation process is like this . i have a folder in unix . when this folder gets updated (like if a file or files is/are added to the folder) an event in informatica is triggered and after the process is done in... (2 Replies)
Discussion started by: kumar8887
2 Replies

6. Shell Programming and Scripting

Simple Unix Automation

Hi, i'm a newbie with unix and shell scripting. I'm just trying to do a script to simply automate a unix task. This are the steps on what i want to just run on a simple shell script 1. go to a specific path (cd /folder1/folder2/) 2. edit and input a number on a file (file_id) then save exit... (6 Replies)
Discussion started by: soultransit
6 Replies

7. Shell Programming and Scripting

Test automation tool for UNIX ??

I am searching for a automation testing tool which I can use for most of the UNIX platforms (AIX, Linux, HP UX, Solaris). The installation process of the application in all platforms is almost same. Are you aware of any automation tool (like WinRunner for Windows) to solve my problem? (5 Replies)
Discussion started by: unmanju
5 Replies

8. UNIX for Advanced & Expert Users

automation of Informatica jobs using Unix

1.How will you do automation of Informatica jobs using Unix ? 2. How u run workflow from Unix? :) (2 Replies)
Discussion started by: kamesh83
2 Replies

9. Cybersecurity

FTP Automation Windows <> Unix <> Remote

Hi All, I am a newbie to unix and scripting. I need to do the following job: 1. Create a batch file in windows that will call a script in a remote unix box. 2. The script now ftp files from the Remote windows machine and get them back to the local windows. Actually, I have written the script... (3 Replies)
Discussion started by: Ankur
3 Replies
Login or Register to Ask a Question