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
#! /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
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.
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
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
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
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
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
yes i tried and got below message
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
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
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:
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
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
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
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
This is why you're supposed to use the return code instead of making the computer swallow the human-readable error messages. There's lots of ways the printing could work, but only one way a return code works.
In this case, it must be printing these messages to standard error. That's the place things the computer isn't supposed to be handling like this go. We can force the script to intercept these things it's not supposed to handle with a redirection.
while read NODE PORT UID PWD
do
cfsend n:"${NODE}" port:${PORT} uid:${UID} pwd:${PWD} pn:CHCKDIR ud:5563 trtype:c rcmd:"pwd" 2>&1 | grep -iq "failed communicating with partner" && echo "PS is down on $NODE"
done < table > output.log 2>/dev/null
Hi Corona,
I passed the cfsend command line output into one log file,from there i did grep command and written a logging to find only
"Failed Communicating with partner" and corresponding node name
its working fine for couple of node names,will try add more nodes in the txt file
And i have one question wanna confirm with you :when passing values from the txt file-how do i separate the values(node,port,uid and pwd)
i am thinking using a space between the values.
Exmp....
node port uid pwd
node port uid pwd
node port uid pwd
is that correct or any other way?
# for space-separated file
while read NODE PORT UID PWD
do
...
done < datafile
# for comma separated file
while IFS="," read NODE PORT UID PWD
do
...
done < datafile
#etc