-1

I have a program on Linux server, which runs a shell script on Linux server. Say "/tmp/ShellScript.sh"

Now I want to copy a file placed on my Windows Machine location "C:\WindowsFolder\FileToCopy" to Linux System directory "/tmp", ONLY WHENEVER /tmp/ShellScript.sh IS EXECUTED ON LINUX.

How can I achieve this ?

I can also manipulate the script " /tmp/ShellScript.sh" itself and write the logic in that, considering it is empty by default.

  • Add the copy line to the script? You do have passwordless ssh enabled? – Andrew Henle Aug 27 '18 at 12:08
  • You do have passwordless ssh enabled? -- Yes, I can use sshpass as well in case its not. But what I'm not able to understand is that how Linux shell script can run some command in Windows (Just like I need here to copy file from Windows to Linux) – Rahul Aug 27 '18 at 12:12
  • I know I can have a .bat file with scp command, running which can copy file from Windows to Linux using scp protocol. But the twist here is that i want this operation to be performed when /tmp/ShellScript.sh is executed – Rahul Aug 27 '18 at 12:15
  • You can add another line to your /tmp/ShellScript.sh on your Linux server to run something like ssh $WINHOST C:\some\windows\path\script.bat – Andrew Henle Aug 27 '18 at 12:25
  • 1
    The question is rather vague. Where is that Linux? WSL? VM? Cloud? What is that Windows? Furthermore, besides being vague, dealing purely with Windows is borderline out of topic here. – Rui F Ribeiro Aug 27 '18 at 12:46
1

Create one executable file with extension .bat in the windows and add the comment given below in file, execute this .bat file whenever you want.

Comment to copy the file from windows to linux,

pscp -pw password C:\WindowsFolder\FileToCopy $user@$ip:/tmp
  • Thanks Ebin, but how do i run this .bat file in windows WHENEVER /tmp/ShellScript.sh IS EXECUTED ON LINUX – Rahul Aug 27 '18 at 12:08
  • @Rahul but how do i run this .bat file in windows You need to put that requirement in your question, too. That's a lot different from simply copying a file. – Andrew Henle Aug 27 '18 at 12:10
  • Hi, you can automate this task in windows using Task Scheduler. – Stack EG Aug 27 '18 at 12:12
  • Hello, The issue with Task Scheduler is that, I need to decide some frequency when say every 10 minute , to copy the file.. But when /tmp/ShellScript.sh is ran, it has to do some other operations with the copied file as well. So in case of Task Scheduler if the frequency is every 10 minutes, and the /tmp/ShellScript.sh is called in the 1st minutes it has to wait for 9 minutes to get the file.Which would be an issue. – Rahul Aug 27 '18 at 12:19
  • The task scheduler works as same as Linux CRON. If the frequency time is every 10 minutes means, the task scheduler executes the script every 10 minutes. The time taken to complete the task depends on the size of the file. – Stack EG Aug 27 '18 at 12:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.