help with multiple loops in shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting help with multiple loops in shell script
# 1  
Old 03-22-2012
help with multiple loops in shell script

Hi Guys-

I'm trying to write a script which takes date as input (mm.yy.dd) and search in the current file. If pattern doesn't exist it will then look in a backup directory and so on.

being a newb i'm unable to loop over to the backup directory. hoping for some ideas, i've highlighted the area where i'm stuck . any advice is appreciated.
I have about mutiple backup directories in the root_dir and the script should keep searching until it runs out of directories.

the naming convention of backup directories is backup-yyyy.mm.dd


Code:
#!bin/bash

datetime=$1
root_dir=/home/xyz
bkup_dir=`ls -tr | grep -i "backup-" | tail -1
pattern=`grep "$datetime" $root_dir/logfile

if [ $pattern = "" ]
then "go into bkup folder and search for pattern "
else
   echo -e $pattern
fi

# 2  
Old 03-22-2012
"go into bkup folder and search for pattern "

to

Code:
 
find $bkup_dir -type f | xargs grep -l "$datetime"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Ssh to multiple hosts and then run multiple for loops under remote session

Hello, I am trying to login to multiple servers and i have to run multiple loops to gather some details..Could you please help me out. I am specifically facing issues while running for loops. I have to run multiple for loops in else condition. but the below code is giving errors in for... (2 Replies)
Discussion started by: mohit_vardhani
2 Replies

2. Shell Programming and Scripting

Help with multiple for loops

All, I have set up ssh trust between 3 machines. The aim is to connect from machine-A to B and C and clear the txt files in tmp on all 3 machines. And, I have 3 environments and each environment has 2 hosts. So I should be able to run this script on any environment. Here is the logic: I want... (5 Replies)
Discussion started by: pnara2
5 Replies

3. Shell Programming and Scripting

Shell Script for viewing multiple logs from multiple server

I am new to Shell scripting and below is my requirement. I need to search some specific word e.g. "exception" or "transaction" from log file. We have multiple env e.g. Level1 , Level2 etc and each env have Multiple boxes e.g. For Level 1 env we have "test11.test.com" , "test12.test.com". Each... (1 Reply)
Discussion started by: peeyush
1 Replies

4. UNIX for Dummies Questions & Answers

While Loops Multiple File

Guru, I try to make a loop of 2 files, Input File1.txt: 1 2 File2.txt: A B C A, B and C is a file name, inside A X Y Z Expected Output A.1 X (2 Replies)
Discussion started by: guns
2 Replies

5. Shell Programming and Scripting

multiple while loops in expect script

Hi, I am trying to incorporate multiple while loops into an expect script written in ksh shell. This is on a Solaris 10 system. Here is the code: #!/bin/ksh EXPECT=/usr/local/bin/expect exp_internal i=1 h=0 while ]; do $EXPECT << DONE set stty_init raw ... (1 Reply)
Discussion started by: cic
1 Replies

6. Homework & Coursework Questions

Shell-script loops beginner

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: "Create a shell script that changes the selected word to another word in all files from selected archive. The... (1 Reply)
Discussion started by: oibanuelos
1 Replies

7. Shell Programming and Scripting

For loops with multiple variables

Hi script gurus. I have need to know how to use for loop with multiple variable. Basically lets take for example /etc/passwd file has following entries The above cat command will basically first greps the real users that have email addresses then converts ':' to '+' then using cut... (4 Replies)
Discussion started by: sparcguy
4 Replies

8. Shell Programming and Scripting

bash scripting: using multiple 'for loops'??

Hey guys, I'm kinda a noob at scripting. I am trying to create a script that uses multiple for loops with the lsiutility to monitor disk health on a system. The script runs, but it will continually echo an infinite number of LogVolumes when there are only 2 per virtual disk on my server. It's... (2 Replies)
Discussion started by: tank126
2 Replies

9. Shell Programming and Scripting

Multiple loops for Load test

Hi All, I am trying to write a bash script that will read a list of numbers from a file, then it needs to use netcat to create a socket connection and pass header/request. I need to limit it to 100 connections. So, after the first set of 100 are fineshed, I need to loop and do it again with... (0 Replies)
Discussion started by: willdev
0 Replies

10. UNIX for Dummies Questions & Answers

Multiple for loops within a Menu?

I have program that I want to be able to use I guess you would call them functions.... to run muliple little programs or loops with one menu script. How would I do this. Here is some code I am using. Sorry about the formatting....it doesn't paste well. echo "*****************************... (3 Replies)
Discussion started by: darthur
3 Replies
Login or Register to Ask a Question