LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-27-2018, 08:00 AM   #1
shivamnew07
LQ Newbie
 
Registered: Aug 2018
Posts: 1

Rep: Reputation: Disabled
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
 
Old 08-27-2018, 08:33 AM   #2
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: FreeBSD/Slackware-14.2+/ArcoLinux
Posts: 9,375

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
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.

Last edited by BW-userx; 08-27-2018 at 08:40 AM.
 
Old 08-27-2018, 08:34 AM   #3
rtmistler
Moderator
 
Registered: Mar 2011
Location: MA, USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 8,188
Blog Entries: 13

Rep: Reputation: 3602Reputation: 3602Reputation: 3602Reputation: 3602Reputation: 3602Reputation: 3602Reputation: 3602Reputation: 3602Reputation: 3602Reputation: 3602Reputation: 3602
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?
 
Old 08-27-2018, 09:44 AM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 22,113

Rep: Reputation: 5914Reputation: 5914Reputation: 5914Reputation: 5914Reputation: 5914Reputation: 5914Reputation: 5914Reputation: 5914Reputation: 5914Reputation: 5914Reputation: 5914
Quote:
Originally Posted by shivamnew07 View Post
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.
 
Old 08-28-2018, 08:15 AM   #5
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 19.1 MATE
Posts: 8,018
Blog Entries: 5

Rep: Reputation: 2869Reputation: 2869Reputation: 2869Reputation: 2869Reputation: 2869Reputation: 2869Reputation: 2869Reputation: 2869Reputation: 2869Reputation: 2869Reputation: 2869
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).
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
shell script - copy stdout to file kobigeu Programming 7 08-04-2013 10:43 AM
Shell script to copy all folders older than 7 days from Linux to Windows by samba blackthu80 Linux - General 4 03-17-2011 01:29 AM
Copy file from one linux server to another using shell script prateek_sahu Programming 2 08-31-2009 05:11 AM
shell script to copy lines from a file Warmduvet Programming 2 09-14-2004 10:25 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:46 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration