Operating System - HP-UX
1838696 Members
5587 Online
110128 Solutions
New Discussion

script to check all modems

 
Todd Bowden
Valued Contributor

script to check all modems

Im trying to write a little "for" loop that does a check of our modems (48). Currently we are having problems that every so often we lose the ability to use these modems. The symptom is if I directly connect to the modem and try to issue an AT command it bumps me out right away with a "Lost Carrier" message. When I tried to write a little "for" loop it didnt work as expected. Can anyone help? Below is what I was using.

for i in `cat /etc/uucp/Devices | grep ^Dire | awk '{print $2}'`
do
echo $i
cu -l${i} dir << EOF
AT
~.
EOF
done

Dosent give me the expected results (my expectations). Thanks for any help you may give me.

Todd
9 REPLIES 9
Rodney Hills
Honored Contributor

Re: script to check all modems

One thing I noticed in the "for" statement, you specify '{print $2}'. Since the first quote you used was back-apostrophe (`), then the $2 will be attempted to be substituted with argument #2 from the command line.

I think you wanted the $2 to remain literal for the awk command. Try changing it to {print \$2}.

By the way you can rework that for statement like this and remove all the unnecessary pipes-

for i in `awk '/^Dire/{print \$2}' /etc/uucp/Devices`

HTH

-- Rod Hills
There be dragons...
Todd Bowden
Valued Contributor

Re: script to check all modems

Thanks for the reply,

I still get the same outcome. I know I have about 7 modems that I should see a lost carrier and I dont. It does issue the ~. at the end and disconnects from the modem. Im just not seeing the AT command being executed, which should be followed by a OK.

Thanks.
Muthukumar_5
Honored Contributor

Re: script to check all modems


Why are trying ~. to disconnect the connection with EOF

On hard-wired lines, ~. sends several EOF characters to log out the session


Try to to use as,

~.. to suppress EOF actions, so that EOF after ~.. will get effect.

So try to use as,


for i in `awk '/^Dire/{ print $2 }' /etc/uucp/Devices`
do

echo $i
cu -l${i} dir <<-EOF
AT
~..
EOF
done

Easy to suggest when don't know about the problem!
Todd Bowden
Valued Contributor

Re: script to check all modems

Thanks but it still doesnt work.
Darren Prior
Honored Contributor

Re: script to check all modems

Hi Todd,

Have you tried breaking the script down? What happens if you just have the here script for cu with a fixed device name? Also, do you have a shell definition as the 1st line of the script?

regards,

Darren.
Calm down. It's only ones and zeros...
Todd Bowden
Valued Contributor

Re: script to check all modems

If I run the sam "for" loop without the EOF, it does what I expect it to, but I now have to do it manually.
Darren Prior
Honored Contributor

Re: script to check all modems

set -x could be useful.
Calm down. It's only ones and zeros...
Rodney Hills
Honored Contributor

Re: script to check all modems

Is it possible that "cu" like "passwd" interacts with the terminal then through the standard input/ouput.

To run "cu" you may have to drive it with a "expect" script.

HTH

-- Rod Hills
There be dragons...
Todd Bowden
Valued Contributor

Re: script to check all modems

I was hoping not to have to use expect. I have used it before, but I was hoping for a different answer.