Script working in AIX, but giving error in SOLARIS


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script working in AIX, but giving error in SOLARIS
# 1  
Old 02-09-2011
Script working in AIX, but giving error in SOLARIS

Hi,
My script is working fine in AIX but throwing an error in SOLARIS system.

Here is the error message that I am getting when calculating the elapsed time:
/home/x772525/FindETA.sh[106]: start_mins = *60 + : syntax error

Code:
.
((start_mins = $(expr substr "$j" 1 2)*60 + $(expr substr "$j" 4 2)))

Please let me know if there is any problemm with the line.

Thanks
Ajay
# 2  
Old 02-10-2011
Perhaps $j is not set?
# 3  
Old 02-10-2011
Code:
for j in `cat starttime.txt`
        do
                
                for k in `cat endtime.txt`
                do
                        
                        num=$(expr substr "$k" 1 2)
                       
                        ((start_mins = $(expr substr "$j" 1 2)*60 + $(expr substr "$j" 4 2)))
                        ((end_mins = $(expr substr "$k" 1 2)*60 + $(expr substr "$k" 4 2)))
                        ((elapsed_mins = end_mins - start_mins))

This is the code that I am using. Same thing if I copy paste in AIX, it is working, but in SOLARIS it is throwing that error.

---------- Post updated at 12:56 AM ---------- Previous update was at 12:39 AM ----------

Code:
[bpdps009] x772525 /home/x772525> cat starttime.txt
20:03:12
[bpdps009] x772525 /home/x772525> cat endtime.txt
20:04:57

Code:
[bpdps009] x772525 /home/x772525> cat > test.sh
#!/bin/ksh
for j in `cat starttime.txt`
        do
                
                for k in `cat endtime.txt`
                do
                        
                        num=$(expr substr "$k" 1 2)
                       
                        ((start_mins = $(expr substr "$j" 1 2)*60 + $(expr substr "$j" 4 2)))
                        ((end_mins = $(expr substr "$k" 1 2)*60 + $(expr substr "$k" 4 2)))
                        ((elapsed_mins = end_mins - start_mins))
echo "$elapsed_mins"
done
done

Output:
Code:
[bpdps009] x772525 /home/x772525> test.sh
expr: syntax error
expr: syntax error
expr: syntax error
/home/x772525/test.sh[10]: start_mins = *60 + : syntax error

---------- Post updated at 08:37 PM ---------- Previous update was at 12:56 AM ----------

It looks to be a problem with expr syntax. Can someone pls help me solve this?

Thanks
Ajay
# 4  
Old 02-10-2011
Try putting set -x in the start of the script. And post the results.

I'm confused because I only get a syntax error from expr if I omit the quotes...
Code:
$ set -x

$ x=""
+ x=

$ expr substr "$x" 1 2
+ expr substr '' 1 2


$ expr substr $x 1 2
+ expr substr 1 2
expr: syntax error

$

...where $ is the bash prompt.
# 5  
Old 02-10-2011
Code:
[bpdps009] x772525 /home/x772525> cat > test.sh
#!/bin/ksh
set -x
read stime < starttime.txt
      
                
                read etime < endtime.txt
              
                        ((start_mins = $(expr substr "$stime" 1 2)*60 + $(expr substr "$stime" 4 2)))
                        ((end_mins = $(expr substr "$etime" 1 2)*60 + $(expr substr "$etime" 4 2)))
                        ((elapsed_mins = end_mins - start_mins))
echo "$elapsed_mins"

Here is the output:
Code:
[bpdps009] x772525 /home/x772525> test.sh
+ read stime
+ 0< starttime.txt
+ read etime
+ 0< endtime.txt
+ expr substr 20:03:12 1 2
expr: syntax error
+ expr substr 20:03:12 4 2
expr: syntax error
+ (( start_mins = *60 +  ))
/home/x772525/test.sh[9]: start_mins = *60 + : syntax error

# 6  
Old 02-10-2011
Perhaps it's the Solaris expr, does expr substr "AB:CD" 1 2 work from the command line?

You could replace the expr call with something like echo $stime | cut -f1 -d:

Last edited by Chubler_XL; 02-10-2011 at 10:35 PM.. Reason: typos
# 7  
Old 02-11-2011
Yes, that command is not working on command line also. .
I used that cut option and it is now working fine.

Thank you.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script giving error-Unable to identfiy

#!/bin/sh #!/bin/prel #set -x while getopts ":n:t:" opt; do case "$opt" in n) host=$OPTARG ;; t) targ=$OPTARG ;; *) break ;; esac done if ping -c 2 $host >/dev/null 2>&1 then echo Host... (17 Replies)
Discussion started by: Vishal_dba
17 Replies

2. Shell Programming and Scripting

Solaris script using awk giving errors - please advise

I'm using solaris 10 Scenario as follows I have a logfile with 2 columns: column 1 = source directory + filename column 2 = destination directory + filename Using cron, my script polls for new files and adds them to the logfile ($ELOG) as described above. Using sed, the distination... (2 Replies)
Discussion started by: davidra
2 Replies

3. Shell Programming and Scripting

script to kill a pid giving error

Hi, I simply want to kill a running process using a script that read pid from a file and tries to kill it .Getting error as shown below code.. cat $HOME/BackupScript.ksh.run | head -1 | while read pid do ps -p $pid > /dev/null 2>&1 if ; then kill -9 $pid else echo "no running $pid... (5 Replies)
Discussion started by: dhirajdsharma
5 Replies

4. Shell Programming and Scripting

Sed script not working properly on Solaris (works fine on AIX)?

Hi, I have a problem with a SED script that works fine on AIX but does not work properly on a Solaris system. The ksh script executes the SED and puts the output in HTML in tables. But the layout of the output in HTML is not shown correctly(no tables, no color). Can anyone tell if there is... (7 Replies)
Discussion started by: Faith111
7 Replies

5. Shell Programming and Scripting

Printer status script giving error

Hi, We check the printer status at the command line by giving the following command and the system gives an output; lpstat -prn001_hp4000n When I give the same command in a UNIX script the system gives an error while running the script as "lpstat: not found". Please let me know... (8 Replies)
Discussion started by: jmathew99
8 Replies

6. Solaris

useradd giving error in solaris 10

Hi, I have installed Solaris 10 in my PC and now installing Oracle10, but while adding a user i am getting following error: useradd -g oinstall -G dba -d /export/home/oracle oracle UX: useradd: ERROR: Inconsistent password files. See pwconv(1M). I have tried pwconv command,... (4 Replies)
Discussion started by: amitanshu.verma
4 Replies

7. Shell Programming and Scripting

A running Script giving error while scheduled in cronjob

Hi, I have script which is properly running but when i schedule it in cron it throws an error like : Your "cron" job on retrprdapp1 /usr/bin/sh /retr/cron/ftp.sh 2>&1 produced the following output: /retr/cron/ftp.sh: syntax error at line 17: `(' unexpected line17 is # Get list of... (10 Replies)
Discussion started by: rajagasti
10 Replies

8. UNIX for Advanced & Expert Users

script giving error

Hi All, i have an small issue... echo " " eval x=$@ export x=`echo $x` echo $x ssh user@ipadrss; cd /mbbv/home/; cd /mbbv/home/orange/orange/ echo pwd bash samplescript.sh $x above is my script which will triger from server A and will connect to server B for some... (2 Replies)
Discussion started by: Shahul
2 Replies

9. Shell Programming and Scripting

mv command is giving error in shell script

Hi, In my shell script when I am using mv command using shell variables it is giving me error of syntax. Following is the shell script: file_edifice="*.txt" fquote="'" fdquote=\" for file in $file_edifice do file_name=$fquote$file$fquote tofile_name=`date... (5 Replies)
Discussion started by: gammit
5 Replies

10. Programming

Code working AIX 5.2 and not in Solaris 5.9

Hi, When i run the below code in AIX it runs and solaris not ... why ??? #include <stdio.h> #include <string.h> #define MAX 1 int main () { char str ="1,2,3,4,5"; char * pch,b; int a; printf ("Enter the int to be searched ",str); scanf("%d",&a); sprintf(b,"%d",a); ... (2 Replies)
Discussion started by: vijaysabari
2 Replies
Login or Register to Ask a Question