Problem with syntax error on line 1, teletype


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem with syntax error on line 1, teletype
# 1  
Old 03-29-2012
Problem with syntax error on line 1, teletype

Hi All,

I am getting below error message while executing memory utilization script.
Code:
$ ./mem1.sh
syntax error on line 1, teletype
syntax error on line 1, teletype

$

$ uname -a
SunOS  5.9 XXX Generic_122300-60 sun4u sparc SUNW,Sun-Fire-V440
$

But i can execute same script in different solaris server.Please let us know how to resolve this isse.
Code:
$ ./mem1.sh
97.99855550130208333300
$ uname -a
SunOS YYYY 5.9 Generic_118558-39 sun4u sparc SUNW,Ultra-4
$


Please find the below for script.
Code:
$ more mem1.sh
#! /bin/sh
if
MEMORY=`/usr/sbin/prtdiag -v |grep -i "Memory size"|awk '{if($NF ~ /Megabytes/) print  $3}'`;then
  REALMEM_GB=`echo "$MEMORY / 1024"|bc -l`
  SWAPMEM_USE=`sar -r 1 30 |grep Average|awk '{print $2}'`
  Swapmem_GB=`echo "$SWAPMEM_USE * 8 / 1024 /1024"|bc -l`
  TOTAL_UTILIZED=`echo "$REALMEM_GB - $Swapmem_GB"|bc -l`
  TOTAL_REAL_UTILIZED=`echo "$TOTAL_UTILIZED / $REALMEM_GB * 100" |bc -l`
  echo $TOTAL_REAL_UTILIZED
else
  MEMORY_GB=`/usr/sbin/prtdiag -v |grep -i "Memory size"|awk '{if ($NF ~ /GB/) print $3}'|sed "s/[^0-9]//g"`
  TOTAL_UTILIZED=`echo "$MEMORY_GB - $Swapmem_GB"|bc -l`
  TOTAL_REAL_UTILIZED=`echo "$TOTAL_UTILIZED / $MEMORY_GB * 100" |bc -l`
  echo $TOTAL_REAL_UTILIZED
fi

Thanks,
Susi.S

Moderator's Comments:
Mod Comment Please use next time code tags for your code and data


---------- Post updated at 11:48 AM ---------- Previous update was at 11:14 AM ----------

Any one help me to fix the above script?????

Last edited by vbe; 03-29-2012 at 01:19 PM..
# 2  
Old 03-29-2012
The syntax error is in relation with bc -l ...
If you had searched a bit in this forum, you would have found e.g.
https://www.unix.com/shell-programmin...-teletype.html
# 3  
Old 03-29-2012
In the else clause $Swapmem_GB never has a value. There appears to be 3 lines missing after the else.

Last edited by methyl; 03-29-2012 at 02:23 PM..
# 4  
Old 03-29-2012
Hi Methyl,

I have changed according to your advice but still i am getting same error.The same script is executing on other solaris 9 server.I dont no why its not working on particular server.


Code:
$ more mem1.sh
#! /bin/sh
if
MEMORY=`/usr/sbin/prtdiag -v |grep -i "Memory size"|awk '{if($NF ~ /Megabytes/) print  $3}'`;then
REALMEM_GB=`echo "$MEMORY / 1024"|bc -l`
SWAPMEM_USE=`sar -r 1 30 |grep Average|awk '{print $2}'`
Swapmem_GB=`echo "$SWAPMEM_USE * 8 / 1024 /1024"|bc -l`
TOTAL_UTILIZED=`echo "$REALMEM_GB - $Swapmem_GB"|bc -l`
TOTAL_REAL_UTILIZED=`echo "$TOTAL_UTILIZED / $REALMEM_GB * 100" |bc -l`
echo $TOTAL_REAL_UTILIZED
else
MEMORY_GB=`/usr/sbin/prtdiag -v |grep -i "Memory size"|awk '{if ($NF ~ /GB/) print $3}'|sed "s/[^0-9]//g"`
SWAPMEM_USE=`sar -r 1 30 |grep Average|awk '{print $2}'`
Swapmem_GB=`echo "$SWAPMEM_USE * 8 / 1024 /1024"|bc -l`
TOTAL_UTILIZED=`echo "$MEMORY_GB - $Swapmem_GB"|bc -l`
TOTAL_REAL_UTILIZED=`echo + "$TOTAL_UTILIZED / $MEMORY_GB * 100" |bc -l`
echo $TOTAL_REAL_UTILIZED
fi
$
$ ./mem1.sh
syntax error on line 1, teletype
syntax error on line 1, teletype

