How to get a variables from two different txt files and need to run a command using that values?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to get a variables from two different txt files and need to run a command using that values?
# 1  
Old 05-16-2016
How to get a variables from two different txt files and need to run a command using that values?

Hi

Q1. I have a scenario to run cfsend command,this command will run based on node name,port num,userid and password
I was created one file called test.txt and inserted two values,then called those two values from test.txt file that pointed to node place and ran the script it worked fine

Now i wanna create two or three files for port num,userid and password values to run the cfsend command

here is the script that i have written
Code:
#! /bin/sh
file=/venu/test.txt
while read node;
do
cfsend n:"${node}" port:46464 uid:tibco  pwd:Tibco123 pn:CHCKDIR ud:5563 trtype:c rcmd:"pwd"  
echo "PS is Down On" $node >>test.log
done< $file

Q2. the node names should change every time and will written one conman line "Failed Communicating with partner"
how can monitor only that message and write into a log file that display
".......(expecting the node that written that message) contains Failed Communicating with partner"

can anyone help?
Appreciate you help!

thanks,
venu


Moderator's Comments:
Mod Comment Please use code tags as required by forum rules!

Last edited by RudiC; 05-16-2016 at 02:59 PM.. Reason: Added code tags.
# 2  
Old 05-17-2016
Do they really need to be in 3 different files? How about one?

The command may return a status which allows you to detect whether it failed without grubbing its text output. || is a short-form notation, command1 || command2 means "if command1 fails, run command2".

Also, you don't need to reopen your logfile 10,000 times for 10,000 different nodes, you can redirect the output of the entire loop once to catch it all.

Code:
while read NODE PORT UID PWD
do
        cfsend n:"${NODE}" port:${PORT} uid:${UID}  pwd:${PWD} pn:CHCKDIR ud:5563 trtype:c rcmd:"pwd" || echo "PS is down on $NODE"
done < table > output.log 2>/dev/null

# 3  
Old 05-17-2016
it was my first question
thanks for the reply.yes i can use one file and pass all the values from there


can you answer my second question...........
the cfsend command will return the output everytime is

Code:
LocalTransactionNumber is I517600050
MFT Platform Server: Transfer Mode Set To Recv Result of Command
Failed Communicating with partner
Make sure the host is available
and the remote IP address and port are correct
Error Code -1

it could be changed based on the node name
my requirement is when ever any node send output contains Failed Communicating with partner,then need to write into a file with the node name

i used
Code:
cfsend n:PSCFSNB5 port:46464 uid:tibco  pwd:Tibco123 pn:CHCKDIR ud:5563 trtype:c rcmd:"pwd" | grep -Fxq "Failed Communicating with partner"

but,no luck!
please let me know if you have any idea!

thanks,
venu

Last edited by Don Cragun; 05-20-2016 at 04:58 PM.. Reason: Add CODE and ICODE tags.
# 4  
Old 05-17-2016
Did you try my suggestion?

It may return an error code whenever it fails, which you can detect with ordinary shell logic, command || echo error
# 5  
Old 05-17-2016
yes i tried and got below message

Code:
LocalTransactionNumber is I517600073
MFT Platform Server: Transfer Mode Set To Recv Result of Command
Failed Communicating with partner
Make sure the host is available
and the remote IP address and port are correct
Error Code -1
PS is down on

but my requirement is when ever node written Failed Communicating with partner that means Platform server is down on that node and expecting to keep monitoring for that message,if found write into a log file with the name

i wanna put that message in a log file to monitor,expecting in a single line like
Code:
Plat form server is down on ${nodename}with Failed communicating with partner message

if you have any code
please share with me
its helpful


thanks,
venu

Last edited by Don Cragun; 05-20-2016 at 04:59 PM.. Reason: Add CODE and ICODE tags.
# 6  
Old 05-17-2016
It nearly worked! It printed PS is down on ...making me suspect you printed $NODE when you meant $node, or vice versa.

You also didn't redirect the output of the loop into the log file, and might need to redirect the command to /dev/null.

If you absolutely need to make life that much harder on yourself though, you can process the output instead of using the return value as designed:

Code:
while read NODE PORT UID PWD
do
        cfsend n:"${NODE}" port:${PORT} uid:${UID}  pwd:${PWD} pn:CHCKDIR ud:5563 trtype:c rcmd:"pwd" | grep -iq "failed communicating with partner" && echo "PS is down on $NODE"
done < table > output.log 2>/dev/null

