Whats the error in this script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Whats the error in this script
# 1  
Old 06-07-2008
Whats the error in this script

#!/bin/sh
#usblcd clear
while true;
do
tail -1 /root/Myprogs/apurva.log > /root/Download/usr/bin/output.txt
cat /root/Download/usr/bin/output.txt | echo `awk '{if ($3 == "Connection"&&$4 == "Established") print"Connection Established "}
else if {($3 == "DTNCO"&&$4 ==" Sent" && $5="Packet") print"Bundle Sent"}
else if {($3 == "Connection" && $4 == "Closed") print"Connection Closed"}
else if {print"Processing"} ' /root/Download/usr/bin/output.txt`
sleep 1;
done
# Just replace echo with usblcd and it will be done
# 2  
Old 06-07-2008
Quote:
Originally Posted by appu1987
#!/bin/sh
#usblcd clear
while true;
do
tail -1 /root/Myprogs/apurva.log > /root/Download/usr/bin/output.txt
cat /root/Download/usr/bin/output.txt | echo `awk '{if ($3 == "Connection"&&$4 == "Established") print"Connection Established "}
else if {($3 == "DTNCO"&&$4 ==" Sent" && $5="Packet") print"Bundle Sent"}
else if {($3 == "Connection" && $4 == "Closed") print"Connection Closed"}
else if {print"Processing"} ' /root/Download/usr/bin/output.txt`
sleep 1;
done
# Just replace echo with usblcd and it will be done
I would guess that the problem is with the semicolons...
try to remove them.
# 3  
Old 06-09-2008
The problem is with the extra curly braces in the awk script.

Code:
#!/bin/sh
#usblcd clear
while true;
do
    tail -1 /root/Myprogs/apurva.log > /root/Download/usr/bin/output.txt
    echo `awk '{if ($3 == "Connection"&&$4 == "Established") print"Connection Established ";
      else if ($3 == "DTNCO"&&$4 ==" Sent" && $5="Packet") print"Bundle Sent";
      else if ($3 == "Connection" && $4 == "Closed") print"Connection Closed";
      else print"Processing"} ' /root/Download/usr/bin/output.txt`
    sleep 1;
done
# Just replace echo with usblcd and it will be done

I also took out cat, as it didn't seem to have any purpose.

Incidentally, the path name /root/Download/usr/bin looks ... weird. If this is meant to be a temporary file, perhaps you should simply store it in /tmp; or if it is used solely by awk, use a pipeline to awk.

Quote:
Originally Posted by Grzegorz
I would guess that the problem is with the semicolons...
try to remove them.
No, the semicolon is a valid delimiter; it's basically equivalent to a newline.

Last edited by era; 06-09-2008 at 05:23 AM.. Reason: Major edit: previous diagnostic was incorrect
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sh Script whats wrong?

Hi there, i have a problem i have created followning sh files some years ago but now it dosen`t work anymore i never used it a long time. Can anyone find the Error? Its always runs the stop() block and trying to Killing the Server also if i try to start or creat a new one. #!/bin/sh stop()... (6 Replies)
Discussion started by: NewCannon
6 Replies

2. OS X (Apple)

Whats wrong with this shell script!!!!!

hi guys can you tell me if anything is wrong with this script, seems reasonable to me but somehow never works. Script redacted for being too explicit (2 Replies)
Discussion started by: Freddo
2 Replies

3. Shell Programming and Scripting

Whats wrong with my script?

I am trying to find a value within a properties file and declare it into a variable. Script below. I want the "memSize" to be the branch from the properties file. Right now it always tells me "Not found" What am I doing wrong? #!/bin/sh memsize =''; memSize=`sed '/^\#/d'... (8 Replies)
Discussion started by: vsekvsek
8 Replies

4. Shell Programming and Scripting

Whats the error in this script ?

Can someone help me figure out the error with this simple script: #!/bin/sh fact() { if ; then p=`fact expr $1 - 1` else echo $1 fi echo `expr p \* $1` } echo "Enter a number you wish to calculate factorial... (5 Replies)
Discussion started by: sheelscripter
5 Replies

5. Shell Programming and Scripting

whats error in code ??

if `egrep -c "safe_mode" /usr/local/lib/php.ini` - gt 0 && " `egrep -c "safe_mode" /usr/local/lib/php.ini` = "On" " then echo " Good " exit else echo " Not Good "; fi and (4 Replies)
Discussion started by: x-zer0
4 Replies

6. Shell Programming and Scripting

Whats the problem whit my script???

I want to take the even-numbered lines from a file and put them in a separate file and the same thing with the odd-numbered lines. #!/bin/bash file=$1 awk ' { if ( NR % 2 == 0) { (( getline < "$file" ) > "even.txt" )} else { (( getline < "$file" ) > "odd.txt" )} } ' $file (4 Replies)
Discussion started by: cristi2008
4 Replies

7. UNIX for Dummies Questions & Answers

Whats wrong in the script?

if then if then echo "fst argument is $1 " else if then "fst argument is $1" fi fi fi Can anyone tell me. My requirement is tht pass a string .. Check whether it contains "-". If yes then check if it... (1 Reply)
Discussion started by: nehagupta2008
1 Replies

8. UNIX for Advanced & Expert Users

Whats wrong in this Script ???

PATH="/clocal/mqbrkrs/user/mqsiadm/sanjay" MAIL_RECIPIENTS="xyz@abc.com" Subject="File accessed in last minutes:" find $PATH -type f -amin -1 > temp.txt.$$ cat temp.txt.$$ | \ while read line do fuser -uV $line >> tempmail.txt done cat "$tempmail.txt" | mailx -s "$Subject"... (4 Replies)
Discussion started by: varungupta
4 Replies

9. Shell Programming and Scripting

Whats wrong with this script?

Hi all, #!/bin/ksh BIN=/interface/Gunner age=$1 directory="$2" && directory=. cd "$directory" || exit 1 from=`$BIN/today -$age` cd $BIN for i in `cat filestoarchive.txt`;do cd $i find . -mtime 14 | grep -v '.tar$' | $BIN/dttmfilter | awk '$1<="'$from'"{ print;};' | \ done (2 Replies)
Discussion started by: kayarsenal
2 Replies

10. UNIX for Dummies Questions & Answers

whats the purpose of the following script?

whats the purpose of the following script? who could run it? To what is the script refering that exceeds 75%? The mailbox? What does sed 's/%//' do? (1 Reply)
Discussion started by: vrn
1 Replies
Login or Register to Ask a Question