I need to do the following:
1. Run in loop on this file
2. find the lines which end with ":Y"
3. cut the path from the line
4. Change directory to the path and run a script
I wrote the following function:
Code:
run_install_sr()
{
cat ${CONF_FILE} | grep INSTALL_SR_ | grep :Y | while read line
do
INSTALL_SR_DIR=`echo $line | cut -d= -f2 | cut -d: -f1`
rcp ${RESPONSE_FILE_SR} ${DB_HOST_NAME}:/tmp >> $installLog
rsh ${DB_HOST_NAME} "su - root -c \"cd ${INSTALL_SR_DIR} && ./Install_SR.ksh -f /tmp/${RESPONSE_FILE_SR##*/} -l database\"" | tee -a $installLog
rcp ${RESPONSE_FILE_SR} ${ADMIN_HOST_NAME}:/tmp >> $installLog
rsh ${ADMIN_HOST_NAME} "su - root -c \"cd ${INSTALL_SR_DIR} && ./Install_SR.ksh -f /tmp/${RESPONSE_FILE_SR##*/} -l administration\"" | tee -a $installLog
if [[ ${RTESUB_LAYER} = 'YES' ]] && [[ ${ADMIN_LAYER} = 'YES' ]] ; then
rcp ${RESPONSE_FILE_SR} ${RTESUB_HOST_NAME}:/tmp >> $installLog
rsh ${RTESUB_HOST_NAME} "su - root -c \"cd ${INSTALL_SR_DIR} && ./Install_SR.ksh -f /tmp/${RESPONSE_FILE_SR##*/} -l subscriber\"" | tee -a $installLog
fi
done
}
The expected results : the loop suppose to run 4 times
The current results: the loop ran only once and issue the first line the loop found.
Does someone see something wrong?
I found the problem but I didn't find a solution.
The loop is OK. The problem is that the function exit from the operation after "rsh" command and does not continue to the next iteration.
I wrote the following testing program:
Code:
#! /bin/ksh
CONF_FILE=nir.conf
export $(< $CONF_FILE)
run_install_sr()
{
cat ${CONF_FILE} | grep INSTALL_SR_ | grep :Y | while read line
do
INSTALL_SR_DIR=`echo $line | cut -d= -f2 | cut -d: -f1`
echo Install SR directory is $INSTALL_SR_DIR
rsh ${DB_HOST_NAME} hostname
done
}
tornado:> ./nir.ksh
Install SR directory is /home/Upgrade_4.7.1/Utilities/Install_SR
tornado
If I remark the rsh command in the script ,I get the following output:
Code:
tornado:> ./nir.ksh
Install SR directory is /home/Upgrade_4.7.1/Utilities/Install_SR
Install SR directory is /home/Upgrade_4.7.2/Utilities/Install_SR
Install SR directory is /home/Upgrade_4.8/Utilities/Install_SR
Install SR directory is /home/Upgrade_4.8.1/Utilities/Install_SR
As you can see,the loop works fine and the problem is with the rsh command - the function is getting out from the loop after the first iteration instead of continuing to the next iteration.
The 'magic' is....
To have TWO FieldSeparators - ':' and '=' : -F'[:=]'
Checking the FIRST field starting with 'INSTALL_SR_'
And LAST field having a 'Y': $NF = "Y"
If the above two conditions are true, output the SECOND field: {print $2}
The output of the 'nawk' gets piped to a while/read .....
And the rest is your loop.
OS : RHEL 6.1
Shell : Bash
I had a similair post on this a few weeks back. But I didn't explain my requirements clearly then. Hence starting a new thread now.
I have lots of files in /tmp/stage directory as show below.
I want to loop through each files to run a command on each file.
I... (8 Replies)
I have the below code which runs on multiple databases , but this runs one-after-one. I will need this to run in parallel so that i could save a lot of time. Please help!!! Thanks in advance
for Db in `cat /var/opt/oracle/oratab |egrep -v "ASM" |grep -v \# |cut -d\: -f1`
do
{
export... (5 Replies)
The command is:
sic -h irc.freenode.net 2>&1 | tee -a irc.log
Where sic is an IRC client, and I'm piping the output to tee in order to log my IRC sessions.
I'm trying to handle reconnects by running it in a while loop in the shell process and cat the initial commands into sic's stdin.
I... (1 Reply)
Hi, I was hoping for help with a for loop to run a program (vina) repeatedly using all the files in a folder as input. Currently my code looks like this:
#!/bin/bash
FILES=/home/afalk/Desktop/battest/*.pdbqt
for f in $FILES do
vina --config /home/afalk/Desktop/A.txt --ligand "$f".pdbqt
done... (5 Replies)
Hi all,
I'm trying to remsh to another server and then execute a for loop command there but I'm getting unexpected errors and would appreciate any suggestions.
Ideally what I want to do is this:
for host in `cat host_file`
do
remsh $host -n "
cd /home/
for DATABASE in `ls -d... (5 Replies)
Sorry for such a dreadful title, but I'm not sure how to be more descriptive. I'm hoping some of the more gurutastic out there can take a look at a solution I came up with to a problem, and advice if there are better ways to have gone about it.
To make a long story short around 20K pieces of... (2 Replies)
The script checks for free space stats on Oracle. If there are any tablespaces with more than 85% usage it prints the details of the tablespace. If all the tablespaces have more than 15% free space, then "All tablespaces have more than 15 pct free space" must be printed on the screen.
When I run... (2 Replies)