Solaris bash syntax different from Linux?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Solaris bash syntax different from Linux?
# 1  
Old 10-21-2010
Solaris bash syntax different from Linux?

I have a script that's meant to check the disk usage on a particular volume and delete the oldest logfile if it's over a certain percentage. It runs fine on a Linux machine, but on a Solaris one, I get this error:
diskspace_check.sh: syntax error at line 3: `diskspace=$' unexpected

I assume this is due to some difference in syntax between the two systems, but I don't know what. Can anyone give me an idea?

Here is the whole script:
Code:
#!/bin/sh
logfile_path='log'
diskspace=$( df -h | grep '/c0t0d0s5' | awk '{ print $5 }' )
usep=$(echo $diskspace | cut -d'%' -f1  )
if [ $usep -ge 10 ]; then
  del_file=$( ls -lt $logfile_path | grep -E 'cisco.log' | tail -1 | awk '{ print $8 }' )
  del_path=$( echo $logfile_path"/"$del_file )
  rm $del_path
  echo "Removed log file $del_file from /disk2 on $(date)" |
   mail -s "Alert: Log file removed from /disk2" xxxxxx@yyyyy.com
fi


Last edited by DukeNuke2; 10-22-2010 at 04:47 AM..
# 2  
Old 10-21-2010
Solaris usually doesn't even have bash, you're using /bin/sh. This, by sheer coincidence, may happen to be bash on your linux system, but often means a much more restrictive shell anywhere else. Whenever you use bash-specific features, you should have the script call #!/bin/bash instead of #!/bin/sh to warn people.

Solaris in particular has a very stone-age /bin/sh.

I think it's objecting to the $(command) syntax, try backticks like `command` instead. You could also try using the Korn shell, /bin/ksh, which I think should be able to tolerate this script but differs from BASH in a few ways.
# 3  
Old 10-21-2010
Try the XPG4-compliant shell i.e. /usr/xpg4/bin/sh. It supports the $(...) syntax.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Syntax error in subtraction in Bash

I am sharing a code snippet. for (( i=0; i<=$(( $count -1 )); i++ )) do first=${barr2} search=${barr1} echo $first echo "loop begins" for (( j=0; j<=5000; j++ )) do if } == $search ]]; then echo $j break; fi done second=${harr2} echo $second (2 Replies)
Discussion started by: ngabrani
2 Replies

2. Shell Programming and Scripting

Bash syntax problem

Hello! i try to understand the art of bash scripting but unfortunately, more i try and less i understand it. Can someone tell me how i can learn its logic? i will give you an example why its making me crazy. Look at this basic script: my for loops are working like this, but it took me more than... (10 Replies)
Discussion started by: sablista
10 Replies

3. Shell Programming and Scripting

Bash syntax

Hello, I have seen this syntax, { ;;};quite often and I don't know what it means exactly. It seems like a distinctive thing of Bash, so it's been used for the logo of the last bug, ShellShock: All you need to know about the Bash Bug vulnerability | Symantec Connect I have also seen... (3 Replies)
Discussion started by: Kibou
3 Replies

4. Shell Programming and Scripting

Bash syntax error

while read line do mkdir $line scp -r Docking_results/docking_$line.pdb $line/ cd /$line/ set a=`grep ENDMDL docking_'$line'.pdb | wc -l` set b=`expr $a - 2` csplit -k -s -n 3 -f docking_'$line'. docking'$line'.pdb '/^ENDMDL/+1' '{'$b'}' foreach f (... (4 Replies)
Discussion started by: chrisjorg
4 Replies

5. Web Development

Bash Script, ec2addtag syntax?

ec2addtag --region us-west-1 vol1234 --tag Name=$nameinst; It should execute ec2addtag --region us-west-1 vol1234 --tag Name=webserver; Instead it thinks that Name is equal to that variable. Please help. Thanks! Please use code tags! (0 Replies)
Discussion started by: svalenciatech
0 Replies

6. Shell Programming and Scripting

Bash syntax behaviour : [[ vs [

Hello. In the following : RESTORE_FF contain a file name : a_file.tar.gz I am testing in a directory if "a_file.tar.gz" exists and or if any file like "a_file.tar.gz" exists. So "a_file.tar.gz" will give me file exists So "a_file.tar.gz." will give me file exists So... (5 Replies)
Discussion started by: jcdole
5 Replies

7. Shell Programming and Scripting

Converting from Linux bash (GNU) to Solaris script syntax errors

Original script written on CentOS 6.3 with GNU bash 4.1.2 Destination system is Solaris 9 with GNU bash 2.05 (not changeable by me) I have a script written on the linux side but now we need to provide a version to another site that "doesn't like linux". I've been going through changing the ] or... (13 Replies)
Discussion started by: oly_r
13 Replies

8. Shell Programming and Scripting

linux bash script to sun solaris

Hi guys, I seek a solution for this action for Sun solaris. find /sapmnt/${up}/global -prune -printf "%m %M %u %g %p\n" > $DAT1 The Application/Utilities in Sun Solaris are to old and cant understand "-printf". An update for Application/Utilities is exist, but not possible to implement... (6 Replies)
Discussion started by: ixibits
6 Replies

9. Shell Programming and Scripting

bash syntax error: command not found

I am trying to create a shell that asks the user to enter their name, and compare it to my own by saying we have the same name or saying my name and that they have a nice name too. Here is my script... #!/bin/bash-x echo "Enter your name". read name if then echo "My name is Adam too"... (1 Reply)
Discussion started by: amaxey45
1 Replies

10. Shell Programming and Scripting

BASH Script syntax error

I'm trying to write a simple script that takes all the .tar.gz files in a directory and verifies them by using the gzip -tv command: for zip in *.tar.gz do gzip -tv $zip if ; then #Check return code from tar echo "File ${zip} verified OK." exit... (4 Replies)
Discussion started by: kelldan
4 Replies
Login or Register to Ask a Question