Script Help


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Script Help
# 1  
Old 07-12-2008
Script Help

I have file standardfilecleanup.lst which has contents as below :

db:background_dump_dest:alert.log:test.log:rest:log
db:user_dump_dest:best.log:test.log
db:core_dump_dest:test.log

Below is my script :

#set -xv

i=5

while [ $i -le 3 ]
do
var_value="$"`echo $i`
file_name=`cat standardfilecleanup.lst|awk -F: {'print ${var_value}`
echo ${file_name}
i=`expr $i + 1`
done

When I run my script it is erroring out on below line.

file_name=`cat standardfilecleanup.lst|awk -F: {'print ${var_value}`

My expectation is :

when $var_value is $3 file_name variables value should be alert.log.
when $var_value is $4 file_name variables value should be test.log.
when $var_value is $5 file_name variables value should be rest:log.

Any help is greatly appreciated.
# 2  
Old 07-12-2008
Unfortunately everything about your script seems to have something wrong with it.

Lets start with your loop.
Code:
i=5

while [ $i -le 3 ]
do
    ......
    i=`expr $i + 1`
done

As written you will never enter the while loop since i is always greater than 3. If you want to count down from 5 to 3, then you need to do something like:
Code:
i=5

while [[ $i > 2 ]]
do
    .....
    i=`expr $i - 1`             
done

# 3  
Old 07-12-2008
My bad. While elaborating my problem I made change but did it at wrong place. while loop in script does not have any issue.

#set -xv

i=3

while [ $i -le 5 ]
do
var_value="$"`echo $i`
file_name=`cat standardfilecleanup.lst|awk -F: {'print ${var_value}`
echo ${file_name}
i=`expr $i + 1`
done

Below statement is erroring out :

file_name=`cat standardfilecleanup.lst|awk -F: {'print ${var_value}`
# 4  
Old 07-12-2008
I believe this command is not properly formatted -->
file_name=`cat standardfilecleanup.lst|awk -F: {'print ${var_value}`

Try this :

file_name=`cat standardfilecleanup.lst | awk -F ":" 'print ${var_value}' `
# 5  
Old 07-12-2008
Thanks for the update cystal. Below command is erroring out.

file_name=`cat standardfilecleanup.lst | awk -F ":" 'print ${var_value}' `

awk -F: -> tells that : is feild separator.

I don't know how to code so that {'print ${var_value}' command translates to {'print $3'}.

Thanks,
Prakash
# 6  
Old 07-12-2008
Hi,

Try this :
file_name=`cat standardfilecleanup.lst | awk -F ":" '{print $'$var_value'}'`

Cheers,
Kunal
# 7  
Old 07-12-2008
Thanks Crystal. After making changes command is working fine but not giving expected output. Output of script below.

# ./testfile
File NAme db:background_dump_dest:alert.log:test.log:rest:log

#

Expected output would be:

File NAme alert.log:test.log:rest:log
File NAme test.log:rest:log
File NAme rest:log

Thanks,
Prakash
 
Login or Register to Ask a Question

Previous Thread | Next Thread

5 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to block first bash script until second bash script script launches web server/site?

I'm new to utilities like socat and netcat and I'm not clear if they will do what I need. I have a "compileDeployStartWebServer.sh" script and a "StartBrowser.sh" script that are started by emacs/elisp at the same time in two different processes. I'm using Cygwin bash on Windows 10. My... (3 Replies)
Discussion started by: siegfried
3 Replies

2. Shell Programming and Scripting

Shell script works fine as a standalone script but not as part of a bigger script

Hello all, I am facing a weird issue while executing a code below - #!/bin/bash cd /wload/baot/home/baotasa0/sandboxes_finance/ext_ukba_bde/pset sh UKBA_publish.sh UKBA 28082015 3 if then echo "Param file conversion for all the areas are completed, please check in your home directory"... (2 Replies)
Discussion started by: ektubbe
2 Replies

3. UNIX for Dummies Questions & Answers

Calling a script from master script to get value from called script

I am trying to call a script(callingscript.sh) from a master script(masterscript.sh) to get string type value from calling script to master script. I have used scripts mentioned below. #masterscript.sh ./callingscript.sh echo $fileExist #callingscript.sh echo "The script is called"... (2 Replies)
Discussion started by: Raj Roy
2 Replies

4. Shell Programming and Scripting

Script will keep checking running status of another script and also restart called script at night

I am using blow script :-- #!/bin/bash FIND=$(ps -elf | grep "snmp_trap.sh" | grep -v grep) #check snmp_trap.sh is running or not if then # echo "process found" exit 0; else echo "process not found" exec /home/Ketan_r /snmp_trap.sh 2>&1 & disown -h ... (1 Reply)
Discussion started by: ketanraut
1 Replies

5. Shell Programming and Scripting

create a shell script that calls another script and and an awk script

Hi guys I have a shell script that executes sql statemets and sends the output to a file.the script takes in parameters executes sql and sends the result to an output file. #!/bin/sh echo " $2 $3 $4 $5 $6 $7 isql -w400 -U$2 -S$5 -P$3 << xxx use $4 go print"**Changes to the table... (0 Replies)
Discussion started by: magikminox
0 Replies
Login or Register to Ask a Question