I am completely new to shell scripting. Basically I am wanting to create a simple while loop script to check if a network connection is available from 'netstat -a' and if its present then output a character to the serial port. I think i am nearly there.. but need some assistance.. this is what i have so far..(ip address an example)..
#!/bin/bash
CONNECTED=$(netstat -a | grep -c 1.1.1.1)
while [echo $CONNECTED -gt 0]; do
echo -n p >/dev/ttyS1;
sleep 20;
done
#!/bin/bash
CONNECTED=$(netstat -a | grep -c 1.1.1.1)
while [ "$CONNECTED" -gt 0 ]; do
echo -n p >/dev/ttyS1;
sleep 20;
CONNECTED=$(netstat -a | grep -c 1.1.1.1)#I think you need this also inside the while loop. so it can change the value and reflects it..
done
Hi I have kind of modified things to change for an application..
#!/bin/bash
CONNECTED=$(ps -ef | grep -c APP1)
while [ "$CONNECTED" -gt 1 ]; do
echo -n p >/dev/ttyS1;
echo $CONNECTED
sleep 10;
CONNECTED=$(ps -ef | grep -c APP1)
done
one thing I don't know how to get right is exit status.. so when $CONNECTED is less than or equal to 1 I want the loop to continue but not send the output to the serial port. Right now if $CONNECTED is = 1 the script stops..
Thanks for your help so far. Essentially if program A is running i want to continually send serial keepalives to the serial port..(something is scooping this output up fine) if the program fails i want the output to stop.. if the program resumes i want it to continue