Jump to content
Sign in to follow this  
michaelslamet

Make sure command doesn't get executed more than one time

Recommended Posts

michaelslamet

Ok, I admit I haven't coded anything yet, still try to grab the main idea.

I will create a script that will run silently through scheduler on many PCs.
This script will connect to MySQL server on the cloud, reading command for it to execute.

Let say from the cloud, it get 5 lines commands to execute.
So what it's going to do is of course execute them one by one.

These commands/lines can be a instruction to delete files, folders, download files, etc.

The problem is these commands on the cloud will someday grow into a big list,
can be hundreds of lines. It will grow into a big list because new command/lines will
added regulary but none will be deleted. We cant delete those past command/lines on the list
because maybe some PCs still have not a change to execute them, right?
Some PCs maybe powered-off for let say a month, and we cant know for sure when it will powered-on.

My questions are:

1. I need to find a way to bypass those lines/commands that are already executed by particular PCs.

My idea is when commands sucessfully executed, it will write @ComputerName and which commands/lines
it sucessfully run to the MySQL table on the cloud. This script will check this table on startup.

Is this a good approach?

2. What if the command MySQL table compromised and the commmand changed to something like "del c:windows*.*"
The only way to prevent this is to make sure the MySQL server never compromised, isn't it? :*

Thank you for reading and posting your thought to this thread :thumbsup:

Share this post


Link to post
Share on other sites
water

What you describe is what a good software distribution system does.

IIRC a user has already written somthing like this in AutoIt. Search the forum and I'm sure you will find the tool.

Split your commands into packets and store the number of the last installed packet on the PC. So you can make sure commands won't be exectued multiple times.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
michaelslamet

Thank you, water :)

What keyword should I use? I found some post about SCCM. Dont really know what is SCCM, need to googling to findout.

Is this you mean?

About "split your commands into packets", you mean something like store the command number in the MySQL server like:

command1=

command2=

command3=

And then save the last command information on each PC in the ini file, something like:

[global]

LastCommandExecuted=command3

Like that?

Share this post


Link to post
Share on other sites
water

I would search for deployment, distribution, software etc. or any combination of this words.

At the moment I can't remember where I've seen this project but I will post a link as soon as I can remember.

And then save the last command information on each PC in the ini file

Correct.

This makes sure that, if the PC is installed from scratch, all actions will again be applied.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
water

Got it!

It's a project on the German AutoIt forum named Hephaistos.

I've never used it myself so I don't know if it fits your needs. But you could get some ideas from the code at least.

Link: http://www.autoit.de/index.php?page=Thread&threadID=17111


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
michaelslamet

Thank you, thank you Water, for the link and the idea of using INI file :)

Talking about INI file, if our INI file contain something like this:

[global]

1=blablbla1

2=blablbla2

3=blablbla3

4=blablbla4

5=blablbla5

How can we loop and read all of those entries? It's not limited to 5 lines, so we can not define "5" in advance.

Do we need use function like _FileCountLines() and Eval() or there is a special function for handle this in INI file?

Share this post


Link to post
Share on other sites
TheSaint

Check out IniReadSection  and the number of elements returned $array[0][0]

If however, you have other keys under that section, that aren't a number, then you will need to strip them out of the result count ... maybe with StringIsDigit and $total = $total - 1 or somesuch.

Or just use something like a While ... Wend loop which checks for all keys and uses a required comparison, builds a list, then exits the loop.


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites
michaelslamet

Thank you, TheSaint, I'm now perfectly understand how to handle that :thumbsup:

I plan to have a format like this:

[global]
1=1|*|I|WIN_XP|I|copy %temp%downloadabc.txt %windir%system32
2=1|PC1|E|*|I|del %windir%file-to-delete.txt
3=1|*|I|*|I|wget http://www.mywebsite.com/myfolder/myfile.txt -O c: --user-agent=MyUserAgent
 

Each option is separated by pipe (|) sign.

1st option is enable (1) or disable (0)

2nd option is computer name (* = all PCs)

3rd option is exclude (E) or Include (I) 2nd option

4th option is operating system

5th option is exclude (E) or Include (I) the 4th option

So this like:

1=1|*|I|WIN_XP|I|copy %temp%downloadabc.txt %windir%system32

Will be translated as:

execute command "copy %temp%downloadabc.txt %windir%system32" on all PCs that run WIN_XP. This command is enable.

second line:

2=1|PC1|E|*|I|del %windir%file-to-delete.txt

Will be translated as:

execute command "del %windir%file-to-delete.txt" on all PCs EXCEPT PC that named "PC1", no matter what is the OS. This command is enable.

What I need to make it more powerful?

Please advice.

Thank you very much :thumbsup:

Share this post


Link to post
Share on other sites
water

Be aware that there is a size limit of 32K IniReadSection can process.

So I would store the list of commands to be executed in a database or a flat file. Only the information about the last command executed on every PC could be stored in a INI file.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
michaelslamet

Actually, I'm not going to use the default IniReadSection, but I'm going to use >AZJIO's IniVirtual because the config and commands will be stored in the MySQL server on the cloud.

So I'm going to read those commands on MySQL server, store them at a variable and then read it using IniVirtual.

What do you think?

Share this post


Link to post
Share on other sites
water

IniVirtual only seems to be useful if you work with ini files.

In your case reading the MySQL database should store the resulting records in an array.

Lets say you retrieved 45 records from the MySQL database, the local ini file contains 23 as the number of the last processed command then your script should start processing the array from entry 23 onwards.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
michaelslamet

Aha, I plan to store them on MySQL table in 1 big text field with only 1 record.

So there is only 1 record on the table which is store the commands to be executed in the INI file format:

[sectionname]

key=value

anotherkey=anothervalue

I will read them, store them in a variable and read them using IniVirtual.

How many chars a variable can hold? 64K ?

Any ideas what features this script should have?

Thank you very much, water :)

Share this post


Link to post
Share on other sites
water

A few questions:

Why do you want to store the commands in a MySQL database? You have only 1 record with only a signle field. That's quite an overhead.

If you have a database why store the content in INI file format?

I would do it this way:

Store the commands in a flat file. One command per line.

Use FileReadToArray to get all the commands into an array.

Read the number of the last processed command from a local file (could be an fIni file)

Loop through the array starting with the first unprocessed command


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
michaelslamet

A few questions:

Why do you want to store the commands in a MySQL database? You have only 1 record with only a signle field. That's quite an overhead.

If you have a database why store the content in INI file format?

I would do it this way:

Store the commands in a flat file. One command per line.

Use FileReadToArray to get all the commands into an array.

Read the number of the last processed command from a local file (could be an fIni file)

Loop through the array starting with the first unprocessed command

 

Because I usually over thinking :idiot:

Store the commands in a flat file seems the right way to do it, thanks!

For Sure I will come again with more questions :muttley:

Share this post


Link to post
Share on other sites
water

I will be glad to help you solve any uprising problem.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
michaelslamet

I will be glad to help you solve any uprising problem.

 

Thank you, Water, thanks a lot :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×