unable to read a parameter


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting unable to read a parameter
# 8  
Old 05-02-2012
PHP

Shailesh,
My requirement is to read a log file (pe.txt) of 35kB and send an alert if any string "Component Manager stopped" is received. also not to report the same alert again.
So ,I am parsing file from bottom to top to get latest alert.

with the code I posted I get following output which is not correct
[output]
151617
tivoli already generated
151617
tivoli already generated
[\output]

Please Help .
# 9  
Old 05-02-2012
To get the last one,

you can use the below awk

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

it will print the last time
This User Gave Thanks to itkamaraj For This Post:
# 10  
Old 05-02-2012
Question

Hi ,

I get the intended result , however I also get this output -
[output]
./tivoliscript.ksh[22]: ^[^[[A^[[A^[d: not found.
[/output]

Please help.Smilie
# 11  
Old 05-04-2012
MySQL Working Now.

Issue resolved.

I was using
Code:
sed 's/://g' newfile.txt | read temp

at the start of my script which was giving output

Code:
./tivoliscript.ksh[22]: ^[^[[A^[[A^[d:  not found.

I removed the above code since I was actually not generating newfile.txt to have any colon based data...all data it has is place 6 digits.. :-) ..

Thanks Everyone. !!

Last edited by Corona688; 05-04-2012 at 01:43 PM..
# 12  
Old 07-08-2012
Question How to tackle an empty string caught in read command

Hi All,

In code below,if pe.txt does not have a string "Component Manager stopped" then when my awk does not find the intended string in the txt file then 'read' command passes an empty value to "msgtime" parameter , I tried to put an if statement to check for an empty string still error comes shown below code..

Please suggest how should I tackle it here ..

Code:
cat newfile.txt | read temp

awk '/Component Manager stopped/ {gsub(":","",$2);last=$2}END{print last}' pe.txt | while read msgtime
                                                                                        do
                                                                                                if [$msgtime -ne null]; then
                                                                                                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
                                                                                                else
                                                                                                        echo "timestamp is null" > /dev/null 2>&1
                                                                                                fi
                                                                                        done

running the above gives me error -
[error]
[aeadmin@FNPRODXT1:/AELogs]$ ksh tivoliscript.ksh
tivoliscript.ksh[11]: test: 0403-021 A ] character is missing.
[/error]

Eagerly awaiting your valuable replies.
# 13  
Old 07-08-2012
Code:
cat newfile.txt | read temp

awk '/Component Manager stopped/ {gsub(":","",$2);last=$2}END{print last}' pe.txt | while read msgtime
                                                                                        do
                                                                                                if [ ! -z "$msgtime" ]; then
                                                                                                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
                                                                                                else
                                                                                                        echo "timestamp is null" > /dev/null 2>&1
                                                                                                fi
                                                                                        done

# 14  
Old 07-08-2012
$temp won't be set for comparison. you'd need to set it without using a pipe.

Code:
temp=$(cat newfile.txt)
or
read temp < newfile.txt

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