Sponsored Content
Top Forums Shell Programming and Scripting print out a line from a output file Post 302316425 by deaconf19 on Friday 15th of May 2009 04:00:27 AM
Old 05-15-2009
Code:
 #!/bin/csh
foreach i (`grep xxx /etc/hosts |awk '{print $2}'`)
echo $i
ping ${i} 2 > /tmp/results 
end

Contents of the results file
Code:
 
herexxx001 is alive
herexxx002 is alive
no answer from herexxx003
no answer from herexxx004

Next line of code
Code:
 cat results |grep alive > /tmp/alive

contents of the alive file
Code:
herexxx001 is alive
herexxx002 is alive

Next Line of the script
Code:
cat /tmp/alive |awk '{print $1}' > /tmp/start

Contents of the start file
Code:
herexxx001
herexxx002

the last line of code
Code:
 foreach x (`grep xxx /tmp/start |awk '{print $1}'`)
echo $x
rsh ${x} init 6
end

my problem now is when i only execute the ping portion of the script i do not get the expected outcome. I have 5 clients that are on the network and alive and the rest of the clients are off. The results file only shows
Code:
herexxx021 is alive

when in fact there are 5 total and nothing else is in the file. did i redirect the out put incorrectly?
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

locating the line and print the output

hi all, I would like to know , if a file contains say 100 lines, and if i want to locate the 54th line and print the output , how to do it?? for eg , if a file details.txt which contains say 100 entries like admin .................... rajes .................... test ..................... (7 Replies)
Discussion started by: vasikaran
7 Replies

2. UNIX for Dummies Questions & Answers

How do i print this output all on the same line?

I have this simple script which gives info on HBA ports. How do i get it all to print on the same line? !#/bin/ksh TMP_INFOFILE=/tmp/tmpfile if ; then rm -f $TMP_INFOFILE touch $TMP_INFOFILE fi PORT_INFOFILE=/tmp/aa if ; then rm -f $PORT_INFOFILE ... (1 Reply)
Discussion started by: rcon1
1 Replies

3. Shell Programming and Scripting

How to print the output in single line

Hi, Please suggest, how to get the output of below script in single line, its giving me in different lines ______________________ #!/bin/ksh export Path="/abc/def/ghi"; Home="/home/psingh/prat"; cd $Path; find $Path -name "*.C#*" -newer "abc.C#1234" -print > $Home cat $Home | while... (1 Reply)
Discussion started by: Prat007
1 Replies

4. Shell Programming and Scripting

extract nth line of all files and print in output file on separate lines.

Hello UNIX experts, I have 124 text files in a directory. I want to extract the 45678th line of all the files sequentialy by file names. The extracted lines should be printed in the output file on seperate lines. e.g. The input Files are one.txt, two.txt, three.txt, four.txt The cat of four... (1 Reply)
Discussion started by: yogeshkumkar
1 Replies

5. Shell Programming and Scripting

Print output and read input on same line

How do I print output and read input on the same line in ksh? echo Hello, what is your name? read name (1 Reply)
Discussion started by: robin_simple
1 Replies

6. Linux

Print line 1 if line 3 matches of the output

Hi I want to extend following command so that on the basis of "Branch: ****" on the third line I can grep and print name of the file on the first line. cat .labellog.emd | grep DA2458A7962276A7E040E50A0DC06459 | cut -d " " -f2 | grep -v branch_name | xargs -I file <command to describe> file ... (1 Reply)
Discussion started by: ezee
1 Replies

7. Shell Programming and Scripting

Print line number from piped output

i need to do something like this: script.sh #!/bin/sh echo "hello" echo "My First name is John" echo "My Last name is Smith" echo "I am here to save you a lot of work" sed -n 4,5p $0 i dont want to run the script. i just want to pull out specific line from it. so the logic here... (5 Replies)
Discussion started by: SkySmart
5 Replies

8. UNIX for Beginners Questions & Answers

Output to file print as single line, not separate line

example of problem: when I echo "$e" >> /home/cogiz/file.txt result prints to file as:AA BB CC I need it to save to file as this:AA BB CC I know it's probably something really simple but any help would be greatly appreciated. Thank You. Cogiz (7 Replies)
Discussion started by: cogiz
7 Replies

9. Shell Programming and Scripting

Print loop output on same line dynamically

Hi, I am trying to print copy percentage completion dynamically by using the script below, #!/bin/bash dest_size=0 orig_size=`du -sk $sourcefile | awk '{print $1}'` while ; do dest_size=`du -sk $destfile | awk '{print $1}'` coyp_percentage=`echo "scale=2; $dest_size*100/$orig_size"... (4 Replies)
Discussion started by: Sumanthsv
4 Replies

10. UNIX for Beginners Questions & Answers

Read line and print output

need help to print the below .. Content of file looks like below .. SCHEMA1. TABLE1 SCHEMA2. TABLE2 SCHEMA3. TABLE3 read lines from above file and print o/p as below print output like read 1st line and print SELECT SCHEMA1.TABLE1 print output like read 2st line and print ... (4 Replies)
Discussion started by: rocking77
4 Replies
MAXDB_PING(3)								 1							     MAXDB_PING(3)

maxdb_ping - Pings a server connection, or tries to reconnect if the connection has gone down

       Procedural style

SYNOPSIS
bool maxdb_ping (resource $link) DESCRIPTION
Object oriented style bool maxdb::ping (void ) Checks whether the connection to the server is working. If it has gone down, and global option maxdb.reconnect is enabled an automatic reconnection is attempted. This function can be used by clients that remain idle for a long while, to check whether the server has closed the connection and recon- nect if necessary. RETURN VALUES
Returns TRUE on success or FALSE on failure. EXAMPLES
Example #1 Object oriented style <?php $maxdb = new maxdb("localhost", "MONA", "RED", "DEMODB"); /* check connection */ if (maxdb_connect_errno()) { printf("Connect failed: %s ", maxdb_connect_error()); exit(); } /* check if server is alive */ if ($maxdb->ping()) { printf ("Our connection is ok! "); } else { printf ("Error: %s ", $maxdb->error); } /* close connection */ $maxdb->close(); ?> Example #2 Procedural style <?php $link = maxdb_connect("localhost", "MONA", "RED", "DEMODB"); /* check connection */ if (maxdb_connect_errno()) { printf("Connect failed: %s ", maxdb_connect_error()); exit(); } /* check if server is alive */ if (maxdb_ping($link)) { printf ("Our connection is ok! "); } else { printf ("Error: %s ", maxdb_error($link)); } /* close connection */ maxdb_close($link); ?> The above example will output something similar to: Our connection is ok! PHP Documentation Group MAXDB_PING(3)
All times are GMT -4. The time now is 05:50 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy