Hi Guys,

First time user & new to scripting. :)

I have my shell script like this:

#!/usr/bin/sh
e_id=`sqlplus -s scott/tiger@DB<<eof
            SET PAGESIZE 0 FEEDBACK OFF VERIFY OFF HEADING OFF ECHO OFF;
            select emp_id from employee;
            quit
            `
echo "Employee ID's $e_id"

group=GROUP1
# Getting the sss_no for each emp_id

for i in $e_id 
 do
   sss_nos=`sqlplus -s scott/tiger@DB <<eof
          SET PAGES 0 LINES 500 HEAD OFF;
          select sss_no from employee_bank where emp_id = $i;
          quit
          `
   echo "List of SSS no's $sss_nos"
   # Run a customize program that calls the sss_nos
   # SSS_move
   SSS_move $sss_nos $group
  sleep 2
done

The Output:
Employee ID's
4567
2231
1121
2233
4554
3243
1231
3311

List of SSS no's
45566
59589
55170
51530
33099
20234
87231
54192

SSS_move:
SSS_move 45566 GROUP1
SSS_move 59589 GROUP1
SSS_move 55170 GROUP1
SSS_move 51530 GROUP1
SSS_move 33099 GROUP1
SSS_move 20234 GROUP1
SSS_move 87231 GROUP1
SSS_move 54192 GROUP1

Now, how will I able to group the output of the loop so that I can assign GROUP1 only to the 1st two output of the loop then assign GROUP2 to the 2nd two output of the loop & so on. :confused:

Desired Output:
SSS_move 45566 GROUP1
SSS_move 59589 GROUP1
SSS_move 55170 GROUP2
SSS_move 51530 GROUP2
SSS_move 33099 GROUP3
SSS_move 20234 GROUP3
SSS_move 87231 GROUP4
SSS_move 54192 GROUP4

Also, how do I count the $sss_nos output so that I have this condition:
If my $sss_nos -gt 7 (w/c in my example above it is true) then assign to multiple GROUP#. If it is -lt 7 then group it only to GROUP1

Pls. help :D

Thanx in advance :)

First get your count of employees with something like this:

e_count=`sqlplus -s scott/tiger@DB<<eof
SET PAGESIZE 0 FEEDBACK OFF VERIFY OFF HEADING OFF ECHO OFF;
select count(emp_id) from employee;
quit
`

Next test your count of employees to see if they are >= to 7. Set your ALT value
accordingly so that you can use it in your loop to determine if custom grouping
is needed. Set TVAL=0 to be able to set trigger for group number change if
needed.
ALT="off";

if [ $e_count -ge 7 ]
then
ALT="on";
fi

Before your loop:

TVAL=0;
GROUP_COUNT=1;

Inside your loop after the comment section insert the following bit:

# Run a customize program that calls the sss_nos
# SSS_move
group=GROUP$GROUP_COUNT
SSS_move $sss_nos $group
if [ "$ALT" = "on" ]
then
if [ $TVAL -eq 1 ]
then
$GROUP_COUNT=`expr $GROUP_COUNT + 1`
$TVAL=0
else
$TVAL=1
fi
fi

That should do it.

Sorry about the first post with the $VAR=... Too much perl and php. Of course your shell variable initializations should be without the preceding $.

First get your count of employees with something like this:

e_count=`sqlplus -s scott/tiger@DB<<eof
SET PAGESIZE 0 FEEDBACK OFF VERIFY OFF HEADING OFF ECHO OFF;
select count(emp_id) from employee;
quit
`

Next test your count of employees to see if they are >= to 7. Set your ALT value
accordingly so that you can use it in your loop to determine if custom grouping
is needed. Set TVAL=0 to be able to set trigger for group number change if
needed.
ALT="off";

if [ $e_count -ge 7 ]
then
ALT="on";
fi

Before your loop:

TVAL=0;
GROUP_COUNT=1;

Inside your loop after the comment section insert the following bit:

# Run a customize program that calls the sss_nos
# SSS_move
group=GROUP$GROUP_COUNT
SSS_move $sss_nos $group
if [ "$ALT" = "on" ]
then
if [ $TVAL -eq 1 ]
then
GROUP_COUNT=`expr $GROUP_COUNT + 1`
TVAL=0
else
TVAL=1
fi
fi

That should do it.

Cool...I'll try this...THANX :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.