LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 11-19-2008, 12:25 PM   #1
cameleon666
LQ Newbie
 
Registered: Nov 2008
Posts: 10

Rep: Reputation: 0
Variable present or not, syntax question....


if [ find /etc/httpd/conf.d/ -type f -exec grep -l 'redcube' {} \ ];
then
echo "Variable present"
else
echo "Adding Variable"
echo Include /etc/httpd/conf.d/redcube.include >> /etc/httpd/conf.d/zz010_psa_httpd.conf
fi

How to correct it, when string redcube found just show variable present if not add it at end of file.
 
Old 11-19-2008, 12:45 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,633

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by cameleon666 View Post
if [ find /etc/httpd/conf.d/ -type f -exec grep -l 'redcube' {} \ ];
then
echo "Variable present"
else
echo "Adding Variable"
echo Include /etc/httpd/conf.d/redcube.include >> /etc/httpd/conf.d/zz010_psa_httpd.conf
fi

How to correct it, when string redcube found just show variable present if not add it at end of file.
Correct what?? What's your question, and what are you trying to do, and what's not working? On what version/distro of Linux? Please clarify.
 
Old 11-19-2008, 12:49 PM   #3
dave201
LQ Newbie
 
Registered: Oct 2005
Location: Camelot
Distribution: cent, RH core, slax, slackware... *buntu...
Posts: 28

Rep: Reputation: 15
i believe you want to use "$?" which is a system variable that contains a number based off the *last* commands success.

here is some code i wrote last year making use of the $? var

Code:
        while read line 
        do
            inputfile=`echo $line |cut -d\| -f3 |cut -c1-6`
            grep ${inputfile} ${TEMPDIR}/bleh.run.tmp > /dev/null
            if [ $? != 0 ]; then
                grep $inputfile ${TEMPDIR}/bleh.tmp  | head -1 >> ${TEMPDIR}/blehReadyToGo.tmp
            fi
        done < ${TEMPDIR}/bleh.tmp
 
Old 11-19-2008, 01:06 PM   #4
cameleon666
LQ Newbie
 
Registered: Nov 2008
Posts: 10

Original Poster
Rep: Reputation: 0
thx guys

well i want to make a script that will read file zz010_psa_httpd.conf file and search for redcube text, if this text is found script will exit, if there are no redcube text in that file it will add other text - at end of this file.

sorry for my english...

this script will run by cron everyday.
 
Old 11-19-2008, 01:19 PM   #5
dave201
LQ Newbie
 
Registered: Oct 2005
Location: Camelot
Distribution: cent, RH core, slax, slackware... *buntu...
Posts: 28

Rep: Reputation: 15
Code:
#!/bin/bash

zz010="/path/to/zz010_psa_httpd.conf"

cat $zz010 |grep redcube > /dev/null
if [ $? != 0 ]; then
     echo "redcube" >> $zz010
fi
explanation... assign the path to your file to the variable zz010.

cat the variable (which is really your file), and grep for the word "redcube", and send any output to /dev/null (deletes it)

if the last command was successful, do nothing and exit the program.

if the last command failed, append the word redcube to the variable $zz010
 
Old 11-19-2008, 01:24 PM   #6
cameleon666
LQ Newbie
 
Registered: Nov 2008
Posts: 10

Original Poster
Rep: Reputation: 0
thx mate
that is what i wanted

cach a beer
 
Old 11-19-2008, 02:03 PM   #7
dave201
LQ Newbie
 
Registered: Oct 2005
Location: Camelot
Distribution: cent, RH core, slax, slackware... *buntu...
Posts: 28

Rep: Reputation: 15
cheers man
 
  


Reply



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
passing a shell variable into awk - syntax for correct interpretation? johnpaulodonnell Programming 3 06-19-2007 12:13 PM
ndiswrapper shows 'driver present, hardware present' but no wlan0 0x12d3 Linux - Wireless Networking 2 05-11-2007 07:43 PM
env variable for proxy: syntax FrayAdjacent Linux - Networking 10 07-13-2005 05:44 PM
ndiswrapper - driver present:harware present but no connection esteeven Linux - Wireless Networking 2 12-26-2004 04:06 PM
Syntax question satimis Linux - Newbie 4 10-08-2003 09:33 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:44 PM.

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