unable to read a parameter


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting unable to read a parameter
# 1  
Old 05-01-2012
Bug unable to read a parameter

All,

on command prompt when i am testing I am able to get the value of 'msgtime' parameter but in the script I get a space value for it . Please help ..

following is the code snippet -

Code:
grep "Component Manager stopped" msgtime.txt | while read line
                                                 do
                                                     awk '{ print $2}' | sed 's/://g' | read msgtime
                             echo $msgtime  # does not display msgtime instead gives space
                                                done

msgtime.txt looks like this -

Code:
pe.txt.2012-03-28:2012/03/28 11:51:02 [RMI TCP Connection(147)-10.87.130.42] INFO  filenet.vw.ComponentIntegrator  Component Manager stopped.

Please help.

Last edited by Scrutinizer; 05-01-2012 at 02:12 PM.. Reason: code tags
# 2  
Old 05-01-2012
you could use following:
Code:
grep "Component Manager stopped" msgtime.txt | while read line
do
msgtime=`echo $line | awk 'gsub(/:/, "",$2 );{print $2};'`
done


Last edited by 47shailesh; 05-01-2012 at 02:34 PM.. Reason: removed extra space around =
# 3  
Old 05-01-2012
what is the expected output ?

you are not passing any input to awk command

---------- Post updated at 10:06 PM ---------- Previous update was at 10:04 PM ----------

Code:
 awk '/Component Manager stopped/ {gsub(":","",$2);print $2}' msgtime.txt

# 4  
Old 05-01-2012
PHP

Hi ,

47shailesh : I get the following error

Code:
./tivoliscript.ksh[19]: msgtime:  not found.

Please suggest.


Moderator's Comments:
Mod Comment Please click this link: How to use [code][/code] tags

Last edited by Scrutinizer; 05-01-2012 at 02:13 PM.. Reason: code tags
# 5  
Old 05-01-2012
1st error was that ... | read msgtime invokes read in a subshell and therefore the value of msgtime is not accessible outside of that. (edit: well, not that it'd work without an input to awk)

This error is that you cannot put spaces around the = when doing an assignment. msgtime=`echo ...

itkamaraj's solution is a great one, or do you need to capture it and do more processing with $msgtime?

Code:
awk '/Component Manager stopped/ {gsub(":","",$2);print $2}' msgtime.txt | while read msgtime
do
    echo $msgtime
    ...
done

This User Gave Thanks to neutronscott For This Post:
# 6  
Old 05-01-2012
PHP

Guys ,

You are all awesome .. hats off..

I used this
Code:
awk '/Component Manager stopped/ {gsub(":","",$2);print $2}' msgtime.txt | while read msgtime do    # I was using msgtime elsewhere in script but I included it here and its working.. :-) done


Thanks a tonnes.................. :-)

---------- Post updated at 01:24 PM ---------- Previous update was at 12:20 PM ----------

Guys , stuck a bit ..

my log file pe.txt is a huge log file , inorder to get the latest alert I read from tthe bottom

How can I give use awk here to read from the bottom of file and execute -

Code:
tail -r pe.txt | awk '/Component Manager stopped/ {gsub(":","",$2);print $2}' | while read msgtime
                                        do
                                            test $temp -eq $msgtime  
                                            if [ $? -eq 0 ]; then
                                                echo $msgtime
                                                echo "tivoli already generated"
                                            else
                                                   echo "$msgtime" > newfile.txt
                                                touch ComponentManagerDown_on_`hostname`.txt
                                            fi
                                        done

The above is not working. :-(

Last edited by Franklin52; 05-01-2012 at 03:26 PM.. Reason: code tags
# 7  
Old 05-01-2012
what error you are getting ?
This User Gave Thanks to 47shailesh For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Forum Support Area for Unregistered Users & Account Problems

Unable to read threads when logged in

I'm getting the following error (or something similar) whenever I try to view a thread when I'm logged in. That is, I login, hit "New Posts", get a list of theads, click on one (in this example is was the "Not allowed to post URLs" thread), then get the following HTML error page instead of the... (1 Reply)
Discussion started by: cnamejj
1 Replies

2. Post Here to Contact Site Administrators and Moderators

Unable to pass shell script parameter value to awk command in side the same script

Variable I have in my shell script diff=$1$2.diff id=$2 new=new_$diff echo "My id is $1" echo "I want to sync for user account $id" ##awk command I am using is as below cat $diff | awk -F'~' ''$2 == "$id"' {print $0}' > $new I could see value of $id is not passing to the awk... (0 Replies)
Discussion started by: Ashunayak
0 Replies

3. Shell Programming and Scripting

Read parameter file for a shell script

Hi All, I need urgent Help from all of you here. Below is my code- ================================================== #!/usr/bin/sh cd $1 cat $2 | tr -ds "$" "" > parameter_file.param export `parameter_file.param` chmod 777 parameter_file.param echo $1 echo $2 cd $prmDirInput... (5 Replies)
Discussion started by: Amit786
5 Replies

4. Shell Programming and Scripting

How to read a directory as parameter in shell script?

Hi All, I have written a shell script to compile an oracle R12 form and also a procedure is called from it. The procedure registers the form, function and creates a menu entry. I took directory as a parameter. Code is as below: #!/bin/ksh echo... (3 Replies)
Discussion started by: veena484
3 Replies

5. Shell Programming and Scripting

Unable to read Environment Variable

Hi I have created the following shell script file with the following content. #!/bin/csh set VAR1="abcxyz" << EOF EOF echo "---------------------" echo "VAR1 = $VAR1" echo "---------------------" i am not able to echo the previously set VAR1. Can any one suggested what could be wrong?... (5 Replies)
Discussion started by: srinu_b
5 Replies

6. Shell Programming and Scripting

Getting foreach to read a parameter with blank space

my program is designed to take the first parameters as extension, then the rest of the parameters as files to be searched for and, if found, modified by the extension. If not found, it prints an error. Everything is great until: ./chExt.sh 'com' 'king cobra.dat' where $file splits up the two... (2 Replies)
Discussion started by: username652719
2 Replies

7. Shell Programming and Scripting

Read parameter file in a shell script to unload a DB2 Table???

Hi , I Have following requirement: DB2 Sql query to pass from a parameter file for example, I would create a parameter file with (SELECT column 1, column 2 FROM Table name) then job would read it and create a file with the contents named table.txt How to write/modify below ksh script to... (10 Replies)
Discussion started by: developer.dwh9
10 Replies

8. Programming

unable to send a char parameter from main to a function

why does this not work? #include <stdio.h> #include <stdlib.h> char getFileMode(char charChanger) { char filetype; /*var to hold the value to be returned*/ filetype = charSetter; /*set filetype to "l" if it is a symlink*/ return filetype; } int main(void){ char... (8 Replies)
Discussion started by: bluetxxth
8 Replies

9. Shell Programming and Scripting

awk/sed script to read values from parameter files

Hi, I am writing a shell program that executes a lot of Oracle SQL Files on different databases based on the enviroment setting value. I am trying to design a parameter file where i can store the environment values for all the databases in the below format Environment File File Name... (6 Replies)
Discussion started by: rajan_san
6 Replies

10. Shell Programming and Scripting

Read from file as script parameter

I have a file with userIDs, one per line no spaces. I have a script that accepts userIDs as a parameter and outputs information about them. What I have had to do in the past was to modify each line of the file with userIDs to call the script with the userID and pipe the output to a data file. ... (2 Replies)
Discussion started by: vmaxx
2 Replies
Login or Register to Ask a Question