Need bash script to ping the servers and rename the output file each time the script is ran


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need bash script to ping the servers and rename the output file each time the script is ran
# 1  
Old 07-10-2012
Need bash script to ping the servers and rename the output file each time the script is ran

HI,
I have a file serverlist in that all host names are placed.
i have written a small script
#./testping

#! /bin/bash
for i in `cat serverlist`
do
ping $i >> output.txt
done
so now it creates a file output.txt till here fine..
now each time i run this script the output file name need to be changed..
i tried a lot but unable to do this. any quick help is appreciated
# 2  
Old 07-10-2012
Code:
 
outputfile=$(date +%Y%m%d_%H%M%S.log)
 
and change the below line
 
ping $i >> $outputfile

This User Gave Thanks to itkamaraj For This Post:
# 3  
Old 07-10-2012
Like this?

Code:
#! /bin/bash
for i in `cat serverlist`
do
ping $i
done > output.txt_$(date +%d%m%Y%H%M%S)

This User Gave Thanks to elixir_sinari For This Post:
# 4  
Old 07-12-2012
THanks it worked..

---------- Post updated at 11:22 AM ---------- Previous update was at 11:21 AM ----------

thanks...worked
# 5  
Old 07-13-2012
Code:
 
#! /bin/bash
while read ip
do
ping $i
done < serverlist > output.txt_$$

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to ping multiple servers

Hi I did the following script to ping multiple servers, but I keep on receiveing duplicate emails for one server that is down: #!/bin/bash date cat /var/tmp/servers.list | while read output do ping -c 1 "$output" > /dev/null if ; then echo "node $output is up" else ... (10 Replies)
Discussion started by: fretagi
10 Replies

2. Shell Programming and Scripting

Ping script to list of servers

Hi Friends, I have experience in redhat/ Ubuntu OS, but I am very new to solaries os. my servers OS is Oracle Solaris 10 8/11 s10x_u10wos_17b X86. I have a file contains 200 servers IPs one by one. now I want a script to chaeck which IPs are pinging, not pingning. I... (8 Replies)
Discussion started by: kumar85shiv
8 Replies

3. Shell Programming and Scripting

Script to Ping Servers

Hey, It's me again! Still trying to learn to become a better scripter on the job :) New challenge for assistance, if anyone cares to help, and its two parted! First part, I wanted to create a script at work that would ping a server that was supplied in an argument, then a count (amount of times)... (5 Replies)
Discussion started by: gkelly1117
5 Replies

4. Shell Programming and Scripting

Ping the hostname of many servers using a script

Hi We have some 300 servers in the Data center and some of them are running with AIX and some of them are running with Solaris. I need a script which can be run in one of the server and that script should ping the hostname of all the 300 servers. Also the script should notify if any server is... (9 Replies)
Discussion started by: newtoaixos
9 Replies

5. UNIX for Dummies Questions & Answers

Ping bash script to file

Hello: I have this script: #!/bin/bash #for loop for ip in `cat ips` do ping $ip | grep "is alive">>pingtestlog done And its working properly with this input: ericadm@amxcruas1> cat ips 10.196.60.4 10.196.61.210 10.196.62.73 10.196.61.152 (5 Replies)
Discussion started by: asenav1
5 Replies

6. Shell Programming and Scripting

Bash script for ping in your own subnet

I have a question for one who wants to help me. I want to create a bash script to ping IP-adresses. It must first ask me the beginnen IP, then the ending IP like: 192.168.100.1 - 192.168.100.255. When nothing is filled in, then it must find my subnet and ping that, like when my ip is... (14 Replies)
Discussion started by: ugurgazi
14 Replies

7. Shell Programming and Scripting

Changing File Time Stamp (Bash Script)

I need some help recovering from a "slight" screwup. We just moved 3 TB of data from one RAID Array to another. Low lever archive files. This was done with a regular cp (for some reason) and now we have lost all the timestamps on the files, and we urgently need to get the timestamps back on these... (7 Replies)
Discussion started by: chj
7 Replies

8. Shell Programming and Scripting

Script to ran ant.xml file

Hi All, I want to login to Oracle Application Server and run ant.xml file. Can someone propose a script for that task? Thanks, Abraham123 (0 Replies)
Discussion started by: Abraham123
0 Replies

9. UNIX for Advanced & Expert Users

script to ping servers

Hi , I would like to automate a script to ping all the unix servers perodically thru cronjob. Is there any script out there? If so Please give me. Thanks in advance. (2 Replies)
Discussion started by: sriny
2 Replies

10. AIX

Script to ping servers in a file

I would like to ping a list of servers in a text file. Can anyone help? (1 Reply)
Discussion started by: gbarkhor
1 Replies
Login or Register to Ask a Question