

InterviewSolution
Saved Bookmarks
1. |
Solve : Append file name with the hostname? |
Answer» <html><body><p>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<br/>Tried rename and no luck.show us your batch file<br/>Trying to capture trace routes and system info for <a href="https://interviewquestions.tuteehub.com/tag/troubleshooting-16225" style="font-weight:bold;" target="_blank" title="Click to know more about TROUBLESHOOTING">TROUBLESHOOTING</a> LAN/WAN performance issues and save to a file for easy association.<br/><br/>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.<br/><br/>echo off<br/>:starttrace<br/><br/>echo %date% %time% >>oracle.txt<br/><br/>echo starting trace route for Oracle<br/><br/>tracert oracle.es.com >>oracle.txt<br/><br/>echo trace route complete<br/><br/>systeminfo >>oracle.txt<br/><br/>exitWhy not just echo the results to tracert.oracle.es.com.txt?<br/><br/>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 <a href="https://interviewquestions.tuteehub.com/tag/getting-2670847" style="font-weight:bold;" target="_blank" title="Click to know more about GETTING">GETTING</a> the hostname from?<br/>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 <a href="https://interviewquestions.tuteehub.com/tag/used-763273" style="font-weight:bold;" target="_blank" title="Click to know more about USED">USED</a> to reach the remote system and the current state of the workstation useful in troubleshooting remote system LAN/WAN access.<br/><br/>Results in the oracle.txt file from running oracle.bat<br/><br/>Tue 10/26/2010 12:37:12:10<br/>Tracing route to oracle.es.com [10.40.23.234]<br/>over a maximum of 30 hops:<br/><br/>1 12ms 13ms <11ms 10.42.255.45<br/>2 120ms 114ms 118ms oracle.es.com [10.40.23.234]<br/><br/>Trace complete.<br/><br/>Host Name: ESP231456<br/>OS Name: Microsoft Windows XP<br/>OS Version: 4.1.2.0<br/> - - - - ---------------------------------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...<br/><br/> <a href="https://interviewquestions.tuteehub.com/tag/code-25512" style="font-weight:bold;" target="_blank" title="Click to know more about CODE">CODE</a>: <a>[Select]</a>echo off<br/>:starttrace<br/><br/>echo %date% %time% >>tracert.%LOGONSERVER%.txt<br/><br/>echo starting trace route for Oracle<br/><br/>tracert oracle.es.com >>tracert.%LOGONSERVER%.txt<br/><br/>echo trace route complete<br/><br/>systeminfo >>tracert.%LOGONSERVER%.txt<br/><br/>exitlogonserver needs illegal characters to be removed<br/><br/> Code: <a>[Select]</a>echo off<br/><br/>set hname=%logonserver:\=%<br/><br/>:starttrace<br/><br/>echo %date% %time% >>tracert.%hname%.txt<br/><br/>echo starting trace route for Oracle<br/><br/>tracert oracle.es.com >>tracert.%hname%.txt<br/><br/>echo trace route complete<br/><br/>systeminfo >>tracert.%hname%.txt<br/><br/>exitResolved by using 'COMPUTERNAME', so the resulting file is named "ES12345-tracert.txt" for the below code line.<br/><br/>tracert oracle.es.com >>%COMPUTERNAME%-tracert.txt<br/><br/>"HOSTNAME" does not work.<br/><br/>Thanks for the assist. Now, have to get support to use it.</p></body></html> | |