# 7  
Old 05-20-2016
Hi Corona,

I agree with you,but my requirement is to monitor only
"Failed Communicating with partner",then write into log file with the node name that it is generating that message

the command that you suggested me
Code:
cfsend n:"${NODE}" port:${PORT} uid:${UID}  pwd:${PWD} pn:CHCKDIR ud:5563 trtype:c rcmd:"pwd" | grep -iq "failed communicating with partner" && echo "PS is down on $NODE"

is not taking only that line,printing all the lines
Code:
LocalTransactionNumber is I517600073
MFT Platform Server: Transfer Mode Set To Recv Result of Command
Failed Communicating with partner
Make sure the host is available
and the remote IP address and port are correct
Error Code -1

any other command that could print only "Failed Communicating with partner"

thanks,
venu
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read in txt file and run a different command for each line

hi, i'm trying to write a tcsh script that reads in a text file (one column) and the runs a different command for each line of text. i've found lots of example commands for bash, but not for tcsh. can anyone give me a hint? thanks, jill (8 Replies)
Discussion started by: giuinha
8 Replies

2. UNIX for Dummies Questions & Answers

Read in Multiple log files and output selected variables and values to cvs file

I have several problems with my problems: I hope you can help me. 1) the If else statement I am getting an error message. My syntax must be incorrect because the entire statement is throwing an error. For example in filew.log if these items don't exist Memsize, SASFoundation and also if... (0 Replies)
Discussion started by: dellanicholson
0 Replies

3. Shell Programming and Scripting

Find and compare values from different txt files

Hello, i am new in Bash. Actually i have a directory : /home/resultfiles and inside i have these txt files: 531_1.out.res, 531_2.out.res , 531_3.out.res 532_1.out.res, 532_2.out.res , 532_3.out.res 533_1.out.res, 533_2.out.res, 533_3.out.res All these txt files has this format : num_q all... (3 Replies)
Discussion started by: nimpoura
3 Replies

4. Shell Programming and Scripting

Read record from the text file contain multiple separated values & assign those values to variables

I have a file containing multiple values, some of them are pipe separated which are to be read as separate values and some of them are single value all are these need to store in variables. I need to read this file which is an input to my script Config.txt file name, first path, second... (7 Replies)
Discussion started by: ketanraut
7 Replies

5. Shell Programming and Scripting

Shell script to run command + compare values and post a warning message.

Hi all, I am trying to create shell script to run command then compare values with rule set for every 5 seconds and post a warning message if the compared value meet the rules. -the script is related to Oracle/Sun product messaging server 6.2 1) command that need to be run to gather... (2 Replies)
Discussion started by: Mr_47
2 Replies

6. UNIX for Dummies Questions & Answers

rusty with cp command -- how to cp all .doc files with .txt extension

I'm rusty with cp, so I was wondering: is it possible to cp all the .doc files in a folder and make them .txt files? Can you use cp to do that? (3 Replies)
Discussion started by: Straitsfan
3 Replies

7. Shell Programming and Scripting

Script to run a command on all txt files present in a dir structure

Hi, I have a directory structure like the one given below root\a\b1 root\a\b2 root\b\b1 root\b\b2 . . . root\j\b1 root\j\b2 Now, there are a txt files in each dir and subdir, there is a root.txt I have to write a script where in i have to run a command called "genrb <filename>"... (6 Replies)
Discussion started by: vikramsinghnegi
6 Replies

8. UNIX for Dummies Questions & Answers

trouble using read to store values in variables from command output

I know there are caveats about using read in pipelines because read is treated by a subshell. I know this but I can't think of any way to accomplish this regardless, I'm still a rookie. I hope somebody will be able to interpret what it is that I'm trying to accomplish and correct me. ... (2 Replies)
Discussion started by: ProGrammar
2 Replies

9. Shell Programming and Scripting

command to list .txt and .TXT file

Hi expersts, in my directory i have *.txt and *.TXT and *.TXT.log, *.txt.log I want list only .txt and .TXT files in one command... how to ?? //purple (1 Reply)
Discussion started by: thepurple
1 Replies

10. Solaris

list files .txt and .TXT in one command

Dear experts, In a directory i have both *.TXT and *.txt files. I have a script- for file in `ls *.txt`; do mv $file /tmp/$file How to list both *.txt and*.TXT file in one command so that script will move both .txt or .TXT whatever it find. br//purple (4 Replies)
Discussion started by: thepurple
4 Replies
Login or Register to Ask a Question