Script Execution

Hello all,

I generally get 6 or more files at location /usr/example.Files listed below

er 1 2 3 9.txt
er 2 2 3 9.txt
er 3 2 3 9.txt
er 4 2 3 9.txt
abc.next
del pa.txt
cr ad.txt
ps tr as er.txt

Now the issue is i need to transfer 2 files (one file is fixed called abc.next) at a time to a location /bin/sam and execute them one by one.For example see below

1st set for execution contains 
er 1 2 3 9.txt
abc.next
 
2nd set 
er 2 2 3 9.txt
abc.next
 
3rd set
er 3 2 3 9.txt
abc.next
 
and so on...

This is pretty manual process as i need to transfer 2 file from /usr/example to /bin/sam everytime and execute.

I need to automate this..

Any suggestion will be welcomed

if the file names what you have written above will remain same ...
then you can do something like this :-

fofo = 0
for file in ls
do
fofo=`fofo +1`
if [[ `ls er $fofo 2 3 9.txt`
then
cp er $fofo 2 3 9.txt ./bin/sam
cp abc.net ./bin/sam
fi
done

i am assuming that the files that you are trying to send have a name like " er 1 2 3 9.txt" and they will remain in the same format apart from the first numeric variable being incrementing.
if u want it to automate it more than this. then you can put this script in cron and run after some continous intervals.

As per the above script, do i have to simply run it at the prompt.
I mean will it pick first two files and then run it or what..
i didnt get it..

---------- Post updated at 03:46 PM ---------- Previous update was at 03:42 PM ----------

i mean what i do is transfer the 2 file from /usr/example to /bin/sam and then run my script so that it will process the two file and reflect the application and database.

After running my script the two file which were transferred are automatically deleted via my script from that location..

---------- Post updated at 03:53 PM ---------- Previous update was at 03:46 PM ----------

I will write the pattern again

transfer 1st set of files from /usr/example to /bin/sam

er 1 2 3 9.txt
abc.next

Then i will execute ok.ksh which will reflect app and database and delete these 2 files.

Next i will do is again transfer 2nd set of files from /usr/example to /bin/sam

er 2 2 3 9.txt
abc.next

Then again i will execute ok.ksh which will reflect app and database and delete these 2 files.
An so on.................

i need to automate this..
i wont put it in cron but need a script for the same..

Do you mean something like this:

ls -rt /usr/example/er* | while read i
do 
  cp "$i" /usr/example/abc.next /bin/sam
  /bin/sam/ok.ksh
done

So that they get processed oldest first, or do you keep some kind of counter?

you can run any of the above 2scripts. the one made by me or 1 made by scrutinizer.

copy these scripts in any of the files and then execute that file.
keep the script made by me or scrutnizer in /usr/example.

and lets say once you transfer the files to /bin/sam and then you have to run a script named db_del (which reads these 2 files and deletes it from directory) u can do something liek this....

fofo = 0
for file in ls
do
fofo=`fofo +1`
if [[ `ls er $fofo 2 3 9.txt`
then
cp er $fofo 2 3 9.txt ./bin/sam
cp abc.net ./bin/sam
/bin/sam/db_del.ksh
fi
done

and in scrutnizer case db=del = ok script is already running.

@dazdseq Your script contains many many logic errors, syntax errors, false assumptions, omissions, and silly typing mistakes (e.g. extra space characters on line 1).
At a fundamental level, any script using the construct "for file in `ls`" will not work if any of the filenames contain space characters.

Scrutinizer's script looks ok and illustrates how best to deal with filenames containing space characters. It might need minor enhancement to delete the data files from the target directory ... unless that is done already in /bin/sam/ok.ksh .

Now iam confused..what is to be done..

---------- Post updated at 11:07 AM ---------- Previous update was at 11:05 AM ----------

I hope the scenario is clear for everybody.
Can anyone re-write the whole script again pls....

Source=/usr/example
Dest=/bin/sam

cd $Source
cp abc.next $Dest

find . -type f ! -name abc.next|while read i
do
  cp "$i" $Dest
  $Dest/ok.ksh
  rm $Dest/"$i"
done

I do not understand your confusion. Just test my script for instance and see if it works for you.

but my ok.ksh is another location

---------- Post updated at 01:06 PM ---------- Previous update was at 12:58 PM ----------

Scrutinizer, can u pls re-write the script again if possible...

Well just change the script accordingly and change "/bin/sam to the directory where your script can be found (I do not know where that is)...

I had 3 files at /usr/sample location

er 1 2 3 9.txt
er 2 2 3 9.txt
abc.next

Tried your script.
Below is the error...

/bin/sam/my_script.ksh[37]: cd: /inb/trans: [No such file or directory]
/bin/sam/my_script.ksh[60]: /inb/proc/day_leed_2010-09-13.txt: cannot create [No such file or directory]
** my_script.ksh failed - SORT PROBLEMS.
cp: cannot stat `/bin/sam/abc.next': No such file or directory
mkdir: cannot create directory `/tmp/leed_uat.0913100858': File exists
/bin/sam/my_script.ksh[37]: cd: /inb/trans: [No such file or directory]
** my_script.ksh failed -  abc.next MISSING...
 

===============
my_script.ksh
It sort combine wat ever files are there in /bin/sam.
Then if reflects the application and database and the data is transferred.
During this stage it delete both the file available in /bin/sam for example (er 1 2 3 9.txt and abc.next) and my_script.ksh says feeding of the data is been completed.
but your script gives me error...
Any idea scrutinizer..............

---------- Post updated 09-14-10 at 11:41 AM ---------- Previous update was 09-13-10 at 12:40 PM ----------

Can any body comment on this pls....

There seem to be several errors

  • The script can not find /bin/sam/abc.next
  • Does the user that executes the script have sufficient access rights?
  • Do the directories exist?
  • /tmp/leed_uat.0913100858 cannot be created since it already exists.

You need to examine each of these error messages..

The error messages contain directories that are new to us, like /inb/trans and /inb/proc . So it can't be the output of just my script. I think you may need to publish your whole script or relevant parts and provide directory listings, if you cannot figure it out...