473,545 Members | 1,310 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2532
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***********@g mail.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
12059
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 running a long Java command from a shell script. Firstly, my Solaris (8) / Java setup. Mu machine already had Java 1.2
1
4985
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 webserver. If it is also possible to run a regular expression on this data that would also be great. It then outputs it in a nice format.
2
8302
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 /site/template/user /site/j/jason cp -p /site/data/j/jason.dat /site/data/j/jason.dat; pico -w /site/data/j/jason.dat In pico I'm basically changing the...
1
984
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 on Windows XP x64. I am using the script on the same system. I can open FEAR manually on the system; I just double click the short cut and...
4
2364
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 my own tool (http://openswarm.sourceforge.net). I already started restructuring my code to separate the actual command implementations from the...
3
5439
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 would like for the python script to exit once the call has been made, without waiting for the shell script to finish. My question is: how do I call...
5
1810
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 getouterframes(currentframe()) (the filename in the frame record of the frame that called the function), and check if it exists or not with...
5
5070
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 passes these as arguments to a configurable shell script or OS command. I would like for the output generated from the shell script/command shall...
7
6212
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 this shell script using the Subprocess module. Here is my code: def resultFromRunning_(command):
0
7457
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7391
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7651
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
5962
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5320
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3443
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3438
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1869
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
693
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.