02-06-2006
scripting headache... loops & variables
Surely there's an easier way to do this, lets see if anyone knows! I am new to scripting so go easy on me!
I have the following script and at the moment it doesn't work and I believe the problem is that I am using a while loop within a while loop. When I run the script using sh -x I can see that it is grepping each $DAACFILE but gets no result, so I think $IP has no value set when running this part of the script, which results in the file, gettrack, containg no data... so the result is that MSISDN.out is empty. Any help much appreciated.
LOGDIR=/usr/local/tibco/adapters/DAAC/bin/archive/
TEMPDIR=/usr/local/tibco/adapters/DAAC/bin/archive/temp/
rm $TEMPDIR/getMSISDN.sh
rm $TEMPDIR/MSISDN.out
touch $TEMPDIR/getMSISDN.sh
chmod +x $TEMPDIR/getMSISDN.sh
echo "Enter the month (e.g Jan) you wish to extract MSISDN's for : "
read MONTH
echo "Enter the number of the day (1-31) you wish to extract MSISDN's for : "
read DAY
DAYLOG=$TEMPDIR"$MONTH$DAY"
#CREATES MSISDN.OUT BY COPYING RELEVANT DAYS LOG FILES TO TEMP LOG DIRECTORY, EXTRACTS IP FROM extract??.EST.txt AND GREPS DAAC LOGS FOR MSISDN BASED ON IP ADDRESS AND TRACKINGID.
echo "DMS transactions by MSISDN" > $TEMPDIR/MSISDN.out
ls $DAYLOG > $TEMPDIR/list_files
# exec < $TEMPDIR/list_files
# while read DAACFILE
cat $TEMPDIR/list_files | while read DAACFILE
do
{
#awk '{print $7}' $TEMPDIR/extract$DAY.EST.txt|while read IP
awk '{print $7}' $TEMPDIR/extract22.EST.txt|while read IP
do
# grep $IP $DAYLOG$DAACFILE | grep tracking > $TEMPDIR/gettrack;
grep $IP $DAYLOG$DAACFILE | grep tracking >> $TEMPDIR/gettrack;
awk '{print$15}' $TEMPDIR/gettrack| sed 's/tracking=/grep "/' | sed "s/zzw\#/\" $DAACFILE \| grep \"MSISDN :\"/" >> $TEMPDIR/getMSISDN.sh;
$TEMPDIR/getMSISDN.sh | awk '{print $1, $2, $3, $4, $5, $6, $12, $13}' >> $TEMPDIR/MSISDN.out
done
}
# rmdir $DAYLOG
done
10 More Discussions You Might Find Interesting
1. IP Networking
Hi all,
I upgraded my SUSE 6.1 to SUSE 7.1 and at once the following things won't work anymore:
1) My DHCP client is not able anymore to retrieve my IP address from the @home server. It times out all the time. If I use a fixed IP I can get on the net, so there is no physical problem.
2) I... (3 Replies)
Discussion started by: Micky
3 Replies
2. UNIX for Dummies Questions & Answers
I have a while read loop that reads values inside of a file and then performs an expr operation on each.
Everything works fine, the way it's supposed to but, once the loop is finished, I can not access the variable that I used inside of the loop (but that variable was created outside of the... (7 Replies)
Discussion started by: yongho
7 Replies
3. Shell Programming and Scripting
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
4. Shell Programming and Scripting
You can use one while inside another?
I made the following script (without really knowing if I can use two while) to get 3 numbers different from each other at random:
num1=$(( $RANDOM % 10 ))
num2=$num1
while
do
num2=$(( $RANDOM % 10 ))
done
num3=$num1
while
do
while
do... (1 Reply)
Discussion started by: ale.dle
1 Replies
5. Shell Programming and Scripting
Hi,
#!/bin/ksh
$v=""
for ((i = 1 ; i <= 5 ; i++ ))
do
v="THerrFile_$i.err";
grep -i "$i:Error" $v >>oraerror_output.txt
done
My requirement is to dynamically create variable like
THerrFile_1.err,THerrFile_2.err etc.
where my grep needs... (5 Replies)
Discussion started by: sudhir_83k
5 Replies
6. Shell Programming and Scripting
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
7. Shell Programming and Scripting
Hi,
This is probably going to be very simple but i came across something i can't quite explain. Here is the situation: i have a list of files, which i'd like to process one by one (get the size, make some tests, whatever) and generate some statistics using different variables.
Something... (5 Replies)
Discussion started by: m69w
5 Replies
8. Shell Programming and Scripting
I am trying to use two nested for loops to process some files and then create a new file using both variables in the output file name. I have several files in this naming style:
S1_L3_all_R1.fastq
S1_L3_all_R2.fastq
S1_L4_all_R1.fastq
S1_L4_all_R2.fastq
.
.
S1_L8_all_R1.fastq... (3 Replies)
Discussion started by: aminards
3 Replies
9. Shell Programming and Scripting
I have a script to start/stop/restart the tomcat application. When we run the script first time i.e stop/start it set all env variables(DISTRIB_ID,NAME,TOMCAT_CFG,....etc),but when we restart the tomcat it is running in the same shell.....I need to set the variables when i restart the tomcat(in the... (1 Reply)
Discussion started by: praveen265
1 Replies
10. UNIX for Dummies Questions & Answers
I am using this code:
for e in {1..14}
do
awk '{gsub(/^.*GGGGGG|TTTTT.*$/,"",$0)} 1' $e.1 > ${e}.2
done
However, in the second loop instead of GGGGGG|TTTTT, I should use AAAAAA|CCCCCC.
For third loop CCAAAA|CCCCAA, so on and so forth. Is there any way to accomplish this without writing... (20 Replies)
Discussion started by: Xterra
20 Replies
LEARN ABOUT DEBIAN
rredtool
RREDTOOL(1) REPREPRO RREDTOOL(1)
NAME
rredtool - merge or apply a very restricted subset of ed patches
SYNOPSIS
rredtool --help
rredtool [ options ] --merge patches...
rredtool [ options ] --patch file-to-patch patches...
rredtool directory newfile oldfile mode
DESCRIPTION
rredtool is a tool to handle a subset of ed patches in a safe way. It is especially targeted at ed patches as used in Packages.diff and
Sources.diff. Is also has a mode supposed to be called from reprepro as Index Hook to generate and update a Packages.diff/Index file.
MODI
One of the following has to be given, so that rredtool know that to do.
--version
Print the version of this tool (or rather the version of reprepro which it is coming with).
--help Print a short overview of the modi.
--patch
The first argument of rredtool is the file to patch, the other arguments are ed patches to apply on this one.
--merge
The arguments are treated as ed patches, which are merged into a single one.
--reprepro-hook (or no other mode flag)
Act as reprepro index hook to manage a Packages.diff/index file. That means it expects to get exactly 4 arguments and writes the
names of files to place into filedescriptor 3.
If neither --patch nor --merge is given, this mode is used, so you can just put
DebIndices: Packages Release . .gz /usr/bin/rredtool
into reprepro's conf/distributions file to have a Packages.diff directory generated. (Note that you have to generate an uncom-
pressed file (the single dot). You will need to have patch, gzip and gunzip available in your path.)
OPTIONS
--debug
Print intermediate results or other details that might be interesting when trying to track down bugs in rredtool but not intresting
otherwise.
--max-patch-count=count
When generating a Packages.diff/Index file, put at most count patches in it (not counting possible apt workaround patches).
-o|--output
Not yet implemented.
ENVIRONMENT
TMPDIR, TEMPDIR
temporary files are created in $TEMPDIR if set, otherwise in $TMPDIR if set, otherwise in /tmp/.
REPORTING BUGS
Report bugs or wishlist requests the Debian BTS (e.g. by using reportbug reperepro) or directly to <brlink@debian.org>.
COPYRIGHT
Copyright (C) 2009 Bernhard R. Link
This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICU-
LAR PURPOSE.
reprepro 2009-11-12 RREDTOOL(1)