473,243 Members | 1,578 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,243 software developers and data experts.

Reading Shell Script Results

Group,

I want to get into a remote server, tail a file, and see if the last
line is an error or not. I think that I've figured out how to shell
over and tail the file. I have the specific server information and
filename/location all stored in a database. I can't figure out how to
get the result of the tail into a variable so that I can search it for
an ERROR string. Any ideas?

thanks in advance,

melih

Jul 17 '05 #1
3 2508
Sorry to clutter everyone's box, but it turns out that exec is already
built to do this. The answer to the question is use the exec function.

melih

Jul 17 '05 #2
me***********@gmail.com wrote:
Group,

I want to get into a remote server, tail a file, and see if the last
line is an error or not. I think that I've figured out how to shell
over and tail the file. I have the specific server information and
filename/location all stored in a database. I can't figure out how to
get the result of the tail into a variable so that I can search it for
an ERROR string. Any ideas?

thanks in advance,

melih


Hi,

If you can write the command (including the tail) and execute succesfully in
a shell, you can also give it to PHP and let PHP execute it.
Then you catch the result.

http://nl2.php.net/manual/en/ref.exec.php

It contains many usefull links to functions you might want to use.

I think shell_exec is usefull for you, but just scan through them and decide
for yourself.

shell_exec:
Execute command via shell and return the complete output as a string

Hope that helps.

Regards,
Erwin Moller
Jul 17 '05 #3

To the original poster, melih:

You could use
if [ "`tail file | grep blah`" ]; then
echo got it
fi
to check if the tail end of file "file" contains "blah", and if it
does, then do something like echo "got it". This is just an example.
I don't know what file you're tailing, what you're looking for in it,
or what you do when you find it. Maybe this will give you some ideas.

Let me explain what this does. Block if statements in bash shell
scripts (seems to me that you are using bash? I'm a Linux programmer
and new to Mac OSX.) well they start with "if" and end with "fi". In
between go the instructions you want to execute, on one or more lines.
To keep it simple, put one instruction on each line.

Notice the use of square brackets in the first line. The left one has
a space on both sides. This matters. The right one has a space on
the
left and a semicolon on the right followed by a space. This matters
also. In the middle is a string delimited by double quotes. For the
moment ignore what is in the double quotes. What we are doing here
just testing the logical value of a string. Well, this is easy. When
done this way a string is true when it is not empty. For example,
this
is false
""
and this is true
"anything in the quotes"
So what have I put in the quotes? I have put in the quotes the result
of "tail file" piped through "grep blah". Try this at the command
line
tail file | grep blah
where "file" is some file in your current directory and "blah" is some
text that file either contains or doesn't contain. Try it both
ways--blah as something in the file and blah as something not in the
file. Note | is a pipe. It is a character that often shares the \
key. It is not
a 1, l or I (one, letter L or letter I) even though it might look like
that.

You will see that if grep finds blah in the tail end of the file that
the above test prints something.

So now look at the ` marks that are just inside the " marks. These
marks are called "single back quotes". The key often shares the ~.
Not the ' which shares the ". A pair of single back quotes means
execute what is inside of the quotes and put the output of the
execution here
The result is that the above script will output
got it
If file "file" contains "blah".

Does all this make sense? The bash shell scripting language is a
venerable, old language, and it is in some ways archaic. Yet, it is
still very widely used and is awesomely powerful especially when used
together with the normal linux command set.

I'm going to stop in a moment, as I've probably given too much help
already. One more clue. You asked for a way to put the results of
tail into a variable. I don't know why you want to do it, but try
this:
found=`tail file`
Again, those are single back quotes.

Do this to see the results of what was found:
echo $found


Have fun!

-Joe
--
jroseve
------------------------------------------------------------------------
jroseve's Profile: http://www.macosx.com/forums/member.php?userid=38248
View this thread: http://www.macosx.com/forums/showthread.php?t=229387
macosx.com - The Answer to Mac Support - http://www.macosx.com

Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Laura P | last post by:
Hi, I wasn't sure whether this should be posted in the Java are or in a Solaris thread, so I shall post it in both. Sorry for the duplication. I am new to Solaris and am having trouble...
1
by: speedster | last post by:
Hi. I need some help converting some php to perl. $meminfo = shell_exec( "free -o" ); I need to execute "free-o" in shell and get the results. It grabs memory information about a linux...
2
by: Shabam | last post by:
Up to now I've been doing this manually via the command shell. However I'm sure I can automate this using a script with better results. Can someone show me how I can do this? cp -pr...
1
by: David Kanter | last post by:
Hi, I have some VB scripts which start by opening an application, in this case it is a game called FEAR (some of you may be familiar). I am using Visual Studio 2005 Professional Edition running...
4
by: Anastasios Hatzis | last post by:
I'm looking for a pattern where different client implementations can use the same commands of some fictive tool ("foo") by accessing some kind of API. Actually I have the need for such pattern for...
3
by: telduivel | last post by:
Can someone please help me with this: I have a python script, that at some point calls a linux bash script (.sh). Starting the shell script is the last thing my python script needs to do, so I...
5
by: dg.google.groups | last post by:
Hi all, Is there any standard way to tell if the user is running from a module or from an interactive shell like IDLE or IPython? The best I've come up with so far is for a function to look at...
5
by: inetquestion | last post by:
I am looking for a web interface for shell commands or shell scripts. Does anyone know of any exexisting php scripts which would solve this requirement? PHP form accepts input from a user, then...
7
by: Samuel A. Falvo II | last post by:
I have a shell script script.sh that launches a Java process in the background using the &-operator, like so: #!/bin/bash java ... arguments here ... & In my Python code, I want to invoke...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.