1.

Solve : Append file name with the hostname?

Answer»

I have a batch file to capture tracert and systeminfo and saving to a .txt file, though want to have the file name include the 'hostname'.  Example is the file would be tracert(hostname).txt
Tried rename and no luck.show us your batch file
Trying to capture trace routes and system info for TROUBLESHOOTING LAN/WAN performance issues and save to a file for easy association.

The batch file may be run on any workstation (hostname), the output file 'oracle.txt' may be stored with others captured from different sources, so need an easy way to manage, identify and retrieve the file for each host.  As such, the hostname is an easy way since no name is the same.

echo off
:starttrace

echo %date% %time% >>oracle.txt

echo starting trace route for Oracle

tracert oracle.es.com >>oracle.txt

echo trace route complete

systeminfo >>oracle.txt

exitWhy not just echo the results to tracert.oracle.es.com.txt?

The same batch file (trace) may run from anyone of thousands of workstations globally, so would like the file to be named specific to that trace.1. Where is the batch file GETTING the hostname from?
The batch file is run on the workstation (hostname), capturing the tracert and system information to the .txt file. The results in the file tell a lot about the path USED to reach the remote system and the current state of the workstation useful in troubleshooting remote system LAN/WAN access.

Results in the oracle.txt file from running oracle.bat

Tue 10/26/2010 12:37:12:10
Tracing route to oracle.es.com [10.40.23.234]
over a maximum of 30 hops:

1     12ms     13ms     <11ms     10.42.255.45
2     120ms   114ms   118ms      oracle.es.com [10.40.23.234]

Trace complete.

Host Name:                  ESP231456
OS Name:                     Microsoft Windows XP
OS Version:                   4.1.2.0
 - - - - ---------------------------------You want the hostname of the machine on which the batch is run to be used in the filename of the logfile? Possibly you could use the system variable %LOGONSERVER% like this...

CODE: [Select]echo off
:starttrace

echo %date% %time% >>tracert.%LOGONSERVER%.txt

echo starting trace route for Oracle

tracert oracle.es.com >>tracert.%LOGONSERVER%.txt

echo trace route complete

systeminfo >>tracert.%LOGONSERVER%.txt

exitlogonserver needs illegal characters to be removed

Code: [Select]echo off

set hname=%logonserver:\=%

:starttrace

echo %date% %time% >>tracert.%hname%.txt

echo starting trace route for Oracle

tracert oracle.es.com >>tracert.%hname%.txt

echo trace route complete

systeminfo >>tracert.%hname%.txt

exitResolved by using 'COMPUTERNAME', so the resulting file is named "ES12345-tracert.txt" for the below code line.

tracert oracle.es.com >>%COMPUTERNAME%-tracert.txt

"HOSTNAME" does not work.

Thanks for the assist.  Now, have to get support to use it.



Discussion

No Comment Found