0

My Code:

#!/bin/bash
rm screenlog.0
screen -X stuff 'X21'$(printf \\r)
while :
do
grep -i "T" $screenlog.0
if [ $? -eq 0 ];
then
FILE=/etc/passwd 
VAR=`head -n 1 $FILE` 
echo $VAR
rm screenlog.0
break
done

This script is to delete the file "screenlog.0" send a command (X21) to an screen interface. Thats the first part and it works.

The second Part is the Problem: That should test the content of "screenlog.0", is there an something with a "T" inside save the contant into a variable.

The error:

line 11: syntax error near unexpected token `done'
line 11: `done'

To the "screen": Its an screen of an usb device that recive radio messages like this:

T350B00A66E2
H34D04DE4254

The script have to scan for the incomming messages with "T" at the beginning (The first letter is a Type field behind this a hex code.

Some ideas to correct or other solutions?

I corrected my code a bit:

#!/bin/bash
>screenlog.0
screen -X stuff 'X21'$(printf \\r)
while :
do
sleep 2
grep -i "T" $screenlog.0
if [ $? -eq 0 ];
then
screenlog.0=/etc/passwd
VAR=`head -n 1 $screenlog.0`
echo $VAR
break
fi
done

The new error is:

grep: .0: No such file or directory

All 5 seconds....

The file screenlog.0 exist .. :(

1
  • 2
    Note that you can test the exit status of the grep command directly: if grep -i "T" screenlog.0. You also probably don't want the $ in front of $screenlog.0 given that the script otherwise manipulates screenlog.0 with no $. It's also better to use the $(…) notation rather than use the back-ticks notation. Commented Mar 29, 2014 at 12:20

1 Answer 1

4

oh...you missed fi in your script :). Like syntax as follows if [ condition ];then #dosomething fi

For your script

if [ $? -eq 0 ];then
    FILE=/etc/passwd  
    VAR=`head -n 1 $FILE` 
    echo $VAR
    rm screenlog.0
    break
fi
Sign up to request clarification or add additional context in comments.

1 Comment

@DemonDragon change from $screenlog.0 to "screenlog.0".Also note you removed on startup rm screenlog.0. remove that line.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.