Trying to understand scripting


Author
Message
stanorchit
stanorchit
New Member
New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)
Group: Awaiting Activation
Posts: 3, Visits: 5
I've been looking at scripting recently for a specific reason.  I can make Reflect do a backup, but I'm in no way an expert with it, so am a little fuzzy on how scripting works.  My specific need right now is that I have an off-site backup set to run a full image backup the first Sunday of every month with differentials on the other days.  The differentials work fine, but the full often fails with an unexpected network error.  I found that if I start a ping to the off-site NAS that's storing these image backups, the full finishes successfully.  Without the ping it's hit or miss and often miss.  So, what I though I would do is figure a way to start a continuous ping prior to the full image backup starting and then ending the ping on completion.  Looks like scripting is the only way to do this, but I'm fuzzy on exactly how to go about this.

Based on what I'm reading, I right click the definition file and then generate the desired script.  If I'm not mistaken, I take the generated script and add my ping command(s) to the script and then run the script using Task Manager.  Am I way out in left field on this?
jphughan
jphughan
Macrium Evangelist
Macrium Evangelist (21K reputation)Macrium Evangelist (21K reputation)Macrium Evangelist (21K reputation)Macrium Evangelist (21K reputation)Macrium Evangelist (21K reputation)Macrium Evangelist (21K reputation)Macrium Evangelist (21K reputation)Macrium Evangelist (21K reputation)Macrium Evangelist (21K reputation)Macrium Evangelist (21K reputation)
Group: Forum Members
Posts: 13K, Visits: 79K
You’re definitely not way out in left field. Yes, you would have Reflect generate a script in the language of your choice and then customize it to include a ping command. As to how you run the script, Task Manager doesn’t run applications. You might have meant Task Scheduler. You can do that if you want to set up schedules manually, but the easier approach is to just generate the script and then set up schedules in Reflect. A Reflect-generated script will appear in the Scripts tab within Reflect itself, and from there you’d right-click it and click Schedule, then set up schedules as you would on a definition file. (You would want to REMOVE schedules associated with the definition file at this stage.) Reflect will handle creating the scheduled tasks, and since they will now call the script rather than directly call Reflect, those scheduled executions will do everything else in your script too, not just run Reflect.

The trick in your case is that you want to start a continuous ping and then have it continue running while Reflect runs. The typical setup for a script is that it does something and waits for that something to complete before proceeding down the rest of the script. So in your case you’d need to implement a design that doesn’t do that. If you use PowerShell, the “Start-Process” cmdlet includes a “-NoWait” parameter for exactly this sort of situation. So you could use that to call a ping and have the script continue on without waiting for that started process to exit, as it normally would. Another option specific to PowerShell is to use the “&” character, which you place immediately before the command line syntax appropriate for an external application. In a somewhat strange quirk, when an application is called using that “&” operator, PowerShell defaults to NOT waiting for it to exit. And the syntax is easier (though it’s less flexible/powerful than Start-Process). The part I’m actually not sure about is whether the continuous ping will stop after the entire script completes and exits. I can’t remember offhand and I’m not in a spot to test those two methods of calling external applications to see whether they’re forced to exit when the script wraps or whether they’d be left running indefinitely, which of course wouldn’t be ideal.
Edited 23 March 2023 5:10 PM by jphughan
stanorchit
stanorchit
New Member
New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)
Group: Awaiting Activation
Posts: 3, Visits: 5
Thank you very much for the informational response!  In a couple paragraphs you've been more helpful than all the other stuff I've read on the subject.  Much appreciated!

BTW, I did mean to say Task Scheduler.
jphughan
jphughan
Macrium Evangelist
Macrium Evangelist (21K reputation)Macrium Evangelist (21K reputation)Macrium Evangelist (21K reputation)Macrium Evangelist (21K reputation)Macrium Evangelist (21K reputation)Macrium Evangelist (21K reputation)Macrium Evangelist (21K reputation)Macrium Evangelist (21K reputation)Macrium Evangelist (21K reputation)Macrium Evangelist (21K reputation)
Group: Forum Members
Posts: 13K, Visits: 79K
Happy to help, and best of luck with your script! Smile

jphughan
jphughan
Macrium Evangelist
Macrium Evangelist (21K reputation)Macrium Evangelist (21K reputation)Macrium Evangelist (21K reputation)Macrium Evangelist (21K reputation)Macrium Evangelist (21K reputation)Macrium Evangelist (21K reputation)Macrium Evangelist (21K reputation)Macrium Evangelist (21K reputation)Macrium Evangelist (21K reputation)Macrium Evangelist (21K reputation)
Group: Forum Members
Posts: 13K, Visits: 79K
I realized I need to make a correction, and I also have another pointer that will likely solve the issue I alluded to at the end of my original post.

First, Start-Process defaults to NOT waiting for a process to exit before proceeding. There's a "-Wait" parameter when that's desired. So in your case, the default is fine. But Start-Process also has a "-PassThru" parameter that will capture details of the started process into a variable. For example, suppose you run:
$MyPing = Start-Process Notepad -PassThru

That $a variable will have properties about the started process, including its Process ID. And that variable can then later be fed to a different cmdlet called...Stop-Process!  So you can start the process before Reflect runs, and then at the end of your script write:
Stop-Process $MyPing

That will kill off that process before the script exits.

You'll likely need to use the FilePath and ArgumentList parameters of Start-Process for your purposes rather than my simplified example, but you get the idea.  There are also PowerShell-native cmdlets for pinging, and there are ways to have a ping run until another process completes, such as a Do/Until loop, but if you already know command line syntax, then the above is a perfectly reasonable method of accomplishing your goal without delving more into PowerShell.

Edited 23 March 2023 5:24 PM by jphughan
stanorchit
stanorchit
New Member
New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)
Group: Awaiting Activation
Posts: 3, Visits: 5
Again, much appreciated!
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Reading This Topic

Login

Explore
Messages
Mentions
Search