Operating System - HP-UX
1838671 Members
6246 Online
110128 Solutions
New Discussion

cstm scripting like ftp scripting...

 
SOLVED
Go to solution
Bill McNAMARA_1
Honored Contributor

cstm scripting like ftp scripting...

Hi, I've got a program that does something like cstm diagnostics on specific hardware.

I'd like to add some standard commands to a script and output the result to file.

in ftp we'd have
ftp $HOST << EOFTP
ls
bin
prompt
mget *
bye
EOFTP

now I'd like to run a script
that'd in the case of cstm as an example run
cstm << EOCSTM > /tmp/out
map

cat /tmp/out| grep CPU | awk '{ print $1 }' > /tmp/cpu_id

for i in $(cat /tmp/cpu_id)
do
sel $i
info
done
EOCSTM

Now, the thing I'm having the problem with is adding script analysis to the application command. It seems to think that the commands are invalid, even though they work on standard input. Some of the commands work, those without the variable substitution.

An similar example would be like doing an ftp but say ftp'ing iles in binary or ascii let's say depending on their extension..

Any ideas?

Later,
Bill
It works for me (tm)
15 REPLIES 15
Sridhar Bhaskarla
Honored Contributor

Re: cstm scripting like ftp scripting...

Bill,

See if this works.

cstm << EOF > /tmp/out1$$
map
quit
OK
EOF
for i in `cat /tmp/out1$$|grep CPU |awk '{print $1}'`
do
echo $i
cstm << EOF >> /tmp/out2$$
sel device $i
infolog
quit
OK
EOF
cat /tmp/out2$$

rm /tmp/out1$$ /tmp/out2$$
done
-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Sridhar Bhaskarla
Honored Contributor

Re: cstm scripting like ftp scripting...

Hi (again) Bill,

Small modification in the above. I am a bad cleaner.

....
infolog
quit
OK
EOF
done

cat /tmp/out2$$
rm /tmp/out1$$ /tmp/out2$$

---End of the Script---

You can use /tmp/out2$$ if you want somewhere.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Robin Wakefield
Honored Contributor

Re: cstm scripting like ftp scripting...

Hi Bill,

You'll have to do it in 2 stages, e.g.

========================================
cstm << EOCSTM > /tmp/out
map
EOCSTM

cat /tmp/out| grep CPU | awk '{ print $1 }' > /tmp/cpu_id
echo 'cstm << EOCSTM' > /tmp/cpu_id.out
for i in $(cat /tmp/cpu_id)
do
echo sel dev $i >> /tmp/cpu_id.out
echo infolog >> /tmp/cpu_id.out
echo done >> /tmp/cpu_id.out
done
echo EOCSTM >> /tmp/cpu_id.out
chmod 755 /tmp/cpu_id.out
/tmp/cpu_id.out

==========================================

Rgds, Robin.
Bill McNAMARA_1
Honored Contributor

Re: cstm scripting like ftp scripting...

mmm, it seems that my shell goes somewhere!! after the cstm thus, the first part works in both of your examples... but the second part doesn't.. I put huge sleeps in the script and it made no difference.. in fact the sleep is ignored and just about everything after the first section.

Did you actually try it?
I'm sure you'll see the same...

Here's one of your example scripts run with an set -x.
(I'm seeing the same on both examples)

cat /tmp/out| grep CPU | awk '{ print }' > /tmp/cpu_id
echo 'cstm << EOCSTM' > /tmp/cpu_id.out
for i in + cat /tmp/cpu_id
+ cat /tmp/cpu_id
cat: Cannot open /tmp/cpu_id: No such file or directory

do
echo sel dev >> /tmp/cpu_id.out
echo infolog >> /tmp/cpu_id.out
echo done >> /tmp/cpu_id.out
done
echo EOCSTM >> /tmp/cpu_id.out
chmod 755 /tmp/cpu_id.out
/tmp/cpu_id.out
It works for me (tm)
Volker Borowski
Honored Contributor

Re: cstm scripting like ftp scripting...

Hey Bill,

not sure on which release you are, my cstm does not have a "sel" command, but here goes (untested though!):

echo map\\nexit | cstm | grep CPU | awk '{ print "sel " $1 "\ninfo" }' && echo exit | cstm

This should do it, but I recommend to test
first:

echo map\\nexit | cstm | grep CPU

and

echo map\\nexit | cstm | grep CPU | awk '{ print "sel " $1 "\ninfo" }' && echo exit

Which output should look like the cstm-commandfile you like to have. Check out, if you really want to leave cstm with exit (the one I have did not know "done")

Hope this helps
Volker
Frank Slootweg
Honored Contributor

Re: cstm scripting like ftp scripting...

The commands between "cstm << EOCSTM > /tmp/out" and "EOCSTM" must be cstm commands. Now you have both cstm and UNIX/shell commands. Of course cstm does not understand the UNIX/shell commands.

I think you will need two cstm runs in your script, one to get the /tmp/out file and another to run the cstm commands you extracted from the /tmp/out file. The latter part can be probably be done with something like:

{
...
echo $cstm_command1
...
echo $cstm_command2
...
echo done
} cstm

The "..." parts can be any shell commands/construct, including loops, etc., as long as the result get into the $cstm_command parameters.

All of this assumes that cstm has no problem with timing issues when reading from a non-interactive input. If it has, you will need something like the public domain 'expect' command as well.

I hope this helps.



Sridhar Bhaskarla
Honored Contributor

Re: cstm scripting like ftp scripting...

I don't know why my script is not working for you. It's working here. I don't know what version of cstm you have.

The first part is only to map. So, it works.

The second part is tricky as it calls sel and infolog. So dependending on the version of cstm you have, you may need to replace the corresponding commands.

As long as we don't include normal shell commands within the markers of cstm, it should work.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Robin Wakefield
Honored Contributor

Re: cstm scripting like ftp scripting...

Hi Bill,

Is /tmp/out being created?

How about /tmp/cpu_id (are you missing the $1 in the awk print statement?).

Rgds, Robin.
linuxfan
Honored Contributor

Re: cstm scripting like ftp scripting...

Hi Bill,


Have you already tried this?

echo 'selclass qualifier cpu;info;wait;infolog' | cstm > cstm.out

It gets the information for all the CPUs

I generally have aliases for this in .kshrc/.profile

cpucstm="echo 'selclass qualifier cpu;info;wait;infolog' | cstm "
memcstm="echo 'selclass qualifier memory;info;wait;infolog' | cstm "

All you need to get the information for CPU's in a log is
cpucstm > /tmp/cpucstm.out
for memory
memcstm > /tmp/memcstm.out

This works for STM versions as old as A.21.05

-HTH
Ramesh
They think they know but don't. At least I know I don't know - Socrates
Bill McNAMARA_1
Honored Contributor

Re: cstm scripting like ftp scripting...

in fact cstm is used as an example of the problem I'm seeing with another program.. although I am doing the test with cstm..

se sel class is no good.

cstm works normally, it's just the script that doesn't as shown above..

The $0 wasn't missing in the script.

I'll try again and post the script and output up.

Bill
It works for me (tm)
Bill McNAMARA_1
Honored Contributor

Re: cstm scripting like ftp scripting...

#!/usr/bin/ksh

set -x

cstm << EOCSTM > /tmp/out
map
quit
OK
EOCSTM

cat /tmp/out


cat /tmp/out| grep CPU | awk '{ print $1 }' > /tmp/cpu_id
echo 'cstm << EOCSTM' > /tmp/cpu_id.out

for i in $(cat /tmp/cpu_id)
do
echo sel dev $i >> /tmp/cpu_id.out
echo infolog >> /tmp/cpu_id.out
echo done >> /tmp/cpu_id.out
done

echo EOCSTM >> /tmp/cpu_id.out
chmod 755 /tmp/cpu_id.out
/tmp/cpu_id.out



--
Execution:
# /tmp/scr1.ksh
+ cstm
+ 0<<
map
quit
OK
EOCSTM

cat /tmp/out


cat /tmp/out| grep CPU | awk '{ print }' > /tmp/cpu_id
echo 'cstm << EOCSTM' > /tmp/cpu_id.out

for i in + cat /tmp/cpu_id
+ cat /tmp/cpu_id
cat: Cannot open /tmp/cpu_id: No such file or directory

do
echo sel dev >> /tmp/cpu_id.out
echo infolog >> /tmp/cpu_id.out
echo done >> /tmp/cpu_id.out
done

echo EOCSTM >> /tmp/cpu_id.out
chmod 755 /tmp/cpu_id.out
/tmp/cpu_id.out


1> /tmp/out


---

cat /tmp/out

Version A.22.00

Product Number B4708AA

(C) Copyright Hewlett Packard Co. 1995-1998
All Rights Reserved

Use of this program is subject to the licensing restrictions described
in "Help-->On Version". HP shall not be liable for any damages resulting
from misuse or unauthorized use of this program.

cstm>map
kibo.grenoble.hp.com

Dev Last Last Op
Num Path Product Active Tool Status
=== ==================== ========================= =========== =============
1 system system () Information Successful
2 0 Bus Adapter (582) Information Successful
3 0/0 PCI Bus Adapter (782) Information Successful
4 0/0/0/0 Core PCI 100BT Interface Information Successful
5 0/0/1/0 PCI SCSI Interface (10000 Information Successful
6 0/0/1/1 PCI SCSI Interface (10000 Information Successful
7 0/0/1/1.15.0 SCSI Disk (SEAGATEST39102 Information Successful
8 0/0/2/0 PCI SCSI Interface (10000 Information Successful
9 0/0/2/1 PCI SCSI Interface (10000 Information Successful
10 0/0/2/1.15.0 SCSI Disk (SEAGATEST39204 Information Successful
11 0/0/4/0 RS-232 Interface (103c104 Information Successful
12 0/0/5/0 RS-232 Interface (103c104 Information Successful
13 0/2 PCI Bus Adapter (782) Information Successful
14 0/2/0/0 PCI Bus Adapter (10110026 Information Successful
15 0/2/0/0/4/0 PCI 4 Port 100BT LAN (101 Information Successful
16 0/2/0/0/5/0 PCI 4 Port 100BT LAN (101 Information Successful
17 0/2/0/0/6/0 PCI 4 Port 100BT LAN (101 Information Successful
18 0/2/0/0/7/0 PCI 4 Port 100BT LAN (101 Information Successful
19 0/4 PCI Bus Adapter (782) Information Successful
20 0/4/0/0 Unknown ()
21 0/6 PCI Bus Adapter (782) Information Successful
22 0/6/0/0 PCI WAN Performance Inter Information Successful
23 8 MEMORY (9b) Information Successful
24 160 CPU (5d5) Information Successful
25 162 CPU (5d5) Information Successful
cstm>quit
-- Exit the Support Tool Manager --
Are you sure you want to exit the Support Tool Manager?
Enter Cancel, Help, or OK: [OK] OK


It works for me (tm)
Bill McNAMARA_1
Honored Contributor

Re: cstm scripting like ftp scripting...

Frank your suggestion was close, but when generating the commands sel device $i
the next command must follow within the same cstm session: info or else it won't work.

Bill
It works for me (tm)
Sridhar Bhaskarla
Honored Contributor
Solution

Re: cstm scripting like ftp scripting...

Bill,

It's surprizing to see why it's not working for you. Can you try this with sh -x and see? Believe me. This works superbly on my system. Only thing is that you need to replace sel device with the one that is applicable to you. Try cstm manually to get the output and incorporate those commands.

//start

cstm << EOF > /tmp/out1$$
map
quit
OK
EOF
for i in `cat /tmp/out1$$|grep CPU |awk '{print $1}'`
do
echo $i
cstm << EOF >> /tmp/out2$$
sel device $i <== I think here it is sel $i
infolog <<== info??
quit
OK
EOF
done

cat /tmp/out2$$
rm /tmp/out1$$ /tmp/out2$$

//END

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Robin Wakefield
Honored Contributor

Re: cstm scripting like ftp scripting...

Hi Bill,

You've got a trailing space after the closing
EOCSTM. Take it out, and it'll work!!

Rgds, Robin.
Bill McNAMARA_1
Honored Contributor

Re: cstm scripting like ftp scripting...

Nice one!

You gotta watch out for copy paste jobs on the forums.!!!

Thanks,
Bill
It works for me (tm)