UNIX command that says "proceed to the next command"?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting UNIX command that says "proceed to the next command"?
# 1  
Old 02-19-2009
Question UNIX command that says "proceed to the next command"?

Unix gurus,

I have a requirement to check whether a db is running or not and send an email if any or all of them are not running.

I have written the code for checking (in the same order):

1. the database processes
2. the listener process
3. the database login

If the database background processes (i.e., unix processes) are not running, then send email and this is working fine.

If they are running, then continue to the next check i.e., listener process. This is where I'm having problems.

I would like to know if there is any command that I can use in my if construct that says "proceed to the next command"?

Note:

1. I know that I can't use the continue command as I am using a loop and it will go to the next iteration skipping the required checks.

2. I know that I can totally remove the else part of the IF construct but I'm curious to know if there is any command that says "proceed to the next command".

3. send_mail is also a function that uses mailx to send emails.

Code:
 
## Call function to check background processes.
check_bkgrnd_process ${sid}
if [[ $? -ne 0 ]]; then
## Problem with background processes. Send email.
send_mail "${BKGRND_PROCESS_ERR_SUB}" "${MAIL_LIST}" "${BACKGRND_CHK_TMPFILE}"
else
## No problem with background processes. Send test email anyway.
##send_mail "${BKGRND_PROCESS_ERR_SUB}" "${MAIL_LIST}" "${BACKGRND_CHK_TMPFILE}"
fi
 
## Call function to check the db listener.
check_db_listener
if [[ $? -ne 0 ]]; then
## Problem with database listener. Send email.
send_mail "${LISTENER_CHK_ERR_SUB}" "${MAIL_LIST}" "${LISTENER_CHK_TMPFILE}"
else
## No problem with database listener. Send test email anyway.
##send_mail "${LISTENER_CHK_ERR_SUB}" "${MAIL_LIST}" "${LISTENER_CHK_TMPFILE}"
fi
 
## Call function to check database login.
check_db_login
if [[ $? -ne 0 ]]; then
## Error thrown - Issue with logging in to the database.
send_mail "${DB_LOGIN_ERR_SUB}" "${MAIL_LIST}" "${DB_LOGIN_CHK_TMPFILE}"
else
## Success - Send a test email anyway.
##send_mail "${DB_LOGIN_ERR_SUB}" "${MAIL_LIST}" "${DB_LOGIN_CHK_TMPFILE}"
fi

# 2  
Old 02-19-2009
What you need is a no-op command. And the best in sh/ksh/bash is the : command:

Code:
if some_program ; then
     :
else
     echo fumble >&2
fi

# also good for infinite loops
while : ; do
      echo hello world
done

: is a built-in command and runs very fast
# 3  
Old 02-19-2009
You mentioned wanting to keep the "else" part. Is that because you have other commands you want to run on occasion?

There is "break" which can be used from within loops. So you could have:
Code:
..
else
  while true; do
     echo yes
     if .... ; then
         echo email something
         break;
     else
         echo do soemthing else
     fi
  done
  echo Continuing from break or end of else
fi


Last edited by otheus; 02-19-2009 at 05:40 AM.. Reason: needed code end tag
# 4  
Old 02-20-2009
@Otheus, no I don't have any commands to run in the else part. However, I wanted to know if there is a single command (not echo "" > file) that I can use to proceed to the next command.

Moreover, the IF construct is inside a for loop and hence, I can't use the "break" or "continue" commands too.

@Perderabo, yes seems like you've hit the bulls eye. That is exactly what I wanted.

Thanks for your valuable suggestions. Smilie

Regards,

Praveen
# 5  
Old 02-20-2009
Other "null commands" include:
  • true
  • false
  • test
  • echo -n
  • eval
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

2. UNIX for Dummies Questions & Answers

New to Unix command line and have a question about the "sort" command

I am going through the Unix Made Easy second edition book by John Muster. So far it's been very informative and I can tell it may be a bit out of date. In one of the exercises it talks about the "sort" command and using it to sort column's of data etc. The "sort" command has changed a bit and... (1 Reply)
Discussion started by: budfoxcat
1 Replies

3. UNIX for Dummies Questions & Answers

Unix "look" Command "File too large" Error Message

I am trying to find lines in a text file larger than 3 Gb that start with a given string. My command looks like this: $ look "string" "/home/patrick/filename.txt" However, this gives me the following message: "look: /home/patrick/filename.txt: File too large" So, I have two... (14 Replies)
Discussion started by: shishong
14 Replies

4. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

5. Shell Programming and Scripting

Identify high values "˙" in a text file using Unix command

I have high values (such as ˙˙˙˙) in a text file contained in an Unix AIX server. I need to identify all the records which are having these high values and also get the position/column number in the record structure if possible. Is there any Unix command by which this can be done to : 1.... (5 Replies)
Discussion started by: devina
5 Replies

6. Shell Programming and Scripting

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

7. UNIX for Advanced & Expert Users

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

8. UNIX for Dummies Questions & Answers

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

9. Shell Programming and Scripting

How to distinguish between "command not found" and "command with no result"

system() call imeplemented in solaris is such a way that: Command not found - return code 1 Command executed successfully without Output - return code 1 how to distinguish between these two based on return code in a c - file? Can you help on this ? (5 Replies)
Discussion started by: iitmadhu
5 Replies

10. UNIX for Dummies Questions & Answers

Unix "at" / "Cron" Command New Problem...Need help

Hi All, I am trying to schedule a one time job using the at command with the help of shell script for my project. The shell script should take a parameter as a command line argument from the at command itself. Is it possible to take a command line parameter for a shell script in the command... (3 Replies)
Discussion started by: Mohanraj
3 Replies
Login or Register to Ask a Question