Not the correct output, works fine via CLI, not inside the script.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Not the correct output, works fine via CLI, not inside the script.
# 1  
Old 04-11-2012
Not the correct output, works fine via CLI, not inside the script.

Guys,
I need you help please.

The script below is not working correclty for checking via a awk/if statement . Can you tell me what i am doing wrong in the script code "if($1 == "$RETENTION_LEVEL") "

Syntax
Code:
RETENTION_LEVEL=`echo $LINE | cut -f2 -d" "`
echo " ============== $RETENTION_LEVEL =============== "
RETENTION_CHECK=`$ADM_CMD/bpretlevel | egrep -v "Retention|Level|---------" | awk '{ if($1 == "$RETENTION_LEVEL") print $0}' | awk '{print $2,$3}'`


Script Ouput
Code:
+ RETENTION_LEVEL=8
+ echo ' ============== 8 =============== '
+ /usr/openv/netbackup/bin/admincmd/bpretlevel
+ egrep -v 'Retention|Level|---------'
+ awk '{ if($1 == "$RETENTION_LEVEL") print $0}'
+ awk '{print $2,$3}'
+ RETENTION_CHECK=''


What the output should be
Code:
# bpretlevel | egrep -v "Retention|Level|---------" | awk '{ if($1 == "3") print $0}'
    3     1 month        31


Last edited by zaxxon; 04-11-2012 at 10:50 AM.. Reason: changed html tags to code tags
# 2  
Old 04-11-2012
pls provide the same input..
# 3  
Old 04-11-2012
RETENTION_LEVEL=8 or 3

Code:
# bpretlevel | egrep -v "Retention|Level|---------" | awk '{ if($1 == "3") print $0}'
    3     1 month        31


Code:
bpretlevel | egrep -v "Retention|Level|---------" | awk '{ if($1 == "$RETENTION_LEVEL") print $0}'

No ouput when run in the script

Moderator's Comments:
Mod Comment Don't forget to use the code tags^^

Last edited by zaxxon; 04-11-2012 at 11:07 AM.. Reason: code tags
# 4  
Old 04-11-2012
The variable $RETENTION_LEVEL can't be handed into awk as it won't be substituted inside the single quotation marks of awk.
You can try something like
Code:
RETENTION_CHECK=`$ADM_CMD/bpretlevel | awk -v rl="$RETENTION_LEVEL" '!/Retention|Level|---------/ { if($1 == rl) print $2,$3}'

Also no need to have another awk invoked for printing the whole line 1st and then field 2 and 3. You can print it directly and also have awk do the egrep -v thing.

So far my guess.
# 5  
Old 04-11-2012
Worked a treat many thanks.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Expect scripting issue, works interactively when doing commands in cli, does not work in script

Hi; problem may be obvious, simple but I have to say it is somehow not easy to locate the issue. I am doing some word extracting from multiline text. Interacting in CLI seems to work without issues. First step is to add multiline text to a variable. expect1.1> expect1.1> set... (2 Replies)
Discussion started by: aldowski
2 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. Shell Programming and Scripting

sed command not working inside ksh script but works fine outside

Hi, I am a bit confused ,why would a sed command work fine outside of ksh script but not inside. e.g I want to replace all the characters which end with a value and have space at end of it. so my command for it is : sed -i "s/$SEPARATOR /$SEPARATOR/g" file_name This is working fine in... (8 Replies)
Discussion started by: vital_parsley
8 Replies

4. Shell Programming and Scripting

Expect script works on CLI, but not under Nagios

I'm having a problem scripting Expect to work as a Nagios check. The script runs fine from the cli, but not when run as a Nagios check. I turn on the debug output, and it looks like it's not seeing the whole buffer's worth of info, like it's paged interactively somehow. I'm new to Expect, but this... (1 Reply)
Discussion started by: dhargens
1 Replies

5. UNIX for Dummies Questions & Answers

C-program works fine interactively, but not on the SGE server

Greetings, I have a C-program that is made to implement a hidden Markov model on an input file. The program is very memory intensive. I've installed it on my local server where I have an account and it compiles fine. The way they have the server set up is that you can either work... (1 Reply)
Discussion started by: Twinklefingers
1 Replies

6. Shell Programming and Scripting

Sed script not working properly on Solaris (works fine on AIX)?

Hi, I have a problem with a SED script that works fine on AIX but does not work properly on a Solaris system. The ksh script executes the SED and puts the output in HTML in tables. But the layout of the output in HTML is not shown correctly(no tables, no color). Can anyone tell if there is... (7 Replies)
Discussion started by: Faith111
7 Replies

7. Shell Programming and Scripting

Script works fine but not with crontab

Hello All, This is driving me nuts. Wrote a very simple script (it's in csh so sorry about that). Just something very simple though. Here is the catch. Works great from command line sometimes. Other times it runs no errors or anything but I never receive an email. Never runs from crontab... (6 Replies)
Discussion started by: jacktay
6 Replies

8. Shell Programming and Scripting

Script Runs fine but not giving any output

Hi, My script is running with no erros but not giving any output can anyonehelp. #!/bin/ksh . /home/application/bin/application.env OUTFILE=Result.txt PROD_PASSWORD=`${GET_PWD} -f ${PWD_FILE_PATH} -s ${PROD_SERVER} -u ${PROD_USER}` echo "1)To get the book last loaded details " read... (7 Replies)
Discussion started by: jagadish_gaddam
7 Replies

9. Shell Programming and Scripting

Cron job fails, but works fine from command line

I have a very basic script that essentially sends a log file, via FTP, to a backup server. My cron entry to run this every night is: 55 23 * * * /usr/bin/archive_logs The script runs perfectly when executed manually, and actually worked via cron for about three weeks. However, it mysteriously... (3 Replies)
Discussion started by: cdunavent
3 Replies

10. Shell Programming and Scripting

Script works fine until I | more

Hello all, This beats me. I have a script that executes some commands and redirects their output to some text files that I will parse. The commands are along the lines of: dsmadmc -id=admin -pa=admin -outfile=/home/tools/qlog.txt q log f=d If I just run the script it works. If I execute... (2 Replies)
Discussion started by: Skovian
2 Replies
Login or Register to Ask a Question