Store output and Echo


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Store output and Echo
# 1  
Old 05-13-2006
Store output and Echo

I will admit I am a newbie but I am trying to write some simple scripts

Situation:

I have a list of IP Addresses that I want to once or 2 times a day store the average ping response time in a database (mysql) I am part way there but not all the way there

I have the following

cat ./slow | while read line
do
for i in $line
do
ping -c1 -q $i | grep "mdev" | gawk -F"/" '{print $5}'
done
done

Which parses the average response time out properly I really would like to have something like the following

But my Question is Why can I not get $i to show up? in the print statment


cat ./slow | while read line
do
for i in $line
do
ping -c1 -q $i | grep "mdev" | gawk -F"/" '{print "update table set field1 ="$5" where field2="$i""}'
done
done

Results
update table set field1 =138.668 where field2=rtt min/avg/max/mdev = 138.668/138.668/138.668/0.000 ms
update table set field1 =209.089 where field2=rtt min/avg/max/mdev = 209.089/209.089/209.089/0.000 ms

Last edited by meyerder; 05-13-2006 at 12:25 PM..
# 2  
Old 05-13-2006
Hea I might have found the issue. I have one SLIGHT problem now

update stores_new set Current_Ping="$5" I cant seem to get the "$5" to be enclosed by a 'value' where mysql will take it

#!/bin/sh
rm /tmp/baseline
/usr/bin/mysql -htxdf -uxxxx -pxxxx -D test1 -e "select Remote_Router_Ethernet_IP_Address from stores_new where Open_or_Closed='Open' and Location_Type !='MSC'" > /tmp/baseline
cat /tmp/baseline | while read line
do
for i in $line
do
ping -c1 -q $i | grep "mdev" | gawk -F"/" '{print "update stores_new set Current_Ping="$5" where Remote_Router_Ethernet_IP_Address='$i';update stores_new set Ping_Diff=(Ping_Current-Ping_Avg) where Remote_Router_Ethernet_IP_Address='$i'; "}' >> /tmp/current_times
done
done

Last edited by meyerder; 05-13-2006 at 08:32 PM..
# 3  
Old 05-14-2006
You can use printf to format string a little better. I don't fully understand your SQL, ( eg Ping_Current-Ping_Avg are the fields?) but you get the idea:
Code:
gawk -F"/" '
    {printf( "update stores_new 
         set Current_Ping='%s' 
         where                  
         Remote_Router_Ethernet_IP_Address='$i';", $5);
      printf( "  update stores_new 
                 set Ping_Diff=(%f ) 
                 where 
                 Remote_Router_Ethernet_IP_Address='$i';", Ping_Current-Ping_Avg);} '

and PLEASE use code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Store output in variables instead of files

Hi All, I have written a (bash) function which generates multiple files say file1 file2 file3 now I want to reduce the generation of these three files i.e. store the output of three files in variables, and generate the same results, in-order to avoid multiple creation of files how is that... (7 Replies)
Discussion started by: sam@sam
7 Replies

2. Shell Programming and Scripting

how to store output to a variable

I need some help: 1) I have a out put from a shell script, the out put looks like this: Attempting privilege escalation using sudo ... List backups for CLTST: Start date Status Ret. Class Label -------------------- ------------ ------------ ... (2 Replies)
Discussion started by: samk
2 Replies

3. Shell Programming and Scripting

Store the output values in array

Hi, How to store the values in array from output result, EG: I have the result like this, ps, google, 1.txt, 1 sam, google, 2.txt, 2 These are the four values followed by comma in two sets. I need to store these values set by set. One set contains four values followed by comma. ... (2 Replies)
Discussion started by: KarthikPS
2 Replies

4. Shell Programming and Scripting

How to store output of command to an array

Hello Guys, I am trying to store output of command to an array and then want to print, but it showing an error that "bad substitution". I am not getting why it's happening. Can anyone help me? #!/usr/bin/sh hr=0 min=0 i=1 last $1 | grep -w `date "+%b"` | grep -v '\(0:.*\)' | grep -vw sshd... (8 Replies)
Discussion started by: kasparov
8 Replies

5. Shell Programming and Scripting

Store grep output file

Hi, I'm trying to store the output from a grep, I just want the file name. But couldn't find how to do it. Basically, I just want to grep <etc> * and I want to store the file name. There is only one file with the what I'm grepping, so storing in a variable o an array its the same. If someone... (3 Replies)
Discussion started by: radicaled
3 Replies

6. Shell Programming and Scripting

store sqlplus output in variable

hi how can i store sqlplus output to a variable in sh script (not bash) Thanks MM (1 Reply)
Discussion started by: murtymvvs
1 Replies

7. Shell Programming and Scripting

To store output of ls command

Hi, I need to pass a run time input to unix script which tracks the list of files in the directory under certain pattern. The files which are matched to the given pattern then need to be stored in the array. Requesint you all to please suggest me the solution. I gave the below command in the... (13 Replies)
Discussion started by: Sekar1
13 Replies

8. Shell Programming and Scripting

ksh script that echo " please insert your name " and store the output to a login.log file.

Hello All Nice to meet you all here in this forum, it's my 1rst time here i'm asking about a little issue that i face i added a ksh script that echo " please insert your name " and store the output to a login.log file. the script is working fine with normal telnet but Xstart is not working... (8 Replies)
Discussion started by: islam.said
8 Replies

9. Shell Programming and Scripting

To store the output in a variable

Hi, I am getting the following error while executing the script. Please can someone throw some light where is the problem. Many thanks. ./check: temp: not found The directory related to SEP instance 4 does not exist. The script is as follows. SEP_APP="/scp/sepx/app... (2 Replies)
Discussion started by: Sudhakar333
2 Replies

10. Shell Programming and Scripting

store output to a file and read from it

Hello all, I need to run snoop command for a period of time (a day) and extract remote host column from it to find out who is accessing my server. When I run the following on the command line it works snoop -port 22 | awk '{print $3}' but when I do snoop -port 22 | awk '{print $3}' | while... (2 Replies)
Discussion started by: afadaghi
2 Replies
Login or Register to Ask a Question