script error


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script error
# 1  
Old 12-10-2010
script error

Hi. I have this script in my cron job. Whats wrong with the below script. I keep getting errors as "syntax error at line 1: `(' unexpected"

Code:
# cat space_check.pl

#!/usr/bin/perl
require "ctime.pl";
require "stat.pl";

open(HTYPE,"/etc/host-type");
$TYPE=<HTYPE>;
chop $TYPE;
$DATE=&ctime(time);
while (true)
{
  $UNIX=`uname`;
  chop $UNIX;
  if ($UNIX ne SunOS) {
    print "$UNIX system - not catered for\n";
    exit;
  }
# If the environment variable of LIMIT is set then it is assumed that the script is run in warning mode
# not alert mode.  Warning mode means output to console, Alert mode output to syslog
  $WLIMIT=$ENV{'LIMIT'};
  if ($WLIMIT eq "") {
    system("logger -p user.err MARK");
    $DLIMIT=90;
  }
  else
    {$DLIMIT=$WLIMIT;}
  &filesystem;
  &inodes;
  &swap;
  exit;
}

sub filesystem
{
  open (DF,"(df -F ufs -k;df -F vxfs -k)|grep -v cdrom|");
  while ($line = <DF>)
  {
    chop $line;
    ($filesystem, $size, $used, $avail, $capacity, $mountp) = split(' ',$line,6);
    if ($filesystem ne "Filesystem")
    {
      $LIMIT="0\n";
      open (LF,"${mountp}/.limit");
      $LIMIT=<LF>;
      chop $LIMIT;
      if ($LIMIT==0) {
# if length is 1 then it is the root "/" file system
        if (length($mountp)==1)
          { $LIMIT=95; }
        else
          { $LIMIT=$DLIMIT; }
      }
      else
      {
        if ($WLIMIT ne "" )  {
          printf "Filesystem %-40.40s has a limit file containing %s\n", $mountp,$LIMIT;
          $LIMIT=$DLIMIT;
        }
      }
      if (index($LIMIT,"m") > 0)
      {
        chop($LIMIT);
        $cap=($avail / 1000);
        if ($cap < $LIMIT) {
          &get_owner;
          $MESSAGE=sprintf "Filesystem %-40.40s has less than minimum space allowed, actual %d MB minimum is %d MB\n", $mountp,$cap,$LIMIT;
          &logging($MESSAGE);
        }
      }
      else
      {
        $cap=($used / $size) * 100;
        if ($cap > $LIMIT) {
          &get_owner;
          $MESSAGE=sprintf "Filesystem %-40.40s is %2.2f full, limit is %2.2f, space available is %d kb\n", $mountp,$cap,$LIMIT,$avail;
          &logging($MESSAGE);
        }
      }
    }
  }
}

sub inodes
{
  $LIMIT=95.3;
  $MIN=5000;
  open (DF,"(df -F ufs -g;df -F vxfs -g)|grep -v cdrom|");
  while ($line = <DF>)
  {
    @field = split(' ',$line);
    $mountp=$field[0];
    $line = <DF>;
    @field = split(' ',$line);
    $avail=$field[6];
    $line = <DF>;
    @field = split(' ',$line);
    $left=$field[0];
    $line = <DF>;
    $line = <DF>;
    $used=$avail-$left;
    if ($left < $MIN) {
      $MESSAGE=sprintf "Filesystem %-40.40s is below min inodes %6d left, minimum is %6d\n", $mountp,$left,$MIN;
      &logging($MESSAGE);
    }
  }
}

sub swap
{
  $HIGH=90;
  $LOW=80;
  open(SF,"swap -s|tr -d k|");
  $line=<SF>;
  chop $line;
  @swapf = split(' ',$line);
  $size=$swapf[8]+$swapf[10];
  $used=$swapf[8];
  $cap=($used / $size) * 100;
 # if ($cap > $HIGH)
 #   { print "Problem Swap space is $cap full\n"; }
 # elsif ($cap > $LOW)
 #   { print "Warning Swap space is $cap full\n"; }

    if ($cap > $HIGH) {
      $SWAPMESSAGE=sprintf "Swap Space is $cap full\n";
      system("logger -p user.err '(SPACE)' Please call WIPRO UNIX SUPPORT $SWAPMESSAGE"); }
}

sub logging
{
  if ($WLIMIT eq "" ) {
    if (&check_if_we_report) {
      if (&checklast)
        { system("logger -p user.err '(SPACE)' Please call WIPRO $CALLOUT $MESSAGE"); }
      }
    }
  else
    { print $MESSAGE; }
}

sub check_if_we_report
{
  open(HTYPE,"/etc/host-type");
  $TYPE=<HTYPE>;
  chop $TYPE;
  $DATE=&ctime(time);
  ($dayofweek,$month,$day,$time,$tz,$year) = split(' ',$DATE,6);
  ($hh,$mm,$ss) = split(':',$time,3);
  if ($TYPE ne DEV)
    {return 1;}
  else {
    if ($hh >= 8) {
      if ($hh < 17) {
        if ($dayofweek ne Sat) {
          if ($dayofweek ne Sun) {
            return 1;
          }
        }
      }
    }
  }
  return 0;
}


sub checklast
{
  return 1;
  $now=time;
  $mountp=~ s/\//./g;
  $TAG="/tmp/.tag$mountp";
  &Stat($TAG);
#  $delay=3600;
  $delay=1;
  $diff=$now - $st_mtime;
  if ($diff > $delay)
  {
    system("touch $TAG");
    return 1;
  }
  return 0;
}

