LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-21-2016, 05:18 AM   #1
nibraz
Member
 
Registered: Oct 2008
Posts: 219

Rep: Reputation: 18
BAT script to copy files and run anther bat script?


Hi

I would appreciate if anyone here can help me with this? this is for my work and I am a bit stuck about how to do this.

My team asked me if I can do a bat script to do the following:

1. connect to server from server1 to server2
2. copy 2 files from server 2 to server 1
3. run the bat script from server 1
(bat script then uploads these 2 copied files) this bat script is already done.

Can anyone helpe me how to do 1,2 and 3?
 
Old 11-21-2016, 05:28 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,800

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
you gave almost no information, so we can hardly give you any help:
what kind of connection is it?
what kind of os is running on server, server1 and server2?
how do you want to transfer your files (over share, ftp, scp, rsync ...)?
...

http://www.linuxquestions.org/questi...gs-4175464257/
http://catb.org/~esr/faqs/smart-questions.html
 
Old 11-21-2016, 05:32 AM   #3
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS,Manjaro
Posts: 5,591

Rep: Reputation: 2689Reputation: 2689Reputation: 2689Reputation: 2689Reputation: 2689Reputation: 2689Reputation: 2689Reputation: 2689Reputation: 2689Reputation: 2689Reputation: 2689
Perhaps. Must we guess what operating systems and what kinds of machines are involved? Is there a TCP network connection between the machines? Is there any special software installed that might either interfere or support this operation? What have you researched or tried before posting the question here?

You might browse the information about asking intelligent questions, available on this site.
 
Old 11-21-2016, 05:46 AM   #4
nibraz
Member
 
Registered: Oct 2008
Posts: 219

Original Poster
Rep: Reputation: 18
Quote:
Originally Posted by pan64 View Post
you gave almost no information, so we can hardly give you any help:
what kind of connection is it?
what kind of os is running on server, server1 and server2?
how do you want to transfer your files (over share, ftp, scp, rsync ...)?
...

http://www.linuxquestions.org/questi...gs-4175464257/
http://catb.org/~esr/faqs/smart-questions.html
Sorry forgot to add that..

Connection is from a SFTP
All servers are running windows server 2008.
Transfer files over scp/sftp

sample script which only does copy file:
Code:
"\\server\Polling\ToStoresPolling\"
CD "\\server\Polling\ToStoresPolling\FTP"
ftp -i -s:"\\server\Polling\ToStoresPolling\FTP\FTPUploadScript.txt" > \\server2\Polling\ToStoresPolling\FTP\Log.txt
what it needs to do is after copying the files it need to run the bat script on \\server2 that is already there.
 
Old 11-21-2016, 06:04 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,800

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
here you can find some tips:
http://stackoverflow.com/questions/1...on-a-remote-pc
 
Old 11-21-2016, 06:10 AM   #6
nibraz
Member
 
Registered: Oct 2008
Posts: 219

Original Poster
Rep: Reputation: 18
Hi

We cant use psexec commmand this wont work.

Its for polling only bat scripts works.
 
Old 11-21-2016, 06:34 AM   #7
nibraz
Member
 
Registered: Oct 2008
Posts: 219

Original Poster
Rep: Reputation: 18
Did this test script..

Quote:
set path=c:\WINDOWS\system32

echo Copying started at %date% %time%>>_date_.txt

xcopy C:\Users\HabeebN\Documents\Infrastructure\Scripts C:\Users\HabeebN\Documents\Infrastructure\Test /s /a /d

echo Copying finished at %date% %time%>>_date_.txt

echo Completed Successfully at %date% %time%>>_date_.txt

echo --------------------------------------------------------------------------- >>_date_.txt

CALL "C:\foo.bat"

echo Uploaded Successfully at %date% %time%>>_date_.txt

pause
Its working on my local computer but how can i make it work on the server? when i put in the server path \\servername it stops working..
 
Old 11-21-2016, 06:38 AM   #8
nibraz
Member
 
Registered: Oct 2008
Posts: 219

Original Poster
Rep: Reputation: 18
problem is how do i get it to work with SFTP?
 
Old 11-21-2016, 06:54 AM   #9
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,856
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
You sure this thing is SFTP? I would think it is "File and printer sharing", a part of Microsoft networking,
 
Old 11-21-2016, 07:22 AM   #10
nibraz
Member
 
Registered: Oct 2008
Posts: 219

Original Poster
Rep: Reputation: 18
Quote:
Originally Posted by NevemTeve View Post
You sure this thing is SFTP? I would think it is "File and printer sharing", a part of Microsoft networking,
Yes the company I work at everything is SFTP and SSL etc part of PCI Compliant.

This script works below but only within the same server. Not sure how to edit this to work from
CONNECT SFTP SERVER 1 to SERVER 2
COPY SERVER 2 file to SERVER 1 (SFTP) connection

Code:
set path=c:\WINDOWS\system32

echo Copying started at %date% %time%>>_date_.txt

xcopy \\172.10.10.2\c$\Test\test1.xml \\172.20.10.2\c$\temp /s /a /d

echo Copying finished at %date% %time%>>_date_.txt

echo Completed Successfully at %date% %time%>>_date_.txt

echo --------------------------------------------------------------------------- >>_date_.txt

CALL "\\172.20.10.2\c$\Test\foo.bat"

echo Uploaded Successfully at %date% %time%>>_date_.txt

pause
 
Old 11-21-2016, 07:45 AM   #11
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
does windows have an scp command ?:
Code:
which scp
 
Old 11-21-2016, 08:16 AM   #12
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,856
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
In Windows, it's putty you can use as SSH (and scp, sftp) client. Also there is WinScp

Last edited by NevemTeve; 11-21-2016 at 09:47 AM. Reason: 'Also' became 'Alsó' thanks to my phone.
 
Old 11-21-2016, 08:43 AM   #13
nibraz
Member
 
Registered: Oct 2008
Posts: 219

Original Poster
Rep: Reputation: 18
Quote:
Originally Posted by schneidz View Post
does windows have an scp command ?:
Code:
which scp
Quote:
'scp' is not recognized as an in
operable program or batch file.

'which' is not recognized as an internal or external command,
operable program or batch file.
this script i am trying to do is for automated polling
 
Old 11-21-2016, 09:34 AM   #14
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,679

Rep: Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892
You can use xcopy to copy a file to a remote computer. xcopy does use Microsoft file sharing (CIFS)

To copy a file from server1 to server2 via xcopy.

Code:
net use \\server2\shared_folder password /user:domain\username

xcopy file1.txt \\server2\shared_Folder\file1.txt
 
net use "\\server2\Shared_Folder" /delete
By the way sftp and ftps are different protocols.
 
Old 11-21-2016, 09:47 AM   #15
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,856
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
(And SMB/CIFS is a third protocoll
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cant run .bat files tukk Linux - Newbie 15 08-25-2013 02:43 AM
Converting a .bat script to sh script to work in linux server newtounix Programming 3 07-21-2011 07:30 AM
How to run bat file from Unix script??? gopi_20us Programming 10 09-14-2010 09:15 AM
How to execute a ssh script on Linux server from Windows through a bat script? wanna13e Programming 13 10-23-2009 02:41 AM
Does linux run bat files like DOS oldgi Linux - Software 6 07-05-2007 11:47 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration