LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Copy file from Windows to Linux WHEN A SHELL SCRIPT IS EXECUTED (https://www.linuxquestions.org/questions/linux-newbie-8/copy-file-from-windows-to-linux-when-a-shell-script-is-executed-4175637219/)

shivamnew07 08-27-2018 07:00 AM

Copy file from Windows to Linux WHEN A SHELL SCRIPT IS EXECUTED
 
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

BW-userx 08-27-2018 07:33 AM

write the steps. I think you're saying.
1. Linux script is on Linux system in /tmp, when executed write same script to a windows partition directory whenever it is executed?

if you are in Linux and want to access a windows directory you need to get and use the Linux classification for that drive and folder absolute path then just add the code into the script that will place a copy of whatever file you want to put into it. if you are creating a new empty file then put the code in the script to create a new (empty) file, touch is a good app to use for this.

things to consider. Is the accessed via IP address, or on the same box, is the partition mounted prior to execution of script, if no, then add code to mount drive partition, or gain access to the partition/directory so access can be gained for further exploitation.

example of Windows Partition on same Linux box
Code:

#!/bin/bash

touch /run/media/userx/01D285E8BED961F0/Users/userx/FileFromLinuxBox
echo "written stuff added" >> /run/media/userx/01D285E8BED961F0/Users/userx/FileFromLinuxBox

executed from CLI in Linux file added and written to via that code.

the shebang and directive is not needed to execute that code in order for it to work.

rtmistler 08-27-2018 07:34 AM

Code a cp command into your script.

I'm assuming you note that the location for the Windows file to copy is different under Linux?

TB0ne 08-27-2018 08:44 AM

Quote:

Originally Posted by shivamnew07 (Post 5896497)
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

Your post makes no sense. You say:
You have a shell script in /tmp (?? NOT a good place for a shell script, generally), that you wrote. But can't write one additional line to copy a file? And you then say that the shell-script you mentioned is **EMPTY BY DEFAULT***???? How do you execute an empty file, exactly?

Basic logic: if you want to copy a file from another machine, you have to connect to it. You don't say if this Windows system has a shared folder, is accessible via FTP/SSH/whatever, but get your connection method first. From there, basic logic continues. If it's a shared folder, you connect to it via smbclient, or mount it via cifs, and copy the file like you would any other file, since the Windows share is mounted on Linux as just another drive.

Contact your administrator/programmer for help.

hydrurga 08-28-2018 07:15 AM

In addition to the other comments, don't think about operating systems (Linux, Windows), think about filesystems. As others have said, all you need to do is issue a command to copy a file from one filesystem to another, ensuring that both filesystems are accessible to the system that issues the command (the origin filesystem with at least read access, the destination filesystem with at least write access).


All times are GMT -5. The time now is 06:21 AM.