Simple issue, what is wrong?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Simple issue, what is wrong?
# 1  
Old 12-06-2010
Simple issue, what is wrong?

I had this working a few days ago but I since changed it. Heres the code

Code:
x=1
while [x = 1] 1 2 3 4 5 6
1=$(ps -ef | grep process | awk '{ print $2}')
if [ -n "$1" ]
 then
      echo "The database is accepting connections..."
  echo "Now I will check the next process"
  
   2=$(ps -ef | grep process1 | awk '{ print $2}')
    if [ -n "$2" ]
     then
          echo "Start The Process 4"
     else
          echo "Start Process3"
      cd /dir/dir/
      StartProcess3.sh
      sleep 10
      echo "Processes 3 started, start process 4!"
    fi
 else
      echo "The database isn't accepting connections"
  sleep 30
fi

I run this script and get this

Code:
test.sh[2]: syntax error at line 8 : `if' unmatched

# 2  
Old 12-06-2010
Code:
while [ condition ]
do
...
done

Code:
ps -ef | grep process | awk '{ print $2}'

could be shorten
& could save a pipe :
Code:
ps -ef | awk '/process/{ print $2}'

This User Gave Thanks to ctsgnb For This Post:
# 3  
Old 12-06-2010
I am now getting this

Code:
test.sh[2]: syntax error at line 26 : `done' unexpected

# 4  
Old 12-06-2010
Quote:
x=1
while [x = 1] 1 2 3 4 5 6
The above two lines don't do anything useful and are upsetting the syntax of your script. Try commenting them out to see if your syntax error goes away.



Quote:
1=$(ps -ef | grep process | awk '{ print $2}')

2=$(ps -ef | grep process1 | awk '{ print $2}')
Btw. It is very unusual to try to change the values of $1, $2 etc. and my Shell will not allow that syntax.

Overall it is not really clear what the script is meant to achieve.
Can you post what Operating System you are running and what Shell you are using.
# 5  
Old 12-06-2010
ksh / aix
# 6  
Old 12-06-2010
I agree Methyl :
a) $1 and $2 : it may be a bad idea to use them that way
b) your while synthax seems geoparadized (or you are using a shell i have never met before)
# 7  
Old 12-06-2010
I apologize. I changed the names of things to keep any proprietary information out.

The script needs to check if a database is in connecting status.
If it is, check if another process is running
if it is running, kick off "script1"
if it isnt running, start it, and then kick off "script1"

It needs to do this 5 times and after the 5th try, just end.

If the database isn't accepting, just sleep then end.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Wrong test interpretation for simple function.

Hello everyone, I have written simple script below to check if ip is added to interface #!/usr/local/bin/bash IFCONFIG="/sbin/ifconfig" SERVICE="/usr/sbin/service" IP="79.137.X.X" GREP=$(${IFCONFIG} | grep ${IP}) ip_quantity_check () { echo ${GREP} | wc -l } if ];... (2 Replies)
Discussion started by: bryn1u
2 Replies

2. Shell Programming and Scripting

I have no idea what is wrong with my simple script.

I am doing a simple "recycle bin" script. It is to check and see if the directory .TRASH exists within the home directory. If not then it makes the directory then appends a date and time to file and then finally moves the file in. However, when I run this script, it is not making the directory as... (5 Replies)
Discussion started by: iamdeman
5 Replies

3. Shell Programming and Scripting

Simple SED issue

Hi! I'm a newbie and can't find the exact sed to make this work. I've installed CentOS and am trying to pass variables to a network-config file. variables: $ipAddress $netmask $gateway file: DeviceList.Ethernet.eth0.IP=192.168.1.10 DeviceList.Ethernet.eth0.Netmask=255.255.255.0... (5 Replies)
Discussion started by: greipr
5 Replies

4. Shell Programming and Scripting

Simple Cut issue

I have a long string that looks something like this.... <string>http://abc.com/40/20/zzz061-3472/dP3rXLpPPV2KC846nJ4VXpH7jt4b3LJgkL/tarfile_date.tar</string> I need to but the tar file name. So I need to put between "/" and ".tar</string>". My desired result should be "tarfile_date". (7 Replies)
Discussion started by: elbombillo
7 Replies

5. UNIX for Dummies Questions & Answers

What's wrong with this simple program in APUE?

I start wetting my toes in Linux programming. I tried the first program myls.c in Advanced Programming in the Unix Environment. #include <sys/types.h> #include <dirent.h> #include "apue.h" int main(int argc, char *argv) { DIR *dp; struct... (1 Reply)
Discussion started by: cqlouis
1 Replies

6. Shell Programming and Scripting

Simple date issue

Hi all, i have used the search already before someone shouts at me and i have seen the 'datecalc' program but this is not working correctly for me in the shell and environment i am using. I am using solaris 10 and bourne shell. I have two dates '07-04-2009' and '05-05-2009'. I just need to... (2 Replies)
Discussion started by: muay_tb
2 Replies

7. Shell Programming and Scripting

Perl Script issue. What am I doing wrong?

#!/usr/local/bin/perl open (MYFILE, 'logs_report'); while (<MYFILE>) { $rec=$_; chomp ($rec); @arr=split(/ /,$rec); print $rec,"\n" if ($arr!~/OK/); open (MYF, '>data.txt'); print $rec,"\n" if ($arr!~/OK/); close (MYF); (14 Replies)
Discussion started by: SkySmart
14 Replies

8. UNIX for Advanced & Expert Users

simple issue..

I have a program. Everytime that I run that program ,it prints a disclaimer msg and prompts the user to accept the agreement (i.e: type 'y' or 'n'). Now I want to run the program multiple times with different inputs. So I wrote a script which runs in a loop and calls the program multiple times.... (2 Replies)
Discussion started by: the_learner
2 Replies

9. Shell Programming and Scripting

What's wrong with this simple statement?

I know that this is a ridiculously simple statement, but I am getting an error when I execute it, and I can't figure out what it is. Can anyone point me in the right direction? #!/bin/ksh integer dateMonth=0 integer intZero=0 if then dateMonth = 1 fi echo $dateMonth (7 Replies)
Discussion started by: mharley
7 Replies

10. UNIX for Dummies Questions & Answers

What is wrong with this simple script?

The script below is supposed to list file and folder names and list the type besides each - It has no practical value - I am just trying to learn KSH (so far sounds like a bad idea!) Expected output should look like this: folder 1 *** dir *** file1 * file * The code runs but produces... (9 Replies)
Discussion started by: GMMike
9 Replies
Login or Register to Ask a Question