File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Linux / UNIX and the fly likes conditional question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "conditional question" Watch "conditional question" New topic
Author

conditional question

Jason Kretzer
Ranch Hand

Joined: May 31, 2001
Posts: 280
Sorry about this newbie question but I am new scripting.
Here is my script.

#!/bin/bash
if [ ps -axf|grep -c "/sbin/mingetty" -eq 6 ]; then
echo yep
else
echo nope
fi

I have also tried this with single quotes around /sbin/mingetty and with cancelled parentheses for better grouping. When I run it as above, I get the followin lines.
test: [: missing `]'
/sbin/mingetty:3
grep: 6: No such file or directory
grep: ]: No such file or directory
nope
for some reason it looks like it is not grouping correctly. Any ideas?


Jason R. Kretzer<br />Software Engineer<br />System Administrator<br /><a href="http://alia.iwarp.com" target="_blank" rel="nofollow">http://alia.iwarp.com</a>
James O'Dell
Greenhorn

Joined: Apr 29, 2002
Posts: 16
Jason,
You just need to put backticks (`) around your ps command:

The backticks execute the command and return the value in place.
The "backtick" is the character that's usually on the same key as the tilda (~) for those that may not be familiar with the term.
Jim
[ September 02, 2002: Message edited by: James O'Dell ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: conditional question
 
Similar Threads
grep
PATH & CLASSPATH?
Environment Variable
Search on a string