Sponsored Content
Top Forums Shell Programming and Scripting Is there a simpler way to achieve this? Post 302416018 by Franklin52 on Saturday 24th of April 2010 11:10:20 AM
Old 04-24-2010
Quote:
Originally Posted by mlott
Hi all

I have the following which is part of a larger interactive script for adding virtual hosts to Apache's configuration (it was built for non-technical administrators). I'm curious as to whether there is a simpler way of achieving the same thing. All it does is look into the /etc/httpd/sites-enabled/ directory and check if the user is adding a FQDN that is already live, and if so, prompts them to add a different FQDN:

Code:
#!/bin/sh

queryFQDN()
{
declare -a VHOST
VHOST=( $(ls -1 /etc/httpd/sites-enabled/) )
printf "What is the Fully Qualified Domain Name?\n"
read FQDN
for i in ${VHOST[@]};do
        if [ "$i" == "$FQDN" ];then
        return 1
        fi
done
}

queryFQDN

while [ "$?" -eq "1" ];do
printf "FQDN already exists.\nYou will have to choose another value.\n"
queryFQDN
done

exit 0

Any ideas would be most appreciated.

Mike
Maybe something like this?
Code:
queryFQDN()
{
  printf "What is the Fully Qualified Domain Name?\n"
  read FQDN

  if [ -z $FQDN ]
  then
    return 1
  fi

  if ls /etc/httpd/sites-enabled/$FQDN >/dev/null 2>&1
  then
    return 1
  fi

}


Last edited by Franklin52; 04-24-2010 at 12:22 PM.. Reason: adding -z test statement
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

is there a way to achieve this with compress?

I'm trying to figure out how I can get an equivalent output to a text file such as if I use gunzip -l filename in that gunzip will output the previous file size and the compressed size and the ratio... is there a way to achieve this with compress and zip? i am very new at shell... (3 Replies)
Discussion started by: nortypig
3 Replies

2. Shell Programming and Scripting

how to achieve following parallel processing thru unix

hey...... i hav the follwing scripts needs to run parallel, so i made it as follows, $HPath/start_script.sh 20 & $HPath/start_script.sh 03 & $HPath/start_script.sh 01 & $HPath/start_script.sh 12 & then once all these above got completed successfully i have to run ... (3 Replies)
Discussion started by: manas_ranjan
3 Replies

3. UNIX for Dummies Questions & Answers

Do i need a script to achieve this?

Hi all, i have a following folder call 'zz'. This 'zz' folder is found in the following directories. I would like to delete the zz in the following directories /aa/zz /aa/bb/cc/zz /aa/bb/cc/dd/zz /aa/bb/cc/dd/ee/zz and keep the zz folder in the following directories /WW/zz ... (1 Reply)
Discussion started by: new2ss
1 Replies

4. Programming

How to achieve Serialization in Unix C, C++

How to achieve SERIALIZATION in Unix , C, C++ Write Objects directly to disk and read back ? (1 Reply)
Discussion started by: Sivaswami
1 Replies

5. Shell Programming and Scripting

How to achieve this?

hi to all, i have the input(text file) like the below... Header 1,2,3 4,5,6 7,8,9 Footer i need a output(text file) like the below... Header,1,2,3,Footer Header,4,5,6,Footer Header,7,8,9,Footer please help me to find out? (2 Replies)
Discussion started by: aaha_naga
2 Replies

6. UNIX for Advanced & Expert Users

how to achieve this output ?

in AIX ,HP Unix and in SUN solaris, how to find the logs by date and time, I mean , Logs which have been generated or updated most recently , which might be present in folders and sub folders, I need to get the list of these Logs along with location path. Example: ======== folder... (3 Replies)
Discussion started by: sidharthmellam
3 Replies

7. What is on Your Mind?

A simpler XML tool

We've been getting a lot of XML questions lately, and I suspect it's only going to get worse better ... Normal shell utilities just can't handle it and the "proper" solutions, do-everything perl modules or things like xmlstarlet, just make my head ache. Started coding something tonight. What... (10 Replies)
Discussion started by: Corona688
10 Replies

8. UNIX for Dummies Questions & Answers

Simpler next month year program

I have created this program to get the next month and year. Is there a simpler way. #!/bin/ksh string=`cat Date.txt` year=`echo $string | cut -c 1-4` month=`echo $string | cut -c 5-6` echo $year$month mon=`expr $month + 1` if ; then mon=0$mon echo $mon fi if ; then month=01 ... (2 Replies)
Discussion started by: w020637
2 Replies

9. Shell Programming and Scripting

Need simpler version of these commands

Hi all, I am trying to grep a file with the word grand and get all the fields.. Then replace multiple spaces with single space and then get 8 th field and add all these numbers . I am able to do it but with so amny commands which i feel can be done in a simpler way Please let me know if... (4 Replies)
Discussion started by: Hypesslearner
4 Replies
All times are GMT -4. The time now is 01:01 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy