Scrip saving time

 
Taulant Shamo
Frequent Advisor

Scrip saving time

Hello all,

In my daily work I have to run some commands UX to check some lines status if they are in state SOFTBLOCK i have to spo and start it as is shown in file attached.

Could anyone help me with that to create a script to run the command UI than in a different environment giving the command STATUS CIC * * STATE according the printout we decide with line to stop and start.
than to close the environment with Q.

See file attached
5 REPLIES 5
Peter Godron
Honored Contributor

Re: Scrip saving time

Taulant,
something along these lines:
#!/usr/bin/sh
# Run the ui and stream the input
ui << .eof > /tmp/$$
status cic ** state
q
.eof
# Look for the Softblocks
cat /tmp/$$ | grep -e"SOFTBLOCK" > /tmp/$$_2
rm /tmp/$$
# If file exists and softblocks were found
if [ -s /tmp/$$_2 ]
then
tappman -vps2 -p 33 stop
tappman -vps2 -p 33 start
else
echo "No Softblocks found"
fi
rm /tmp/$$
exit

Regards
Taulant Shamo
Frequent Advisor

Re: Scrip saving time

numbers 2 and 33 are variables. The alarm my affeck other lines example: 1 15 ore mre that one

tappman -vps2 -p 33 stop
tappman -vps2 -p 33 start
Peter Godron
Honored Contributor

Re: Scrip saving time

#!/usr/bin/sh
ui << .eof > /tmp/$$
status cic ** state
q
.eof
cat $file | grep -e"SOFTBLOCK" > /tmp/$$_2
if [ -s /tmp/$$_2 ]
then
# Assumptions
# Output is fixed format
# vps? where ? 0-9
# p ?? where ?? 00-99
proc=`cat /tmp/$$_2 | cut -c38`
ident=`cat /tmp/$$_2 | cut -c40-41`
tappman -vps$proc -p $ident stop
tappman -vps$proc -p $ident start
else
echo "No Softblocks found"
fi
rm /tmp/$$_2
exit
Peter Godron
Honored Contributor

Re: Scrip saving time

Third time I'll get it right:
#!/usr/bin/sh
# This will allow for multiple entries
ui << .eof > /tmp/$$
status cic ** state
q
.eof
cat /tmp/$$ | grep -e"SOFTBLOCK" > /tmp/$$_2
rm /tmp/$$
while read record
do
part1=`echo $record | awk -F')' '{print $2}'`
part2=`echo $part1 | awk -F' ' '{print $2}'`
proc=`echo $part2 | awk -F'/' '{print $1}'`
ident=`echo $part2 | awk -F'/' '{print $2}'`
tappman -vps$proc -p $ident stop
tappman -vps$proc -p $ident start
done < /tmp/$$_2
rm /tmp/$$_2
exit

Please let us know if this solved the problem
Hein van den Heuvel
Honored Contributor

Re: Scrip saving time



If the status is in a file "x" then you can use a perl '-one liner' like:

perl -ne 'if (/comport\/\s+(\d+)\/(\d+).*SOFTBLOCK/) {system "tappman -vps$1 -p $2 stop";system "tappman -vps$1 -p $2 start"}' x


Or you can just have perl do it all (untested!):

perl restart.pl

with

------------- restart.pl ------------

foreach (`status cic * * state`) {
if (/comport\/\s+(\d+)\/(\d+).*SOFTBLOCK/) { system "tappman -vps$1 -p $2 stop";
system "tappman -vps$1 -p $2 start";
}
}

Broken down:
- pick up each line from status command into default string $_
- if you see 'comport' followed by a slash (\/), followed by some whitespace (\s+), followed by some decimals (\d+) remember those in $1 (()) followed by an other slash and some decimals remembers in $2 followed by anything (.*) and 'SOFTBLOCK' ... then
- execute a stop and a start

Hein.