Live Chat & Podcast at 1:00PM Eastern on Sunday!
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Software Development
Tag Cloud
access acer asus bios bsod computer crash desktop dns driver drivers error ethernet excel freeze gaming graphics hard drive hardware hdmi internet laptop malware memory monitor motherboard network printer problem ram registry repair router slow software sound trojan ubuntu 11.10 uninstall usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Software & Hardware > Software Development >
Solved: Creating a Batch file

Reply  
Thread Tools
ustacp's Avatar
Computer Specs
Member with 292 posts.
 
Join Date: Aug 2004
Location: Akron, Ohio
Experience: I'm trying.
12-Jan-2010, 05:40 PM #1
Question Solved: Creating a Batch file
I am looking to create a batch file. I have little to no experience writing batch files, which is why I am here. We are having issues with one of our software titles and they fix they gave to us is to replace a specified file with a new file to fix the issue. We have 200 plus computers with this software on it, which will take a long time to do manually going to each computer. We have software to actually push batch files out and such but I need to create it first.

What I need the batch file to do is go out to a specified directory, rename the current file, and then add a new file to that directory. I want to rename the current file in case we have to revert back to it down the road. The file we are adding will be the same file name, which is why the original needs to be renamed. If anyone could help me with this, I would really appreciate it. In the meantime, I will be trying to learn myself. This will also need to be a silent operation without any user interaction.

Thanks,
David
__________________

David
Only The Dead Have Seen The End Of War
hockeyfreak863's Avatar
Computer Specs
Member with 148 posts.
 
Join Date: Feb 2008
Experience: Intermediate
12-Jan-2010, 08:28 PM #2
for example remove the ("") and modify it in notepad then when done save it as "filename".bat

@echo off

ren "C:\Program Files\test.txt" "testing.txt.old" (Take this out when in acutall use, for renaming files")
move "%userprofile%\desktop\test.txt" "C:\test.txt" ("moves the file from the desktop to C:")
mkdir "C:\test" ("Creates a new folder within the specified location")
ustacp's Avatar
Computer Specs
Member with 292 posts.
 
Join Date: Aug 2004
Location: Akron, Ohio
Experience: I'm trying.
13-Jan-2010, 05:33 PM #3
Thanks for your reply. The rename worked great. Would it be possible to move a file from a network share and place it to the end users PC? I would of course need to provide credentials to access the file unless I created a share that allowed all access for the time being. So I would need to pass the appropriate credentials to the share in order to pull the file. I would be happing if I could just get it to pull the file from a network share and place it to the user’s PC. I tried doing it myself but could not get it to work. Thanks again!!!
__________________

David
Only The Dead Have Seen The End Of War
hockeyfreak863's Avatar
Computer Specs
Member with 148 posts.
 
Join Date: Feb 2008
Experience: Intermediate
16-Jan-2010, 11:28 PM #4
the computers would have to be mapped to that one computer, if they are already mapped the syntax would be ie copy "Y:\test.txt" "C:\test.txt" this copies the files from the server to the users computer, only if its mapped if its not then it may be best to show your employees a demo of how to get the bat file
ustacp's Avatar
Computer Specs
Member with 292 posts.
 
Join Date: Aug 2004
Location: Akron, Ohio
Experience: I'm trying.
01-Feb-2010, 11:05 AM #5
OK, I did manage to get this all to work. I was actually able to figure out how to do this all with one-step using our management software. I was able to create a script with multiple tasks. This way I was able to upload the file to our management software and then pushed the file out to a folder on each pc. I then was able to verify if the file that needed to be renamed was on the pc and renamed the file with the script you provided. Finally I verified that the uploaded file was present on the pc and used the script you provided to move the file to the new location.

Thanks a lot for all your help with this. I need to get more familiar with scripts as they work well with our management software and help save a lot of time.
__________________

David
Only The Dead Have Seen The End Of War
PatrickMc's Avatar
Junior Member with 14 posts.
 
Join Date: Jun 2009
02-Feb-2010, 01:05 PM #6
Pushing files on networked computers while saving the previous files
We do this all the time. There is a file C:/hosts.txt which lists all the hosts on the network - one host per line. It looks like the following.

C:/hosts.txt
Quote:
Computer1
Computer2
.
.
.
Then there is a file that contains a list of files to be pushed, C:/files.txt. It looks like the following.

C:/files.txt
Quote:
C:/APLIT/Reports/Daily/Manager.rpt
C:/APLIT/Reports/Daily/SalesAssociate.rpt
C:/APLIT/Reports/Weekly/Manager.rpt
C:/APLIT/Reports/Weekly/SalesAssociate.rpt


Then this script, run from one computer, will push each file in files.txt to the exact same location to each host in file hosts.txt, while saving the previous files as _saved.



Code:
 
# Script PushFiles.txt
var str filelist, file, hostlist, host, destfile, saveddestfile
 
# Read the file list.
cat "C:/files.txt" > $filelist
 
# Get the first file.
lex "1" $filelist > $file
 
# Go thru files one by one.
while ($file <> "")
do
    # Read the host list.
    cat "C:/hosts.txt" > $hostlist
 
    # Get the first host.
    lex "1" $hostlist > $host
 
    # Go thru the hosts one by one.
    while ($host <> "")
    do
        # We have the source file in $file. The destination file is
        # gotten by replacing the "C:/" part with "//Computer1/".
        sal -p "^:/^]" ("//"+$host+"/") $file > $destfile
 
        # Destination file in now $destfile. Copy it first to _saved.
        set $saveddestfile = $destfile+"_saved" 
 
        # Save the previous destination file, if exists.
        echo -e "DEBUG: Copying " $destfile " to " $saveddestfile
        system -s "copy /Y" ("\""+$destfile+"\"") ("\""+$saveddestfile+"\"") 
 
        # Copy $file onto $destfile.
        echo -e "DEBUG: Copying " $destfile " to " $destfile
        system -s "copy /Y" ("\""+$file+"\"") ("\""+$destfile+"\"")      
 
        # Get the next host.
        lex "1" $hostlist > $host
    done
 
    # Get the next file to push.
    lex "1" $filelist > $file
done


Script is in biterscripting ( http://www.biterscripting.com ). Save the script in file, say, "C:/Scripts/PushFiles.txt". Run it as

Code:
 
 
script "C:/Scripts/PushFiles.txt"


Test first in your environment - particularly, you may need to experiment with the "//Computer1/APLIT/Reports/Weekly/Manager.rpt" syntax. On some networks, you may need to experiment with this syntax.

You can write a mirror script to revert the changes. But I will leave it up to you to do that.
Reply

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 09:32 PM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.