sub get_owner
{
  if ($mountp eq "/" || $mountp eq "/rootbackup")
  {
    $CALLOUT="UNIX team";
  }
  else
  {
    open (LS,"ls -ld $mountp|");
    $LINE=<LS>;
    ($one, $two, $OWNER, $four) = split(' ',$LINE,4);
    $CALLOUT="Application support";
    if ($OWNER eq sybase) {$CALLOUT="Sybase team"};
    if ($OWNER eq oracle) {$CALLOUT="Oracle team"};

    open (OF,"${mountp}/.callowner");
    $FSOWNER=<OF>;
    chop $FSOWNER;
    if ($FSOWNER ne "") {
        $CALLOUT=$FSOWNER
    }
  }
  return 0;
}
0:0:0 /utl/sh

Moderator's Comments:
Mod Comment Code tags, please.
# 2  
Old 12-10-2010
This script seems ok. Could you run a perl -c on both ctime.pl and stats.pl? Also, how do you call the script?
# 3  
Old 12-10-2010
Your first line is an empty line : delete that empty line
Indent your code and use the code tags.
This User Gave Thanks to ctsgnb For This Post:
# 4  
Old 12-10-2010
It seems that the other 2 program u r using are producing an error. Check out the "ctime.pl" and "stat.pl" can be executed properly or not. Let me guess "perl -c space_check.pl" command doesn't produce any output...???? This error might be coming at run time..??
R0H0N
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script with sql script error

Hi All when I execute from psql prompt, I get the result, when I try to automate using a shell script, the query is not working # `/usr/bin/psql -U postgres -d coba1 -c "select name from users where "Date" > current_date - 30;"` ERROR: column "Date" does not exist LINE 1: select... (2 Replies)
Discussion started by: srilinux09
2 Replies

2. Shell Programming and Scripting

Calling shell script within awk script throws error

I am getting the following error while passing parameter to a shell script called within awk script. Any idea what's causing this issue and how to ix it ? Thanks sh: -c: line 0: syntax error near unexpected token `newline' sh: -c: line 0: `./billdatecalc.sh ... (10 Replies)
Discussion started by: Sudhakar333
10 Replies

3. Shell Programming and Scripting

Help with FTP Script which is causing "syntax error: unexpected end of file" Error

Hi All, Please hav a look at the below peice of script and let me know if there are any syntax errors. i found that the below peice of Script is causing issue. when i use SFTP its working fine, but there is a demand to use FTP only. please find below code and explain if anything is wrong... (1 Reply)
Discussion started by: mahi_mayu069
1 Replies

4. Shell Programming and Scripting

Error in calling a shell script from another script

HI, We are using two shell scripts, script.sh,env.sh, where env.sh will be called inside script.sh. The variable inside env.sh is used as $var in script.sh.But while running the script its not identifying that variable. Is there any permission needed to call a script inside another script. ... (3 Replies)
Discussion started by: banupriyat
3 Replies

5. UNIX for Dummies Questions & Answers

Re: Script Error [syntax error at line]

Hi , I Have Written A Simple Script To Check Greatest Of '2' Number When Execuating The Script I Am Getting The Below Error SP11: if:not found SP11: line 4:syntax error at line 5:'then' unexpexted And The Program I Have Wrriten For This #!bin/ksh echo "Enter Two Numbers"... (3 Replies)
Discussion started by: anudeepkumar123
3 Replies

6. Shell Programming and Scripting

Syntax error calling TCL script from shell script

hello everyone i am beginner on shell scripting .and i am working on my project work on ad hoc network i wrote a batch (.sh) to do a looping and execute a tcl script i wrote before in each iteration ..but i got this problem " syntax error near unexpected token `('... (1 Reply)
Discussion started by: marcoss90
1 Replies

7. Shell Programming and Scripting

How to grep sql error in shell script and exit the script?

I need help in the following script. I want to grep the sql errors insert into the error table and exit the shell script if there is any error, otherwise keep running the scripts. Here is my script #!/bin/csh -f source .orapass set user = $USER set pass = $PASS cd /opt/data/scripts echo... (2 Replies)
Discussion started by: allinshell99
2 Replies

8. Windows & DOS: Issues & Discussions

Error opening script file - location error

Hello, I know nothing about UNIX, ftp, etc. I am building an excel VBA macro which calls a .bat file. I've taken a pre-existing batch file and am trying to modify it to fit my purposes. I would be very grateful for some assistance. Here is my .bat file: echo off set... (9 Replies)
Discussion started by: starcraftbud
9 Replies

9. Shell Programming and Scripting

Script with error output but continuation in script?

I have written a basic fetching script. The script logs into an FTP site, downloads a .zip file, then unzips and moves the files to the necessary folders, then deletes them, etc. The problem I have is if one of the files no longer exists on the FTP site or another part of the script fails, then... (3 Replies)
Discussion started by: daem0n
3 Replies

10. UNIX for Dummies Questions & Answers

awk Shell Script error : "Syntax Error : `Split' unexpected

hi there i write one awk script file in shell programing the code is related to dd/mm/yy to month, day year format but i get an error please can anybody help me out in this problem ?????? i give my code here including error awk ` # date-month -- convert mm/dd/yy to month day,... (2 Replies)
Discussion started by: Herry
2 Replies
Login or Register to Ask a Question