|
Answer» how can i get the HOSTNAME from a workstation and make a folder NAMED the same as the workstation? i have tried "setlocal, set hostname=%hostname%, endlocal".
or in other words, "hostname" is a command. how can i make a file from the output of a command?
xpp sp3.
i am trying to backup multiple folders to one folder with the name of the workstation it came from. Im assuming you mean appending to a file, when you say "make a file from the output of a command"
> Clears the file >> adds a line to a file
example: echo hello>>myfile.txti am trying to GO to a workstation and run my batchfile. it needs to find the computer name and make a file with the name of the workstation. then it will backup some folders and save them under the folder that it just created with the computer name so i can find it later to restore them. i have the batch file created and it can store folders under the %username% VARIABLE, but i would MUCH rather have it store under computer name.
example: when i type "echo %username%" in a cmd it displays my user name. but when i type "echo %hostname%" it does not display. i can however type "hostname" by itself to get the workstation name....
thanks in advance...on your command prompt, type
Code: [Select]env. You can see computer name there.env does not work. isnt that for linux? i need to create a folder with the name of the pc...ComputerName is a system variable that you can use:
md %computername%
OR
You can still use the hostname command in a batch file:
Code: [Select]echo off for /f %%a in ('hostname') do ( md %%a )
Good luck.
Env works on WinXP but you can also use set to list all the environment variables.echo off md c:\%computername%
or if you want to name a file:
echo off echo. >> c:\%computername%.txt
thank you both, i ran the set comand to see the variables but "computername" was not in there. but it does work with computername so thanks again...
Quote from: 037 on March 31, 2010, 07:06:40 AM "Hostname" is a command. How can I make a file from the output of a command?
C:\>type thirty7.bat
Code: [Select]echo off
hostname > host.txt
type host.txt
pause md Okie cd Okie
echo hello okie > host.txt
type host.txt Output:
C:\>thirty7.bat Okie Press any key to continue . . . hello okie
C:\Okie>another greg
Quote from: ghostdog74 on April 04, 2010, 06:10:09 PManother greg
I already sent a PM to Nathan...
Quote from: ghostdog74 on March 31, 2010, 08:07:48 AMon your command prompt, type
Code: [Select]env. You can see computer name there.
I use XP pro SP3 and there is no env command.
Quote from: BobJordan on April 04, 2010, 08:55:11 PMI use XP pro SP3 and there is no env command.
Here.
|