$

Thanks,
Susi.S

Moderator's Comments:
Mod Comment Please use code tags for program contents and output.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Expr: non-numeric argument syntax error on line 1, teletype

Hi, I tried to look up the issue i'm experiencing, but i'm confused what's wrong with my script. After executing the script I'm getting the following error expr: non-numeric argument syntax error on line 1, teletype After some research, it seems that the problem relates to bc. I have... (1 Reply)
Discussion started by: nms
1 Replies

2. Shell Programming and Scripting

Syntax Error Problem

Hi Below script is throwing an error: repos=root filename=/home/admin/Desktop/authz case $repos in root) root_folder="\" do sed "/$root_folder/a $username = $access" $filename done ;; esac exit 0 Error: ./new1.sh: line 77: syntax error near unexpected token `do' (1 Reply)
Discussion started by: ankur328
1 Replies

3. Shell Programming and Scripting

./1.sh: Syntax error at line 1 : `<<' is not matched.

function user { sqlplus primeit@$ORACLE_SID/primeit <<EOF select user_name from test; EOF } function gen { genpwdfile dec -in $1 -out $2 echo $1 echo $2 } function reset { sqlplus primeit@$ORACLE_SID/primeit... (7 Replies)
Discussion started by: ripudaman.singh
7 Replies

4. Shell Programming and Scripting

IF section problem. syntax error: unexpected end of file error

Hello, I have another problem with my script. Please accept my apologies, but I am really nooby in sh scripts. I am writing it for first time. My script: returned=`tail -50 SapLogs.log | grep -i "Error"` echo $returned if ; then echo "There is no errors in the logs" fi And after... (10 Replies)
Discussion started by: jedzio
10 Replies

5. Shell Programming and Scripting

Receiving error: ./ang.ksh[35]: 0403-057 Syntax error at line 116 : `done' is not expected.

Hi All I am quite new to Unix. Following is a shell script that i have written and getting the subject mentioned error. #!/bin/ksh #------------------------------------------------------------------------- # File: ang_stdnld.ksh # # Desc: UNIX shell script to extract Store information.... (3 Replies)
Discussion started by: amitsinha
3 Replies

6. Shell Programming and Scripting

Makefile: syntax error at line 1

I am able to 'Make' some of projects's modules using GNU's make except one where it throws me the following error gmake -f Makefile /bin/sh: syntax error at line 1: `if' unexpected gmake: *** Error 2 I am sure it has nothing to do with the Makefile as there is no 'if' in the first... (1 Reply)
Discussion started by: sudsa
1 Replies

7. Shell Programming and Scripting

ERROR: ./launch_full_backup.sh[18]: Syntax error at line 28 : `else' is not expected.

Help please! :confused: I have the following error with the following file and the emails are not arriving to the email, any idea please? ERROR: ./launch_full_backup.sh: Syntax error at line 28 : `else' is not expected. FECHA=`date +%d%m%y%H%M`... (2 Replies)
Discussion started by: villenan
2 Replies

8. Shell Programming and Scripting

Syntax error at line 11 : `for' is not matched.

hi , while running this script i am getting below error: Syntax error at line 11 : `for' is not matched. here is program: #! /bin/ksh sqlplus -s << !+! user/password update GR_SUB_SCRIPT_PC set act_del_ind='0'; commit; exit; !+! cd /home/salunke/pvcsfiles/source_files for i in... (5 Replies)
Discussion started by: digambar
5 Replies

9. UNIX for Advanced & Expert Users

I got error like...syntax error on line 1, teletype

Hi All, when i executing scripts i got error like: syntax error on line 1, teletype expr: syntax error expr: syntax error expr: syntax error Please advise to me. Note: Yesterday it's working fine, 2day only i got error. (2 Replies)
Discussion started by: koti_rama
2 Replies

10. Shell Programming and Scripting

syntax error on line 1, teletype

Hi There, I have a cron script that returns the error: syntax error on line 1, teletype Has any one seen this, know what it is, or know's how to get rid of it? Thanks, Jeremy. (1 Reply)
Discussion started by: KokoPops
1 Replies
Login or Register to Ask a Question