Confusion over a small conditional script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Confusion over a small conditional script
# 1  
Old 06-13-2007
Confusion over a small conditional script

Hi,

I was going through a file containing hundreds of lines of codes having conditional statement written as:

log()
{
echo $@
}

num=$(/usr/bin/rsh <one_machine> -l root 'ls -d /home/user/db* 2> /dev/null' | wc -w)
(( num > 0 )) && log "db info:"

so,if here the return value(stored in variable "num" is greater than 0) then
"db info"will be echoed on the screen.
But if i need to do more commands execution if the return value is > 0 then how can i add more statements here.

In past i've used something like this:
num=$(/usr/bin/rsh <one_machine> -l root 'ls -d /home/user/db* 2> /dev/null' | wc -w)
if [ "$num" -gt "0" ]; then
statement 1
statement 2
..................

statement N
fi

but how this can be used here ?

~amit
# 2  
Old 06-13-2007
Exactly as you've written:

Code:
num=$(/usr/bin/rsh <one_machine> -l root 'ls -d /home/user/db* 2> /dev/null' | wc -w)
if [ $num -gt 0 ]; then
log "db info: "
statement 1
statement 2
statement ... N
fi

-c
# 3  
Old 06-13-2007
Thx a lot craig!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Conditional Script

Hi, I have a script file which has some simple commands. I want these commands to be executed based on the input. Ia m good with IF statement also. At the end it has to be based on incoming value. Example CASE 1 : Execute some commands where Input value as 1 CASE 2 : Execute... (5 Replies)
Discussion started by: vrupatel
5 Replies

2. Shell Programming and Scripting

Conditional Execution of a Script.

I have a unix shell script Test.sh more Test.sh echo "Calling dbquery1.sh...." ./dbquery1.sh echo "Calling dbquery2.sh...." ./dbquery2.sh more dbquery1.sh sqlplus -s user1/password1@DB_SID @/tmp/storedprocedures/Hello.rcp I run Test.sh However, I do not want dbquery2.sh to be... (3 Replies)
Discussion started by: mohtashims
3 Replies

3. UNIX for Dummies Questions & Answers

Cron confusion - scheduling a script

I have a script that backs up a directory, creates a log file and mails the log file to us. find . -print | backup -ivqf/dev/rmt0 | tee backup.log cat backup.log|mail -v -s "Tape backup log" maillist This script works fine from the console. When I schedule it in cron, I never get the... (1 Reply)
Discussion started by: landog
1 Replies

4. UNIX for Dummies Questions & Answers

If Then ElseIf Script - Confusion Around Expression's Syntax

Hello, I am relatively new to UNIX scripting and am learning a lot. I have already tried several searches on this website and have tried various syntax options suggested to no avail. I am obviously not writing the script correctly. I really do appreciate any and all the help. Below is an... (8 Replies)
Discussion started by: dqrgk0
8 Replies

5. Shell Programming and Scripting

conditional confusion

Hell Unix.com Community: I am working on a personal project using yad v0.12.4 (zenity fork) and have hit a wall on how to show a progress bar while my function is processing. I have been all over the ABS Guide, googled 21 Linux-specific sites that I revere. I even asked on the yad-common... (4 Replies)
Discussion started by: Habitual
4 Replies

6. UNIX for Dummies Questions & Answers

need help with small script

Hi I have the below file Name=abc Yr=2011 Mon=05 My script should be in such a way that whenever I run it then Month should increment by 1 and if the month is 12 then when I run the script then year should incremented by 1 and month Should become 01(I.e jan) Thanks for the help in... (6 Replies)
Discussion started by: kishu
6 Replies

7. Shell Programming and Scripting

small script

Hi, I am new to unix shell scripting. I just want a little script to check the no. of processes are equal to 8, then echo a successful message otherwise echo a unsuccessful message. Please help. Thanks. (3 Replies)
Discussion started by: everurs789
3 Replies

8. Shell Programming and Scripting

Conditional Date Script

I am learning Unix for the first time. I am playing around with my default profile file to add some script in the KSH. The time format is GMT and I am in eastern time zone. I am trying to script some greetings based upon the time of day using the IF/ELIF conditions. I am getting errors. I have... (2 Replies)
Discussion started by: cpd259
2 Replies

9. Shell Programming and Scripting

small script help

here is a small script: if ; then echo please enter an argument fi if [ "$1" = "tom"; then a=$1 echo $a fi here is my question. if the script name is j.sh and I run it : j.sh from shell prompt: without a parameter: it prints please enter an argument but if I go with . j.sh (current... (1 Reply)
Discussion started by: rkl1
1 Replies

10. Shell Programming and Scripting

Need help in a small script

Hi all, I have a file of the following format - EXPRPT:SCN:1.1706E+10:SEQ_START:121652:SEQ_END:121664:0 ( This file name is variable and changes daily) Now in the same directory I have another set of files of the format - EXPRPT.log.0001.0000121669 Now what I am trying to do is to ... (2 Replies)
Discussion started by: super_duper_guy
2 Replies
Login or Register to Ask a Question