write python code in one computer and running it on another automatically - python

I have the following situation.
I want to write python code in my Laptop that will take more than 24 hours to run.I am using UBUNTU 12.04 lts.
Is it possible so that I write python code in my laptop, automatically send it to some remote desktop, run there and send the output result to my laptop when done?
one way suggested to me is to use openssh.
But I want to do this in the following way----
Write and Debug Python Code in my laptop.(Solved)
email the code as attachment to ****#gmail.com(Solved)
Other python program in the desktop will automatically download and run the source code(Unsolved)
and email the output file back to my gmail id.(Solved)
what is the python code to download the attachment from the latest email from a specific gmail folder?

If your remote system is windows, a good option would be to use PsExec from SysInternals.
Ex. If your script is long_running.py a typical usage would be
PsExec \\remote-server -c long_running.py
If your remote system is *nix, and your local system is Windows, you can use ssh for remote execution via Plink (part of PuTTY).
plink remote-server#user -m long_running.py
Finally if both remote and local machine are *nix systems, you can simply use ssh
ssh remote-server#user 'bash -s' < long_running.py
Note This is just some possible options, but the idea is remote execution is possible either via ssh or a similar option (like PsExec) for Windows

If both systems are running *nix, you can easily do all your dev work and debugging locally, while still executing remotely:
One time set up:
Mount a folder from the remote box locally
On your laptop, save your project/script to that (now local) folder, or set the mounted folder as your project's save path in your IDE.
Publishing:
Do work
Click the save button
Executing:
SSH into the remote box and open a new screen
Navigate to the folder you'd previously mounted, and run your script.
You can then safely detach and close ssh if necessary (ctrl+a d), and re-attach later:
3a. screen -ls (to find the screen name)
3b. screen -x screen_name
The advantage of this solution is that if you've got an ongoing project requiring frequent edits/changes, you can do all your dev work/debugging locally, and the only work required to "publish" is clicking the save button, starting the screen, and running.

Related

Execute a script when alarm is triggered in McAfee ESM 11.5.X

I want to execute a Python script when creating an alarm (McAfee ESM Virtual machine - ESM 11.5.4 20220106). When creating an alarm, I configured "Execute remote command". Alarm is being triggered but script isn't getting executed. I tried as shown in the image below but it didn't work.
I found a way to this. You can't execute a script situated in the ESM (In the image above, the IP is of ESM machine itself). You have to spin another VM with the required ports open. Refer image in the question.. So, the IP address, credentials and script path has to be of the VM.
Basically you should have a command server for script execution and others.
Also, in my case I noted that only bash scripts were getting executed. Python scripts failed. So, the work around to that could be that you mention bash script in ESM and inside bash script you write a command to execute the python scripts that has to be executed.
Hope it helps!

Raspberry Pi SimpleHTTPServer startup on boot with chromium launch

I am currently trying to get a display window I made in html setup to work immediately when the pi is plugged in, without needing to type in command prompt codes everytime it is shutdown
The 3 commands I need are:
cd ~/Desktop/screen
python -m SimpleHTTPServer
chromium-browser --start-fullscreen http://localhost:8000
The first one directs to the location the files are in (index.html
and its supporters)
The second one starts the server in that location
The third one launches chrome in f11 mode, filling the entire screen and connected to the default location of SimpleHTTPServer
I have implemented this directly in the terminal and it works, but even just sticking this in a .sh file does not operate, let alone hooking the .sh into the backend. I was following this instructable: https://www.instructables.com/id/Raspberry-Pi-Launch-Python-script-on-startup/
The thing is only serving static content, and people only will access it with their eyes looking at the screen. (If chrome allowed access to local files, it would literally be opening an html document). I tried setting up a full server, but between me being new to linux, pi, and servers, that did not get far.
Any help getting this set up will be greatly appreciated.
I got it working. There needs to be an '&' at the end of SimpleHTTPServer
python -m SimpleHTTPServer &
Also, chromium cannot be booted at this point, as the screen has not been initialized by the pi yet (from what I read). Instead, go into chromium's settings and change the startup page to "localhost:8000"
final .sh file
#!/bin/sh
#!launcher.sh
#!navigate to home directory, then to here
#!launch simple python server
#!open chrome at localhost:8000
cd /
cd /home/pi/Desktop/screen
python -m SimpleHTTPServer &
cd /
you will need to open chrome manually, but upon opening, it will be on the correct page.
The rest of the instructions at https://www.instructables.com/id/Raspberry-Pi-Launch-Python-script-on-startup/ worked

Run a script located on remote server using python

I have a python script located on a remote server with SSH enabled. That script displays a lot of debug messages displayed while executing. I want to trigger this script using another python script which is on my local system and depending on the output of the earlier script, I want to proceed further. While doing all this, I want the display messages on the remote server to be displayed on my local system as well. Basically, I want to view whatever output is thrown by the remote script during the course of the script, on my local system. I am able to trigger the script using paramiko but I am neither able to check whether the script on the remote server is running nor am I able to view it's output. Is there any way to do it? Already tried conn.recv(65535) but to no avail.
In my experience I found python fabric module easier than using paramiko. If you want to execute local script on remote machine using fabric. You just need to upload them using put() and then call run() api.
http://docs.fabfile.org/en/1.14/api/core/operations.html#fabric.operations.put

run python script in DigitalOcean

I'm having troubles to run a python script in DigitalOcean.
I have two doubts.
How to upload the scripy.py to DigitalOcean droplet.
How to run the script.
I'm able to access to the console, but further that I don't know what to do and i can't find any specific information on internet.
I'm running a Ubuntu 14.4 Droplet through web.
Ok first, in order to upload any file to your droplet you can user the command scp
scp foobar.txt your_username#remotehost.edu:/some/remote/directory
Here is a related question that shows you how to use scp from Windows.
Then in the console setup in the remote host check if you can run the command python. If you do not have it, just follow the steps in the documentation and you will have python running inside your remote machine.
If you put a Python script on the server and ssh in, you can run it from the command line. For instance,
python yourFantasticScript.py
If you want a level of automation to triggering the script to run, you will need to learn more about automation scheduling and server technologies.

jenkins wouldn't execute python script correctly

I set up a job that want to execute an action that open the local browser. I write it use the python script:
import webbrowser
if __name__=="__main__":
webbrowser.open("http://www.example.com")
Then,i click Build now button on jenkins dashboard, it can execute successful and show successful as a result at last. But nothing happen for browser.It's very wierd that other python script could execute correctly, I have no idea why?
Addition:This jenkins(Jenkins ver. 1.524) is installed on my laptop and my laptop's OS is Win7, i start jenkins as a Windows Service. Do u have any idea?
If you are running Jenkins as a Windows service, by default it runs as user Local System. Did you check the box titled "Allow service to interact with desktop"?. If that does not help you may have to set the service to log on as an actual user, instead of Local System. This is a common problem with running any process with a GUI from Jenkins.

Categories

Resources