Register a domain and help support LQ
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 04-02-2012, 12:48 PM   #1
Registered: Apr 2011
Location: Philadelphia
Posts: 158

Rep: Reputation: 3
Running if statement from command line?

Hello All,

We have some software that we use through a web browser that runs some reports by passing a command to the shell's command line.

Is it possible for me to write something like this (below) but make it into all one line to be issued on the command line...?

For example:

while (( $GREP_RETCODE != "0" ))
	ps -ef | grep -v grep | grep
	if [[ $GREP_RETCODE == 0 ]]
		exit 0
		##If NOT found sleep 1 and try the ps command again...
		sleep 1
If this doesn't make sense let me know and I'll try to clarify.

Basically what I'm trying to do is:
If the command "" is found I want to sleep for a moment and try again. If the cmd is not found in the ps -ef statement then Run the Report...

Any suggestions would be much appreciated.

Thanks in Advance,
Old 04-02-2012, 03:02 PM   #2
Registered: Sep 2003
Posts: 382

Rep: Reputation: 87
If is possible to strings shell commands together on a single line with semicolons, like this:

for f in `ls *`; do echo "$f"; done
However, unless there is some very good reason not to, you might want to consider placing the shell commands in a file, and executing the file. If the commands I used above were intended to be executed by bash, and the commands are in the file $HOME/src/bash/my_loop.bash then:

bash $HOME/src/bash/my_loop.bash
could be used to execute the commands.
Old 04-02-2012, 03:04 PM   #3
ReliaFree Maintainer
Registered: Aug 2004
Location: Kalamazoo, Michigan
Distribution: Slackware-current, Cross Linux from Scratch, Gentoo
Posts: 2,779
Blog Entries: 1

Rep: Reputation: 243Reputation: 243Reputation: 243
Assuming I made no typing errors, this should work....
GREP_RETCODE=1; while (($GREP_RETCODE != "0")); do ps -ef | grep -v grep | grep; GREP_RETCODE=$?; if [[ $GREP_RETCODE == 0 ]]; then exit 0; else sleep 1; fi; done
1 members found this post helpful.
Old 04-02-2012, 03:08 PM   #4
Registered: Apr 2011
Location: Philadelphia
Posts: 158

Original Poster
Rep: Reputation: 3
Hey kakaka, thanks for the reply!

Yea you may be right... I was thinking of something else and I'm thinking I was a bit off base.
But that for loop on the command line is going to help me out. Thanks...

Thanks Again,
Old 04-02-2012, 03:10 PM   #5
Registered: Apr 2011
Location: Philadelphia
Posts: 158

Original Poster
Rep: Reputation: 3
Hey weibullguy, thanks for the reply too!

Cool, thanks for that... I'm thinking I'm going to have to go back and re-think what I'm going to do. (sad face)
But really, thanks for your suggestion.

Thanks Again,


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Scripting question - feed an input file into an if statement line-by-line kmkocot Linux - Newbie 10 01-18-2010 11:49 AM
How Can I Use An "if" statement on a Single Command Line? jagooch Linux - General 4 02-10-2009 11:32 PM
Issue a command line statement from within a C/C++ program? DiBosco Programming 7 05-23-2008 07:34 PM
bash case statement with multiple command line options pwc101 Programming 16 06-01-2007 11:43 AM
Running programs from Command Line SirLostalot Linux - Newbie 1 11-11-2002 09:24 PM

All times are GMT -5. The time now is 09:51 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration