Script that runs itself every now and then - powershell

I work in marine systems institute. We have a buoy that sends information about the sea every few hours to a central computer in the institute. It drops it as a .txt file in a certain folder. It would be really great if I could make a script that looks into that folder every 3 hours and checks if there are any new files. If there is a new file, it should upload it to an ftp.
I have no idea where to start. Are there any suggestions what language, where to look, what to search etc.
The computer is running 24/7 and the script can easily be an executable that is active all the time. The script doesn't have to restart itself every time, it can be up and running 24/7 also.
Thanks in advance
EDIT1: My op.sys is windows

If your platform is Windows, I suggest Windows Forms Application. An IDE is available, Visual Studio - it is easy to use and has everything you need for your application. You basically need a timer object that will execute a function (checking the file) in a certain interval. 3 hours is long enough, you can even check it every 5 min.

AutoHotKey can be learned by anyone in a day, and is powerful enough to do what you describe.
A program written in a real language could do exactly what you like with full customization, robustness, portability, and maintainability, but will take quite a bit longer to make.

It might be a little over your head if you never done any programming(Forgive me if you have).
A good solution is to use FileSystemWatcher http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx. Then create a windows service to run it.
But again that takes some experience implementing.

Try using an ftp client such as smartftp which can watch the folder where the files are created, and automatically upload them.

Related

Simple yet fast deployment tool or solution for FTP-based server

