Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple script but it's making me crazy 1

Status
Not open for further replies.

icu812

MIS
Sep 10, 2001
52
US
Input script (oradbproc3.lis)looks like this:
sp18cw:tnslsnr TRN::The DB Listener process on SP18 is down:
sp18cw:FNDLIBR:appltrn:The TRN Concurrent Manager process on SP18 is down:

Korn shell script looks like this:
for line in `cat /bin/danka/oradbproc3.lis`
do
SERVER=`echo "$line"|cut -f 1 -d :`
PROC=`echo "$line"|cut -f 2 -d :`
USER=`echo "$line"|cut -f 3 -d :`
MAILMSG=`echo "$line"|cut -f 4 -d :`
echo $SERVER
done

My problem is that the cut command does not seem to be working as it should. Anyone got any suggestions before I decide to quit this business and open up a hot dog stand somewhere???(Just kiddin, it's not that bad...yet) Thanks
 
Which cut statement? You have four.
Can you show the output/values for your variables
vs what you are expecting.

I am a litte better with awk than cut,
so I will show you another way to do it
since youre fields are already delimited
with :

I am assuming your input script is actually a config/data file

SERVER=`echo "$line"|awk -F: '{print $1}'`

just change the $1 to $2, $3, etc for
whatever field you want grab
Robert G. Jordan
Unix Sys Admin
Sleepy Hollow, Illinois U.S.A.
sh.gif


FREE Unix Scripts
 
icu812:

You're K shell is probably having setting the IFS to white space. You might try something like this:

IFS='&' # some char other than whitepace not being used
for line in `cat /bin/danka/oradbproc3.lis`
do
SERVER=`echo "$line"|cut -f 1 -d:`
PROC=`echo "$line"|cut -f 2 -d:`
USER=`echo "$line"|cut -f 3 -d:`
MAILMSG=`echo "$line"|cut -f 4 -d:`
echo $SERVER
echo $PROC
echo $USER
echo $MAILMSG
done

But if it were me, I'd do something like this:

IFS=':'
while read SERVER PROC USER MAILMSG
do
echo $SERVER
echo $PROC
echo $USER
echo $MAILMSG
done < /bin/danka/oradbproc3.lis

Change my field separator to &quot;:&quot; and read in each argument.

Regards,


Ed
 
Try :-

#!/bin/ksh
cat /bin/danka/oradbproc3.lis | while read line
do
SERVER=`echo &quot;$line&quot;|cut -f 1 -d :`
PROC=`echo &quot;$line&quot;|cut -f 2 -d :`
USER=`echo &quot;$line&quot;|cut -f 3 -d :`
MAILMSG=`echo &quot;$line&quot;|cut -f 4 -d :`

echo SERVER = $SERVER
echo PROC = $PROC
echo USER = $USER
echo MAILMSG = $MAILMSG
done
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top