Simple issue, what is wrong?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Simple issue, what is wrong?
# 8  
Old 12-06-2010
ps will only show you the current processes, it will NOT tell you whether the database accept new connections or not.
This User Gave Thanks to ctsgnb For This Post:
# 9  
Old 12-06-2010
When I grep for the one process, that is all that we need to show that the database is accepting new connections.

Normally, if you do a ps -ef | grep <process> it brings back a bunch of running processes.

Code:
root  221352  581886   0   Nov 21      -  0:46 process-database: db (idle) 
    root  262310  581886   0   Nov 21      -  0:37 process-database: db (idle) 
    root  290860  581886   1   Nov 21      -  0:41 process-database: db (idle) 
    root  553002  581886   0   Nov 21      -  0:46 process-database: db (idle) 
    root  581886       1   0   Nov 21      -     0:05 process-database: (accepting)

If I do this command..
Code:
ps -ef | grep '[p]rocessd.*(accepting)

It returns what I am looking for

---------- Post updated at 03:14 PM ---------- Previous update was at 11:45 AM ----------

I did my best to clean up the code. Can anyone help with including a for loop in this. It needs to run 5 times (If the first argument is false and the database isnt accepting connections) If it gets past the first part it can just run then.

Code:
 
database=$(ps -ef | grep '[d]atabase.*(accepting)' | awk '{ print $2}')
if [ -n "$database" ]
 then
      echo "The database is accepting connections"
 
  process=$(ps -ef | grep [p]rocess | awk '{ print $2}')
   if [ -n "$process" ]
    then
         
         echo "Start  Automated Processes"
          ###START OTHER SCRIPT###
    else
          echo "Start Processe".
          cd /home/user/dir/process
          sleep 10
          ###START OTHER SCRIPT###
   fi

   
 else
      echo "The database is not accepting connections..."
  sleep 30
 
fi
 
done

# 10  
Old 12-07-2010
Wrench

The sleep 30 seems useless, as well as the done
Or you miss the while loop ?

By the way, since you only test $database and $process value to know if they are empty or not, i don't see the use of the | awk '{...}' stuff

You could just use such kind of condition (this is just an example, adapt it to your needs) :

Code:
if ( grep [d]atabase.*accepting <(ps -ef) >/dev/null 2>&1 )
then
    echo "Process 'accepting' found"
else
    echo "Process 'accepting' not found"
fi


Last edited by ctsgnb; 12-07-2010 at 05:16 AM..
# 11  
Old 12-07-2010
Thank you all for the help. Turns out, I had a bunch of carriage returns in my code which were causing issues.
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