Run URL in Background as Service - service

I'm looking for a way to create a file that runs a specific URL in the background at a specific time. I'll run the service on a timer, and the user won't be logged in. Basically, the server restarts every day, and I want to run a service at 6AM that just goes to a URL (which will automatically complete some tasks). I was thinking batch file or even AHK..but is there a simple way to do this?

My comment:
You just want to open a URL that itself start some tasks? Tried iexplore.exe "your url" as a windows task?
Add:
If this don't work you can just write a small script in vbscript which you fire as task sheduler task.
This script just opens your url:
Dim l_lTimeoutResolve, l_lTimeoutConnect, l_lTimeoutSend, l_lTimeoutReceive, l_sUrl
l_lTimeoutResolve = 5000
l_lTimeoutConnect = 60000
l_lTimeoutSend = 10000
l_lTimeoutReceive = 10000
l_sUrl = "http://yoururl"
'Dim l_sRequestText : l_sRequestText = "stuff you want to send"
Dim l_oXML : Set l_oXML = CreateObject("MSXML2.ServerXMLHTTP")
l_oXML.setTimeouts l_lTimeoutResolve, l_lTimeoutConnect, l_lTimeoutSend, l_lTimeoutReceive
l_oXML.open "POST", l_sUrl, False
l_oXML.setRequestHeader "Content-Type", "text/xml"
' you can post data and als get a result then to write to a logfile e.g.
'l_oXML.send l_sRequestText
'l_sResponseText = l_oXML.responseText
Pro's prolly post that you better do this as powershell .NET script instead, but I never get used to that now. If you want todo coding in .NET instead (vbscript is a bit tricky to setup security on windows 2008 servers) then better write a simple .exe file in .NET that you just start.

Wrap it in a batch file and create a Windows scheduled tasks to execute it?
edit: massive assumption that you are running in windows... but you get the gist

Related

Dash - Run callback in server side

Good morning,
I have created a callback in Dash that makes the job of a scheduler.
Every 10 minutes (with the help of an interval component), my callback is running to fetch the data from a server and to update the csv file that I use in my app.
The problem is that my callback is called only when I have the webpage opened. As soon as I close the page, the scheduler stops and runs again when I open the page again.
As the data process of updating data can be long sometimes, I want the scheduler to always run and fetch the data every 10 minutes.
I assume that a callback is a client side process right? So how can I make it run in server side?
Thank you,
Dash is probably not the right solution for this. I think it would make more sense to set up the Python code you need for this job in a simple .py script file, and set a cron job to run that script every 10 min.
Thank you #coralvanda for the help.
I finally did a python script in my container A that calls the container B every 10 minutes. The container B is fetching the data.
It makes the job.
import schedule
import time
import docker
def worker_restart():
client = docker.from_env()
container = client.containers.get('container_worker')
container.restart()
schedule.every(10).minutes.do(worker_restart)
while True:
schedule.run_pending()
time.sleep(1)

How to setup email notification alert in IIS 6.0 web server when a file is uploaded via any ftp client?

I'm trying to setup email notification alerts in IIS 6 when a file is uploaded via any FTP client. Does anyone know how to accomplish this?
I found something similar but don't understand how to implement it:
http://forums.iis.net/t/1196793.aspx/1?How+to+add+email+notification+service+in+IIS+6+0+when+a+file+is+uploaded+via+FTP+
Does anyone have any insight on this?
function countFolders(strPath)
dim objShell
dim objFolder
dim folderCount
set objShell = CreateObject("shell.application")
set objFolder = objShell.NameSpace(strPath)
if (not objFolder is nothing) then
dim objFolderItems
set objFolderItems = objFolder.Items
if (not objFolderItems Is Nothing) then
folderCount=objFolderItems.Count
end if
set objFolderItem = nothing
end if
set objFolder = nothing
set objShell = nothing
countFolders=folderCount
end function
The post you're citing basically suggests this:
Create a script which checks the number of files in a folder(or folders) (as you have).
Create a running total of number of files. Maybe save this value into a database or another txt file.
If the number of files differs from the last time the check was ran, then send the email.
It suggests using scheduled tasks. This means an email is sent exactly when the FTP is updated only when you script is executed. The good thing about Windows Tasks is you can run it as often as you like. So, assuming you don't need an immediate notification, you could set your script to run once a minute, once every 10 minutes or similar.
The problem with the above though is if people are removing files as well, you'll probably get missed notifications. EG assuming you don't want to be notified when a file is removed, this means if my current count of files is 10, 3 and removed and 1 added, this means next time the script runs I have 8 files. There is no way to know that files had been removed/re-added. In this case, you want to take a notice of the file-names and paths, make a note of them so you can compare existing paths to previous paths!
I have just completed a very similar task, but I had an extra luxury. I wrote the FTP client which had to be installed on all clients machines to send files to my FTP. This meant, in my FTP program, I had an extra bit of code which did: OnUploadCompleted -> Send Notofication Email
You could create a service which uses the FileSystemWatcher.
The FileSystemWatcher listens to files system change notifications. In the provided link is a good example how to use the class.

Stopping cURL transfer in Matlab

I wrote a Matlab GUI that's used to automate the transfer of data to and from an ftp server, which is done using cURL, e.g.
str = sprintf(' "%s" -O "ftp://%s:%s#%s" -Q "CWD %s%s/" ', ...
handles.curl, username, password, ...
strcat(ftpname, d{1}), '/users/', username);
% Try to transfer file until successful (s=0)
s = 1;
while s ~= 0
s = dos(str);
end
Typically this GUI will be ran on a slow network, so transferring a 50 MB file could take up to 30 minutes or longer.
What I'd like to know is that if a "Stop" button is pressed on the GUI while it's in the middle of a data transfer, is there a way in cURL to cancel that transfer, or do I need to let it complete?
You could setup a timer object with a callback to check if the user hit the cancel button and then try to kill the process via a different dos command. The only thing I don't like is the whole external process cURL, it may be difficult to know you for sure got the right process. Is there a reason you didn't try any of the Matlab transfer commands?

perl: Launch process with system(), then check if its running under a specific display number

I have a locked down "kiosk" terminal server.
This terminal server has a perl script as its .Xsession, and launches a Tk interface. When that Tk interface is done, the perl script launches "process2" and lets the user interact with "process2" (which is a graphical application).
If a user tampers with "process2", and make it crash, the user might be able to access the underlying desktop, therefore I would want to check if "process2" is running, and if "process2" is not running on $display, I would want to just execute logout (which would logout the display the perl script is currently running as).
Since the system is running 10 instances of "process2" to 10 different users simultanuosly, I cant just check if "process2" is running on the system with "ps" or someting like that. I need to check if "process2" is running under that specific display $display.
Note that all 10 users log on as the same username in all sessions, so I cannot check all processes run by a specific user, that would return all 10 instances too.
Like:
system("process2 &");
while(1) {
sleep(1);
if (is_it_running("process2", $display) == false) {
system("logout &");
}
}
Its the function "is_it_running" that I need to get to know how it should look.
$display can either contain the raw display number, like this: ":1.0", or it can contain the display number parsed out, like this: "1".
If you use fork and exec instead of system("...&"), you can store the Process IDs of your child processes and more directly check their status. See also perlipc.
Why not just run process2 in the foreground? Then your perl script won't get control back until it's done executing, at which point it can exit:
system("process2");
system("logout");
Of course, if that's the entire script, maybe a bash script would make more sense.
I solved it after many attempts.
Did a piped open
$pidofcall = open(HANDLE, "process2|");
Then I did whatever I did need to do, and I made the server send a signal to me if it loses connection with process2. If I did need to bang out, I simply did a "goto killprocess;" Then I simply had:
killprocess:
kill(9,$pidofcall);
close(HANDLE);
$mw->destroy;
system("logout");

Creating batch jobs in PowerShell

Imagine a DOS style .cmd file which is used to launch interdependent windowed applications in the right order.
Example:
1) Launch a server application by calling an exe with parameters.
2) Wait for the server to become initialized (or a fixed amount of time).
3) Launch client application by calling an exe with parameters.
What is the simplest way of accomplishing this kind of batch job in PowerShell?
Remember that PowerShell can access .Net objects. The Start-Sleep as suggested by Blair Conrad can be replaced by a call to WaitForInputIdle of the server process so you know when the server is ready before starting the client.
$sp = get-process server-application
$sp.WaitForInputIdle()
You could also use Process.Start to start the process and have it return the exact Process. Then you don't need the get-process.
$sp = [diagnostics.process]::start("server-application", "params")
$sp.WaitForInputIdle()
$cp = [diagnostics.process]::start("client-application", "params")
#Lars Truijens suggested
Remember that PowerShell can access
.Net objects. The Start-Sleep as
suggested by Blair Conrad can be
replaced by a call to WaitForInputIdle
of the server process so you know when
the server is ready before starting
the client.
This is more elegant than sleeping for a fixed (or supplied via parameter) amount of time. However,
WaitForInputIdle
applies only to processes with a user
interface and, therefore, a message
loop.
so this may not work, depending on the characteristics of launch-server-application. However, as Lars pointed out to me, the question referred to a windowed application (which I missed when I read the question), so his solution is probably best.
To wait 10 seconds between launching the applications, try
launch-server-application serverparam1 serverparam2 ...
Start-Sleep -s 10
launch-client-application clientparam1 clientparam2 clientparam3 ...
If you want to create a script and have the arguments passed in, create a file called runlinkedapps.ps1 (or whatever) with these contents:
launch-server-application $args[0] $args[1]
Start-Sleep -s 10
launch-client-application $args[2] $args[3] $args[4]
Or however you choose to distribute the server and client parameters on the line you use to run runlinkedapps.ps1. If you want, you could even pass in the delay here, instead of hardcoding 10.
Remember, your .ps1 file need to be on your Path, or you'll have to specify its location when you run it. (Oh, and I've assumed that launch-server-application and launch-client-application are on your Path - if not, you'll need to specify the full path to them as well.)