Execute command with loop


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Execute command with loop
# 1  
Old 07-07-2013
Execute command with loop

[/CODE]I have a below command

Code:
ALTER TABLE `abc`  ADD PARTITION ( PARTITION 20130613 VALUES less than (DAY('13')));

Below is requirement

It runs in Loop

as DAY start with 13 and end with 100 along with this of counter "20130613" also increases per command

as the next command should be

Code:
ALTER TABLE `abc`  ADD PARTITION ( PARTITION 20130614 VALUES less than (DAY('14')));

# 2  
Old 07-07-2013
Try:
Code:
perl -e 'use Date::Calc qw(:all);
for ($i=13;$i<=100;$i++) {
  ($y,$m,$d)=Add_Delta_Days(2013,05,31,$i);
  printf "ALTER TABLE `abc`  ADD PARTITION ( PARTITION %d%02d%02d VALUES less than (DAY(\047$i\047)));\n",$y,$m,$d
}'

This User Gave Thanks to bartus11 For This Post:
# 3  
Old 07-07-2013
Thanks,

But I want this to be done by using Shell scripting
# 4  
Old 07-07-2013
What have you tried and where are you stucK?
# 5  
Old 07-07-2013
Quote:
Originally Posted by Scrutinizer
What have you tried and where are you stucK?
Please find the code I have wrote but Problem is unable to rotate c variable second thing If i want to use 1000 value for a That means I have write 1000 numbers in for loop
as Now Used just 10 in for loop want to change about 1000

Code:
#!/bin/sh
#
#Script to test for loop
#
#
if [ $# -eq 0 ]
then
echo "Error - Number missing form command line argument"
echo "Syntax : $0 number"
echo " Use to print multiplication table for given number"
exit 1
fi
a=$1
c=20130613
for i in 1 2 3 4 5 6 7 8 9 10

do
echo "ALTER TABLE seats  ADD PARTITION ( PARTITION $c VALUES less than (DAY( `expr $a \+ $i`)));"
c = expr $c + 1;
done

# 6  
Old 07-07-2013
Try:
Code:
c=$(expr $c + 1)

or better:
Code:
c=$((c+1))

--
As to the other part, what OS and shell are you using?
# 7  
Old 07-07-2013
Quote:
Originally Posted by Scrutinizer
Try:
Code:
c=$(expr $c + 1)

or better:
Code:
c=$((c+1))

--
As to the other part, what OS and shell are you using?
Thanks

As for the Other Part

My Unix Info is below

Code:
$uname -a
Linux ndbd1 2.6.18-238.el5 #1 SMP Thu Jan 13 15:51:15 EST 2011 x86_64 x86_64 x86_64 GNU/Linux

As I want to use for in 1 2 3 4 < 1000 Or any input number, for "FOR" Loop

Or For this I have to Migrate the code to while loop
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Exit while loop on execute script

Hi, I have first script which on IR remote command event execute the second script. If the second script is executed, it display echo "timeout expired" after 10s. This works as expected. But I also want to reset timer (increase time) in case if the second script is executed again within 10s. ... (8 Replies)
Discussion started by: armatron
8 Replies

2. Shell Programming and Scripting

How to execute a command inside a while loop?

How do we execute a command inside a while loop? (7 Replies)
Discussion started by: Little
7 Replies

3. Shell Programming and Scripting

How to execute a no of SELECT COUNT(*) statements using a loop

HI Unix Gurus, I have a number of SELECT count(*) statements in an input file and I want to execute it using a shell script but one by one using loop in script.... How can I do this..... (7 Replies)
Discussion started by: ustechie
7 Replies

4. UNIX for Dummies Questions & Answers

unable to execute while loop

Hi everyone. I wanted to print numbers from 1 to 5 in reverse order. For this I used the following code: #!/bin/bash x=5 while do echo $x x=`expr $x - 1` echo "" done echo "" Well but on compiling the above code, it gives the following error. ... (3 Replies)
Discussion started by: grc
3 Replies

5. UNIX for Dummies Questions & Answers

For Loop to execute a command on a series of files

Hello, I have a set of input data that I split into batches using the following command: split -l 4000000 MyInput.in Split_a Once I get the split files, I run a certain command on the split files that spews an output. So far I have been doing it without a for loop. How can I translate the... (2 Replies)
Discussion started by: Gussifinknottle
2 Replies

6. UNIX for Advanced & Expert Users

Execute while loop

Hi, I have a background process running for which I want to know the status continuously. I want to execute a WHILE loop in the command prompt so that it keeps on displaying in the screen.But, I am getting the following errors :- hyper20:~ 3> while while? while? hyper20:~ 4> while {1}... (7 Replies)
Discussion started by: shubhranshu
7 Replies

7. Shell Programming and Scripting

Execute Loop in Telnet

hi Everyone , have a nice day #!/bin/sh ( sleep 1 echo "LOGIN:username:password;" sleep 1 while IFS= read -r line do #echo $line GET:VOUCHERDETAIL:VoucherSerialNumber,$line; >> /home/status_log done < /home/status.txt sleep 1 echo "LOGOUT;") | telnet 127.0.0.1 7021 , it... (2 Replies)
Discussion started by: Dastard
2 Replies

8. UNIX for Dummies Questions & Answers

how to execute a while loop for 20 minutes?

I want to execute a while loop (or any other loop) for 20 minutes. I have extracted the minutes and seconds from the current system date by using the command y = `date +%M%S` How to proceed ?? (6 Replies)
Discussion started by: subhotech
6 Replies

9. Shell Programming and Scripting

loop does not execute in bash script?

I have a very basic bash shell script, which has many "while... done; for .... done" loop clauses, like the following ~~ #!/bin/bash while blablalba; do .... done < /tmp/file for line in `cat blablabla`; do grep $line /tmp/raw ; done > /tmp/1; while blablalba2; do .... done <... (2 Replies)
Discussion started by: fedora
2 Replies

10. Shell Programming and Scripting

Execute commands parallel in a for loop ?

Hi, please can someone point me in the right direction with a shell scripting problem. I want to execute a command in a for loop and the command should be started not one-by-one meaning the for loop is waiting for the exit code , it should be started in parallel. I have a plain text file... (3 Replies)
Discussion started by: networkfre@k
3 Replies
Login or Register to Ask a Question