2

Okay, I know my title is a bit obscure but let me explain what I did and how I failed to accomplish what I wanted to do.

First off, security is not a my concern at this moment. Once I get it working I will implement an authentication schema to protect my setup.

I want my windows machine at home, to ftp/scp a batch file from a Linux server on the cloud (A VPS with non-root user playing ftp/scp server role) and run it as soon as it completes downloading it.

I setup a non-privileged (read as non-root) account on my vps. I generated a public/private key pair. From my windows PC, using the key-pair I was able to login to my VPS without needing a password. Using the same key-pair, I was able to download a file from my VPS onto windows machine.

I have a batch file that I scheduled to run every 3 minutes using the windows' internal task scheduler. Batch file does something like this :

scp remote-server:/home/user1/job.bat .
job.bat  > outfile.txt
scp outfile.txt user1@remote-server:/home/user1/outfile.txt
echo "rem done" > job.bat
scp job.bat user1@remote-server:/home/user1/job.bat

last two lines are there to protect against unintentional run of the same batch twice.

when it runs, if pulls the batch file from the remote-server but fails to execute it as the subsequent line and the batch file dies without going any further than the first line.

The reason I am looking for something like this is two fold. 1) when I can I access to my laptop, using VNC, but sometimes, it goes unresponsive and I have no other way to take back control but killing VNC process and restarting from the command line;m 2) when I am bandwidth limited, I'd like to run a nircmd command to take a screenshot and send it to me via scp, so that I can follow up, what's going on at home.

Can someone shed a light, why I am in this shape, i.e., why my batch file gets stuck after first line ? More importantly, how can I fix this ?

MelBurslan
  • 2,383
  • 4
  • 18
  • 26
  • Do you receive any errors? How does the batch file fail? – unclemeat Apr 23 '14 at 23:18
  • possible duplicate of [call batch script without CALL or START](http://stackoverflow.com/questions/14586164/call-batch-script-without-call-or-start) – Harry Johnston Apr 24 '14 at 00:29
  • @unclemeat : no error messages encountered – MelBurslan Apr 24 '14 at 05:38
  • @HarryJohnston : tried with running the batch file directly and using call command, but the result is the same. job.bat won't run – MelBurslan Apr 24 '14 at 05:38
  • What is inside job.bat? Your code overwrites it and then updates the batch file in vps with only the `rem done`. On next run `job.bat` will do nothing. – MC ND Apr 24 '14 at 06:15
  • @MCND job.bat changes. I can update it from anywhere on my linux VPS at any given time to make my laptop do whatever I want at that time. So, its contents are irrelevant at this point. But for testing, I wanted it to execute a benign single liner, something like `echo "testing" > c:\test.out` – MelBurslan Apr 24 '14 at 15:04
  • Is `scp` a console tool, a windows tool or a batch file? – MC ND Apr 24 '14 at 15:45
  • scp is the renamed version of putty's pscp and it is an executable, i.e., scp.exe, needless to say, it is an executable to run under windows command prompt. – MelBurslan Apr 24 '14 at 19:39
  • I'm not sure offhand if batch files with Linux end-of-line sequences will run or not. You might need to download it in text mode. – Harry Johnston Apr 24 '14 at 22:23
  • @HarryJohnston I do not create the batch files on the linux side. I use a windows PC at work, save it as job.bat and upload to my VPS, to be picked up by my home laptop. VPS is just an intemediary. – MelBurslan Apr 26 '14 at 17:57
  • 1
    Is `scp` exiting? There was another question recently about a problem caused by `pscp` hanging on exit. Perhaps try putting an echo command in the batch file instead of the call to `job.bat`, or monitor `scp.exe` using Task Manager while submitting a job.bat? – Harry Johnston Apr 26 '14 at 22:50

1 Answers1

0

Try using schtask in your batch file to dynamically create a new scheduled task and then run that task to implement your down loaded script separately at the end of this task.

look at schtasks /Create /? and schtasks /Run /?. examples should help (the freecell example will be the closest to what you want, just remove the time constraints options.)