I have a simple task to which some simple solution should exist yet I cannot come across one.
I have a huge file tree on computer A (development). I have the same (multiple) such file trees on a computer B (let's call it production). Computer B runs FTP and PHP, nothing much else.
I need to move the changed files from the tree on A to the tree on B but as efficiently as possible. I.e. if just one file changes, it will just transfer that one file. It would be enough to "compare" the local and remote trees using last modification dates, nothing else needed.
I tried to use the good old Ant for it but that really does not work as the FTP task is really bad one there (does not preserve modification dates on PUT and so on). What other options are there if I do not want to write the code for such a task myself? I'd expect there is some tool out there that would make a remote dir listing, download it to local computer, select only those changed files and transfer them to the destination. Do you know how I could do it? Some sort of FTP or PHP-based distributed robocopy?
EDIT: I should have added that I mean doing it on a Windows 10 computer syncing to some FTP/PHP server using command-line automated script, not GUI.
Actually I solved the issue using winscp. I managed to integrate it into ant calling it through the task and using the winscp's synchronize command. For my current folder size it is fast enough, let's see later. The FTP command in ant was not useful since it does not preserve the modification dates.

Interactive Perl programming in Sublime 3 (Ubuntu)

Practically all of the exercises in my introductory Perl book have so far required taking input, which is causing me some challenges with Sublime Text 3. I set up the custom build file from this post to run scripts directly and I've also installed REPL on top of that, but I'm still unable to provide input through the bottom console.
Is there a way to enable input for scripts built via Ctrl+B, preferably with the console messages getting a little less in the way? I'm currently stuck with having to fire up the terminal every time, which doesn't make for a particularly smooth learning experience.
This doesn't really help you with your Sublime issue, but you mention firing up a terminal every time isn't helping you learn - here's the way I do it when I'm either learning or rapidly prototyping: Simply setup a folder on your local machine, called sync or something. Create a similar folder on your terminal server.
Now use an app (I use WinSCP and use Keep Remote Directory Up To Date setting) to sync. Every time you press save in your text editor, the new script is automatically uploaded to your terminal server, you can now just alt+tab to your terminal and run the script. Works very well for me and enabled really easy rapid prototyping.

Script to open two applications on start up and snap them with one being 80% screen and the other being 20% in Windows 8.1 Desktop

I am not a programmer rather a designer but have been trying to write a .bat file for weeks to have two applications, which I specify, open automatically and snap to a scale of 80% left hand side and 20% for the second app on the right hand side. I have looked into multiple options without having any luck. Currently, I can create a script to open two files and automate key strokes to have them snap 50-50%, however I really need the 80-20% screen real estate. Any chance anyone would be able to help me out?
I am currently trying to use PowerShell with WASP (http://wasp.codeplex.com/) but scripting in this is beyond my knowledge. Many thanks!
You should try UI Automation PowerShell Extensions.
It supports testing for Metro Apps. The initial setup is a bit tedious (as described in the link provided) but it is well worth it. You have a UI action recording tool UIAutomationSpy which records all of your actions and generates corresponding PowerShell scripts. You can then run these scripts using the UIARunner tool.
With respect to the current problem, you could simulate the steps for snapping the apps using the recorder. You could then create a task which runs a batch file (executing the concerned script) on startup.

Precompiled applescript service?

I have created an automator service for my finder which runs an applescript. I will have to use this service incredibly often. I have noticed that after running the service, there is a very large (about ten second) delay before I receive any popups from the script. This is far too long. I am almost positive this delay comes form automator compiling my script every time it is run....
So, I have a question -- is there a way to pre-compile an applescript, then install that applescript as a finder service? Going through automator was the simplest way I could think of to install my script as a service, but if there is a better way -- particularly one that pre compiles my applescript, that would be great.
I'm not sure if it's a "compiled" issue. I see long delays sometimes too, even with compiled scripts. Automator actions are run by the "automator runner" application and applescripts are run by the "applescript runner" application (unless they're created as stand-alone applications). I notice sometimes that during the first launch that it takes extra time but on subsequent launches it acts faster... maybe because the runner applications are up and running during subsequent runs. So I'm more likely to believe it's something in the runner applications rather than the script itself.
However you can run a "compiled" script if you wish. Just create the script as a separate file. Then in the applescript portion of your automator action use this...
run script file "path:to:script.scpt".
With that being said, you can even create the applescript as an application and then run that from automator...
tell application "MyApplescript" to activate
Maybe one of those solutions will help speed it up for you. If you do achieve a speedup, please let us know.

Making and Interfacing with Custom Services

I've been searching for this for awhile now, and I am not sure if I am just not using the correct search terms or if the answer is really that hard to find.
What I am trying to do is to create a new Windows service for a game server from a batch file, and then have a task run another batch file every 30 minutes or more that would run two commands on the game server's command line and do some file work.
Specifically, I am running a Minecraft server using Bukkit for a gaming community I help run, and I want to make sure that the thing is always up unless I specifically tell it to stop (like a service). Bukkit is run directly from a batch file and has it's own command line thing running on it.
I am told that you CAN run this type of thing as a service, but the command line will be hidden from view and/or interaction. This is the second part of my query. I have a handy little backup.bat file that copies all the world files and userdata files into a backup directory, 7zips it, and deletes the directory. The only thing is, is that Minecraft likes to always have the worlds' region files open and writing at all times, meaning that it could cause map corruption if I just run it straight off. To compensate, I need to run the command "save-off" on the server to disable the file hooks temporarily, run the backup, and as soon as it finishes, run "save-on" so that the game can continue without lost data.
What I would like to know about this second one is, is it possible to interface with the game service through a batch file, or do I need to create an application to do that? If the latter, how exactly does one go about doing that? I have moderate C++ knowledge (up through my second OO-C++ course in college), and can possibly learn another language if absolutely necessary.
So, in short, two questions:
1. Is it possible to, and how to run a BAT file as a Windows Service?
2. How to interface with said service via BAT files, and if not possible, what kind of application do I need to write (redirection to or writing a tutorial works for me).
Thank you in advance for any and all help!
Old question, user account doesn't seem active on SO anymore, but hey, if you stumble upon this because you have a similar problem:
Since we are speaking about a Bukkit Minecraft server, turn to the "Essentials" plugin for Bukkit.
It now includes a Backup function that does exactly what the OP asks for, namely stop the save so the files can be manipulated without corruption, launch a script, then starts again.
The script can be a backup one (examples provided in the linked page) but can be used to run any operation on the world's files.