Need script for Itanium server

Hi,

I have a folder that has the below 6 files.

 
 
-rw-r-----   1 wlsuser    users        32203 May 16 09:41 card_10.77.200.100.csv
-rw-r-----   1 wlsuser    users       104119 May 16 09:42 card_135.57.206.116.csv
-rw-r-----   1 wlsuser    users        12412 May 16 09:42 card_10.141.29.144.csv
-rw-r-----   1 wlsuser    users        65171 May 16 09:42 card_10.87.162.211.csv
-rw-r-----   1 wlsuser    users        93162 May 16 09:43 card_10.112.68.10.csv
-rw-r-----   1 wlsuser    users        79674 May 16 09:43 card_10.87.225.156.csv

I want my script to run as below.

 
./Generateadd.sh -ip 10.77.200.100
.....
....
....
./Generateadd.sh -ip 10.87.225.156 

for all the 6 IPs one after the other finishes.

Can someone please help me with the script.

#!/bin/ksh

typeset chCmd="/path/to/Generateadd.sh -ip"
typeset pDir=/path/to/your/directory
typeset pFile=""
typeset chIP=""

ls $pDir | while read pFile ; do
     chIP="${pFile%.csv}"             # chop off the extension
     chIP="${chIP#card_}"             # chop off the leading "card_"

     $chCmd $chIP
done

exit 0

It is a bad idea to have relative paths in scripts, so i changed ./Generateadd.sh to a call with the absolute path. If you use relative paths in scripts that means the script will work in one directory but not in another.

I hope this helps.

bakunin

I dont think this script will work if the file name is "card_xyz_something_something_10.87.162.211.csv"

So, what I would like is the "_" just before the IP address to be considered for chopping off anything prior to that so I am just left with the IP address.

Can you please help tweak it and get it working for me ?

You know what? Me neither. But it would have been a nice thing to define your problem correctly instead of letting me guess. I am a Sysadmin, being a psychic is not part of the job description.

Yes, i can. Replace:

     chIP="${chIP#card_}"             # chop off the leading "card_"

with this:

     chIP="${chIP##card_*_}"          # chop off the leading "card_" and everything up to the last "_"

I hope this helps.

bakunin