I am obviously new to Unix Script writing, and I think I am trying to do this in SQL when im not in a SQL environment. What I need to do is the following
I have been studing the IF man pages but they dont seem to do what I need. Im probably overlooking something, can you point me in the right direction?
It does appear that you're using SQL syntax in the shell
What shell do you use? What platform? (uname -a; echo $SHELL)
The syntax of `if` varies by shell and version, somewhat - here's an example that should work in bash, ksh, or POSIX shell (make sure to test it first!):
There's got to be dozens of ways to do this; this is just one way that should work in many shells.
Your problem is you are looking in the wrong place. ;-)
The shell construct "if [ ...] ; then" is utilizing a command external to the shell: /usr/bin/test. In fact "[....]" is just an alternative way to write "test ...." and branch on the errorlevel (return value) of this command.
You have the following (basic) options in test, more to be found on the manpage of test:
(for the following we assume x=5 and y=10)
-gt "greater then" compare (integer) values: test $x -gt $y => returns FALSE
-ge "greater or equal"
-lt "lower then"
-le "lower equal"
-eq "equal"
-ne "not equal"
-a logical AND. Example: test "$x -gt 0 -a $y -ge x" => returns TRUE
-o logical OR. Analogous to above
\(...\) grouping. Example: test "\( $x -gt 0 \) -a \( $y -gt $x -o $y -gt 0 \)"
-n non-zero TRUE if a string is not empty
-z zero TRUE if a string is empty ("")
It does appear that you're using SQL syntax in the shell
What shell do you use? What platform? (uname -a; echo $SHELL)
The syntax of `if` varies by shell and version, somewhat - here's an example that should work in bash, ksh, or POSIX shell (make sure to test it first!):
There's got to be dozens of ways to do this; this is just one way that should work in many shells.
To answer your question:
Do you know of a good web page that discribes the switches to your command well? I beleve that is what is confusing me the most.
Your problem is you are looking in the wrong place. ;-)
The shell construct "if [ ...] ; then" is utilizing a command external to the shell: /usr/bin/test. In fact "[....]" is just an alternative way to write "test ...." and branch on the errorlevel (return value) of this command.
You have the following (basic) options in test, more to be found on the manpage of test:
(for the following we assume x=5 and y=10)
-gt "greater then" compare (integer) values: test $x -gt $y => returns FALSE
-ge "greater or equal"
-lt "lower then"
-le "lower equal"
-eq "equal"
-ne "not equal"
-a logical AND. Example: test "$x -gt 0 -a $y -ge x" => returns TRUE
-o logical OR. Analogous to above
\(...\) grouping. Example: test "\( $x -gt 0 \) -a \( $y -gt $x -o $y -gt 0 \)"
-n non-zero TRUE if a string is not empty
-z zero TRUE if a string is empty ("")
I hope this helps.
bakunin
This looks a bit more streight forward to me...but again do you have a detailed link that can clear up some questions for me.
It does appear that you're using SQL syntax in the shell
What shell do you use? What platform? (uname -a; echo $SHELL)
The syntax of `if` varies by shell and version, somewhat - here's an example that should work in bash, ksh, or POSIX shell (make sure to test it first!):
There's got to be dozens of ways to do this; this is just one way that should work in many shells.
One more question, If I am using the above code, how would I put in a second action if the test fails to terminate the script? Do I just use a ; after the log file is wrten and say end?
This looks a bit more streight forward to me...but again do you have a detailed link that can clear up some questions for me.
No need for a link, just enter "man test" on your commandline and be enlightened. ;-))
Quote:
Originally Posted by jadionne
For example
what is the => representing here?
Nothing. I just explained above, that in my example i assume x to be 5 and y to be 10. And if you ask "is x greater than y" this would return a logical FALSE. You could test this by entering the following on your commandline:
Line 3 would print "1", which is a logical "FALSE" and line 4 would print a "0", which is a logical TRUE.
I have big large snapshot file which contains every process start time and end time. One server snapshot contains many Application handle. My task is to identify the process id for which the end time is not there or empty also if the completion time is not on the same date then I need to kill.
... (6 Replies)