How to transfer file from Windows to Linux server, process it with shell script, and download results back - linux

I normally do this using WinSCP: I transfer a .tex file from my local Windows machine to a Linux server. I run a script (on the server) to pdflatex the file for me. And I use WinSCP again to copy the output .pdf to my local Windows machine again. I would like to automate the copying process in my script.
So the first step is to copy file.tex from C:\Doc...\source to ~/Documents. I think I need to use the scp command, but the server sees my local machine as a remote machine. That's why I'm confused as to how the first directory needs to be specified:
$scp C:\Doc...\source\file.tex ~/Documents
doesn't work because the server doesn't know how to talk to my local machine. I have the same issue for the scp command I need to use to copy file.pdf back to my local Windows machine.
Can anybody help me with these two scp commands?
Thanks in advance!

You can use WinSCP in scripting mode. It (naturally) supports the upload/download. But it can also execute the shell script on the server with call command (with some limitations, which should not matter in your simple case):
winscp.com /log=winscp.log /command ^
"open scp://username:password#example.com/" ^
"cd /remote/path" ^
"put my.tex" ^
"call pdflatex ..." ^
"get my.pdf" ^
"exit"
(I'm the author of WinSCP)

Related

xcopy, net use not working from Linux machine

I am trying to copy files from windows server to network shared folder via VPN . Here is my code from batch file. This is working fine without any issues.
net use \\servername\test_folder password /user:user_name
xcopy C:\Apache\htdocs\arul\xias \\servername\\test_folder
But when I try to run this from Linux machine it is not working. This Linux machine is also connected to network shared folder via VPN. So I tried below on Linux machine in .sh file.
net use \\servername\test_folder password /user:user_name
cp C:\Apache\htdocs\arul\xias \\servername\\test_folder
I am getting errors like net command is not found and cp: -r not specified;
How to achieve this from Linux machine ?
The commands "net use" and "xcopy" are specific to Windows and will newer work on linux.
You should use some smb specific commands instead (of course, the kernel must support them).

Executing a Shell Script on Remote Server :: Gives sqlplus: command not found

I have two servers Server A which has a shell script - 'Process_Backup.sh'.
I executed this script on server A - './Process_Backup.sh' and it executed fine. Basically this script connects to my oracle database on Server A and executes a procedure.
What I need to do is execute the script 'Process_Backup.sh' on server A from a different Server B.
I tried following command from Server B
ssh test#server1.xxx.com "cd Scripts/Shell; ./Process_Backup.sh"
But I am getting following error-
line 49: sqlplus: command not found
I have all the software installed on server A so not sure why am I getting this error. I am new to linux environment. I have gone through most of the question posted here but mine seems to be a different case.
Any help is appreciated
Oracle installs a file oraenv that sets some environment variables including the PATH where commands like sqlplus are. That file is included when you start your login shell, the commands to do that were probably created by the installer.
Use
ssh test#server1.xxx.com "source /path/to/oraenv; cd Scripts/Shell; ./Process_Backup.sh"
The file oraenv is probably somewhere below /usr/local.

How To Run a Script in WinSCP

I am using winSCP GUI to connect to linux terminal and then copy the files and other stuff.
Now i have some scripts on the UNIX server,I am connected but how to run the script from the Win SCP.
what basically is needed is
sh scriptname.sh through the WinSCP.Please let me know if anyone else found out how to do that.AS loging into putty and running the command is time taking for me.
WinSCP Custom Command option tried to click on Execute,but the error pops up like no such directory.
Tried google but to the point information is not coming up.
Try this
sh "!"
OR
First of all executing commands from WinSCP can be tricky and if you are able to run few commands also,there are restrictions which you can not do fro WinSCP and should have to ultimately take help of PUTTY.
Here is the link Integrate WinSCP with Putty which will help you integrate your WinSCP to Putty,so that when you open any server through WinSCP putty will automatically connect without even asking for the password.And then you can run you command,hope that wound be of any trouble to you.
Remember you can store the connection details in WinSCP and in just one click it will connect to the server on SCP and also on Putty.
You can define your own custom command by right-clicking, selecting Custom commands and selecting Customize. Then click "Add", enter a description, e.g. Run and specifying a custom command. Try sh "!" to start with - that works ok for me, if you still get errors post your output back here. The quotes are important - only the exclamation should be quoted.
Right click the script > Custom Commands > Execute
Hope this helps.
To execute an ad-hoc shell command in WinSCP, use the Console window:
To execute the shell script selected in a file panel, create a custom command like:
sh "!"
This is actually, what the pre-defined custom command Execute (almost) does.
I'm aware that you claim that this does not work. But it should work in general. If you are having problems, please tell us details (exact error message, screenshot, anything)
You can have WinSCP open PuTTY terminal client and execute the commands there.
With some setup you can even open the PuTTY in the same directory as you have opened in WinSCP file panel.
Particularly for long-running commands/scripts, you can create a local custom command that runs the script via Plink:
"C:\Program Files (x86)\PuTTY\plink.exe" -ssh !U#!# "!/!"
Check the Use remote files option. Do not forget to select the Local command.
You can also pass the command to PuTTY to using similar method as used for Opening PuTTY in the same directory.

psexec error code -1073740771

I'm trying to open up a Unity3D game.exe that is on a remote computer through my main desktop. I had tried to do this through a batch file, but was advised to try PsExec in its place.
So far, I've brought the Psexec program into my game.exe folder. I run the command line required to open the program and the window opens up for a fraction of a second before closing down due to an error. The error code it gives is: -1073740771.
I tried googling what this error actually is but I can't find anything. Does anyone know what this error relates to?
The command line I type is as follows:
psexec \\OtherComputer -i C:\Administrator\Users\Desktop\TargetFolder\Target.exe
I even tried the above line with -d after the -i, quotes around the C:... but it all results in the same thing.
PSExec wont know about other game resources that live without side the EXE. It will simply copy game.exe to the remote machine and execute it.
Try deleting or renaming the resource folder and running it on your local machine - it should do the same thing as its doing on the remote machine.
You cant do what you want with psexec unless the entire application is self contained within one single .exe file.
You may be able to manually copy the resource folders if you have admin access to the other machines and administrative shares are enabled, then execute with psexec using the -w option:
Copy the files to \\OtherComputer\C$\MyGame
Run psexec \\OtherComputer -w C:\MyGame -i C:\Administrator\Users\Desktop\TargetFolder\Target.exe
Might work ;o)
Use the -h parameter to elevate the permissions.

How to create a script on windows which could run ssh command on a remote linux

I just want to create a auto script on windows which could do run some comand through ssh on a reomote linux.
I know it's easy to write script between linux(ssh client) and linux(ssh server).
But I do not know how to create a script on windows(ssh client) to remote connect to linux(ssh server)
If it's just some command lines you want to run then plink will be enough IMHO..
Goodluck.
Most popular languages have ssh libraries you can use, pick a language you are familiar with and then go library hunting.
I've used these with success:
C - libssh
.NET - SharpSSH
Python - Paramiko or Really Simple SSH or Fabric
use plink (get it from putty website) and a bat file format like this:
Plink.exe -ssh -pw %password5 %linuxuser%#%servver% /path/to/script/script.sh
Save em in same folder -> run your awesome masterpiece
One way is to install Cygwin and use a shell script to run ssh commands. You can launch this script by running sh.exe with arguments.
This way, you can do the job with the same Linux tools (sh and OpenSSH) that you are already familiar with.

Resources