UNIX automation


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting UNIX automation
# 22  
Old 01-12-2011
Can you post a directory listing. We all seem to be having trouble understanding the filenames because they appear different in different posts.
Code:
ls -la


As others ask, do you want the script to search the directory and automatically copy the files? Also, what happens the second time the script is run?
# 23  
Old 01-13-2011
@xoops--
1.DE.1.TXT is a 1 file
2.DE.2.TXT is a second file and so on..and One Fe.ok
There can be multiple files may be till 100 also.
All are one file..
In previous post they were also one file but with a space between them like 1.DE 1.TXT (This is one file i.e filename is with space)...
Now what all contains in the Direcetory
Code:
1.DE.1.TXT
2.DE.2.TXT
3.DE.2.TXT
4.DE.2.TXT
5.DE.5.TXT
6.DE.6.TXT
7.DE.7.TXT
Fe.ok

Can contain any number of files starting with one two three numbering and can contain any other file name (for example 92.xoops.txt)...
My concern is if i use for loop then i cant put all these file name in the for loop.What can be the solution..
also if one file is missing (for example from 1 to 20 files are in sequence, and suddenly 21 file is not available and drom 22 to 100 files are present, in that case the script will fail)..
Hope this clears all the doubt....pls provide the script...
# 24  
Old 01-13-2011
Help us to help you ...

At the biginning, you talked about files like :
1.DE 1.TXT (without telling us if it was 2 distincts files or 1 filename containing a space, so we had to ask for this information)
then you changed for filename like :
1.DE.1.TXT
and now you tell us that the filename could also be
92.xoop.txt

If the structure of the filename change at every post, it becomes difficult to provide an accurate help to you.
This is why it is important that you take the time to fully explain your requirement.

... so :

1) do you confirm that all your files do have a name like :

Code:
<a_number><a_dot><a_random_string>

like :

Code:
1.gjsdlfjds
2.fsdjklmghsj
3.fjdksfdsq
4.xoop.txt
5.DE.5.TXT
6.DE.6.txt
92.gjefdlkghlmdsjgld
...

when you state "in that case the script will fail" <---- this is not clear

"in that case the script should fail but currently doesn't
" <---- this is a clear statement
"in that case the script currently fails whereas i wish it would continue" <---- this is a clear statement

2) What do you want to happen if a number is missing in the sequence ?

a) Do you want the script to continue to the next sequence number ?
or
b) Do you want the script to abort ?

Please be clear about your requirements.

Last edited by ctsgnb; 01-13-2011 at 05:06 AM..
# 25  
Old 01-14-2011
@ctsgnb Apologize.
I confirm that the file name are like :
Code:
<a_number><a_dot><a_random_string>

1.gjsdlfjds
2.fsdjklmghsj
3.fjdksfdsq
4.xoop.txt
5.DE.5.TXT
6.DE.6.txt
92.gjefdlkghlmdsjgld

OK...Now if any number is missing it should check for the next number if it is present then the script should continue and if not then it should come out of the loop sayin hmmm next number not present or what ever echo message....

---------- Post updated at 11:40 AM ---------- Previous update was at 11:30 AM ----------

Also please put a check in your script like
if there is a file (may be adc.dat) at some xyz location (/usr/xyz) remove that file and then start your script....
# 26  
Old 01-14-2011
I didn't try it, but maybe something like this :

Code:
flag="/usr/xyz/abc.dat"
[[ -f "$flag" ]] && rm -f "$flag"

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

i=0
while [ $i -lt 100 ]
do

     if [ $(ls $i.* | wc -l 2>/dev/null) -gt 1 ]
     then
          echo "Error : more than 1 File found starting with increment $i, script aborted"
          exit 1
     fi

     filename=$(ls $i.*)
     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

# 27  
Old 01-21-2011
@ctsgnb - Thanks the above script of yours is working fine but there is one issue in it....

It reads all the file properly like it is reading 1.gjsdlfjds, 2.fsdjklmghsj, 3.fjdksfdsq, 4.xoop.txt, 5.DE.5.TXT but is the 6th file is not there and the 7th file is available it thros and error saying ls: 6.*: No such file or directory and the loop get over and it doesnt read the 7th file..
Also i have 15th file as well it doesnt go there as well...
Sequence of files are
Code:
 1.NL_DEMAND1.DAT
2.NL_DEMAND.DAT
3.NL_DEMAND3.DAT
4.NL_DEMAND4.DAT
5.NL_DEMAND4.DAT
7.NL_DEMAND4.DAT
15.NL_DEMAND4.DAT

# 28  
Old 01-21-2011
Lot of stuff, maybe this give some ideas
Code:
#!/usr/bin/somesh   (ksh, bash, dash, ...)
# doit
pwd=$PWD

for f in $@
do
        case "$f" in
                *.ok) continue ;;
                +([0-9]).*) ;;  # file starting with number dot ... are interesting
                *) continue ;;  # something else ...
        esac

        IFS="." arr=($f)  # split filename to array using .
        f1="${arr[0]}"    # take 1st field

        okfile=$f1.Fe.ok  # ok filename
        if [ -f "$okfile" -a -f "$f" ]   
        then
                cp "$f"  "$okfile"  to_dest
                cd to_dest
                ./some_script
                ERROR=$?
                ((ERROR > 0 )) && echo "$f" && exit $ERROR
                 cd $pwd
        else # no ok file, ??? or $f is  not file
                :
        fi
done

And using
Code:
chmod a+rx doit
errfile=$(./doit *  )
echo "exit status:$? and file:$errfile "

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