If option statement


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting If option statement
# 1  
Old 10-02-2013
If option statement

I working on my Apache2 restore script.

This is the code so far

Code:
updatedb
prompt_list "Whick configuration_backup file do you want to use?" `find /restore/configuration/ -name configuration_backup* -type d`
BACKUP_OBJECT=${CHOICE}
echo "--------------------------------------"

cd ${CHOICE}

tar_gz=`find @etc@apache2@mods-available.tar.gz @etc@apache2@mods-enabled.tar.gz @etc@apache2@ports.conf.tar.gz @etc@apache2@sites-available.tar.gz \
@etc@apache2@sites-enabled.tar.gz`

echo "Founded Apache2 tar.gz files"
echo "--------------------------------------"
echo "${tar_gz}"

#tar -zvf ${tar_gz}

if [ -f "{$tar_gz}" ]
then
        echo "found"
else
        echo "not found"
fi

My problem now is the if and else. I want that the if statement finds the @etc@apache2 tar.gz files that i found with the "find" cmd so i can continue to extract the tar.gz files and other commands.
Somebody knows the good variabel of something else that can help?


Thank you

Last edited by dannyvdberg; 10-02-2013 at 03:38 PM.. Reason: Code tags
# 2  
Old 10-02-2013
If tar_gzholds more than one file name, the expression fails, as it has "too many arguments". Make sure to work on one file at a time, e.g. by using a for loop or similar.
This User Gave Thanks to RudiC For This Post:
# 3  
Old 10-02-2013
Thank you for you message. I will make a for loop. But is necessary that all the 5 tar_gz are in the backup for the restore and if not that the restore script exits. Is this possible in a for loop you think?
# 4  
Old 10-02-2013
Check the number of files before, e.g. make tar_gz an array and use count of elements (bash: ${#tar_gz[@]} )
# 5  
Old 10-02-2013
Do you have a example maybe for me? I'm doing anything but nothing works..
# 6  
Old 10-02-2013
Not knowing what shell you use, here's a bash proposal:
Code:
tar_gz=( $(find @etc@apache2...) )
[ ${#tar_gz[@]} -ne 5 ] && { echo "file set incomplete"; exit 1; }
for FN in ${tar_gz[@]}; do ... ; done

This User Gave Thanks to RudiC For This Post:
# 7  
Old 10-02-2013
Thank you for helping.

This is my code now

Code:
tar_gz=( $(find @etc@apache2@mods-available.tar.gz @etc@apache2@mods-enabled.tar.gz @etc@apache2@ports.conf.tar.gz @etc@apache2@sites-available.tar.gz \
@etc@apache2@sites-enabled.tar.gz) )

cd ${CHOICE}

echo "Founded Apache2 tar.gz files"
echo "--------------------------------------"
echo "$tar_gz"

if [ ${#tar_gz[@]} -eq 5 ]
then
        echo "found"
else
        echo "not found"
-- INSERT --

But for my i won't work

My bash is /bin/bash/
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Unrecognized option: sparc-sun-Solaris2.10/bin/as: unrecognized option `-m32'

Hi, I installed some packages required by an app built with python. But when I try python setup.py install, I get the following error: /opt/csw/lib/gcc/sparc-sun-solaris2.10/5.2.0/../../../../sparc-sun-solaris2.10/bin/as: unrecognized option `-m32' Could anyone tell me what's wrong... (4 Replies)
Discussion started by: Kimkun
4 Replies

2. Shell Programming and Scripting

Convert Update statement into Insert statement in UNIX using awk, sed....

Hi folks, I have a scenario to convert the update statements into insert statements using shell script (awk, sed...) or in database using regex. I have a bunch of update statements with all columns in a file which I need to convert into insert statements. UPDATE TABLE_A SET COL1=1 WHERE... (0 Replies)
Discussion started by: dev123
0 Replies

3. UNIX for Dummies Questions & Answers

What is the meaning of "-s" option in "if" statement?

Hi Guys, I'm sorry but I can't find answer for this, what is the meaning of -s option in "if" statement on unix scipting. Please see sample below: opath=/home/output for i in N1 N2 N3 N4 do echo $i if then grep $i $opath/N5_CRAI > $opath/N5_$i.crai chmod 777 $opath/N5_$i.crai ... (7 Replies)
Discussion started by: rymnd_12345
7 Replies

4. Shell Programming and Scripting

recently introduced to the newer option for find...does an older option exist?

To find all the files in your home directory that have been edited in some way since the last tar file, use this command: find . -newer backup.tar.gz Is anyone familiar with an older solution? looking to identify files older then 15mins across several directories. thanks, manny (2 Replies)
Discussion started by: mr_manny
2 Replies

5. Shell Programming and Scripting

How is use sselect statement o/p in insert statement.

Hi All, I am using Unix ksh script. I need to insert values to a table using the o/p from a slelect statement. Can anybody Help! My script looks like tihs. ---`sqlplus -s username/password@SID << EOF set heading off set feedback off set pages 0 insert into ${TB_NAME}_D... (2 Replies)
Discussion started by: nkosaraju
2 Replies

6. Shell Programming and Scripting

If statement - How to write a null statement

In my ksh script, if the conditions of a if statement are true, then do nothing; otherwise, execute some commands. How do I write the "do nothing" statement in the following example? Example: if (( "$x"="1" && "$y"="a" && "$z"="happy" )) then do nothing else command command fi... (3 Replies)
Discussion started by: april
3 Replies

7. Programming

g++ and the -R option

hi everybody, can somebody tell me what -R option on g++ on solaris means : g++ -DAIX -fpic -static -o printps printps.o -L/epost2/blitz/xercesc1_1 /lib -L/oracle/OraHome/lib32/ L/epost2/blitz/lib -lxerces-c1_1 -lhmltods -lhmlt ops -lgeneric -lnotify -lutil -lclntsh `cat... (0 Replies)
Discussion started by: eternalflame
0 Replies

8. Shell Programming and Scripting

option followed by : taking next option if argument missing with getopts

Hi all, I am parsing command line options using getopts. The problem is that mandatory argument options following ":" is taking next option as argument if it is not followed by any argument. Below is the script: while getopts :hd:t:s:l:p:f: opt do case "$opt" in -h|-\?)... (2 Replies)
Discussion started by: gurukottur
2 Replies

9. Programming

cc option

my yacc output file y.tab.c is not compiling using cc y.tab.c -ly command .possibily option flag -ly is not correct.i m using red hat linux 9.please give solutions. (4 Replies)
Discussion started by: kuldeep_bora
4 Replies

10. Shell Programming and Scripting

option in if statement

does anyone know what the -a in an if statement is referring to ex... if (6 Replies)
Discussion started by: cubs0729
6 Replies
Login or Register to Ask a Question