riahc3 50 Â Team Colleague

Hello

Havent been here in a while but might as well give it a shot.

I have several Apache Tomcat instances running on a Windows Server on different ports. They are all HTTP. The idea would be to (on the same server) install a IIS and use it a content switcher and also as a SSL terminator.

This was depending on the URL, the IIS would redirect to one spot or another.

All of this is to replace a Netscaler

Ive tried to setup this with ARR, URL rewrite and IIS but for now Im only getting a "Bad Gateway" error.

Anyone done this before?

riahc3 50 Â Team Colleague
#!/bin/sh
# How many seconds before file is deemed "older"
# 86400 = 1 day
# 172800 = 2 days
FILENAME=$1
WARNTIME=$2
CRITTIME=$3
# Get current and file times
CURTIME=$(date +%s)
mount -t cifs //192.168.3.222/SHARENAME/FOLDER /mnt/FOLDER -o ro,username=USER,vers=1.0,password=PASS,nodev,uid=backup,file_mode=0444,dir_mode=0444
FILETIME=$(stat /mnt/FOLDER/$FILENAME -c %Y)
umount -l /mnt/FOLDER
TIMEDIFF=$(expr $CURTIME - $FILETIME)
# Check if file older
if [ $TIMEDIFF -lt $WARNTIME ]; then
echo "OK"
exit 1
elif [ $TIMEDIFF -gt $WARNTIME -and $TIMEDIFF -lt $CRITTIME ] ; then
echo "WARNING"
exit 1
elif [ $TIMEDIFF -gt $CRITTIME ] ; then
echo "CRITICAL"
exit 2
fi
echo "UNKNOWN"
exit 3

I believe the issue is that "mount" isnt working. Running this as root works so the script isnt the issue. I know the username that runs the script.

riahc3 50 Â Team Colleague

Bash would be fine

riahc3 50 Â Team Colleague

First, it has been a LONG time since Ive been here. Good memories from when I was young.

Anyways

In a monitoring system I have, I had a plugin that remotely checked a SMB share and if the file hasnt been modified in 1 day, it should return a warning. if it is 2 days or more, it should return a critical.

Returning the warning and the critical isnt the issue, its the entire logic of the script itself.

I mean, I dont think it should be too difficult but Im not used to shell scripting. Also, the downfall exists, of having to check if the mount is correct, etc.

The logic is basically

inputvariable warningdays
inputvariable criticaldays
inputvariable smbpath
mount smbpath to final folder /mnt/folder
if mount is unsuccessful
return unknown
if mount is successful
if /mnt/folder/file does not exist
return unknown
if /mnt/folder/file does exist
if /mnt/folder/file has been written to less than warningdays
return ok
if /mnt/folder/file has been written to more than warningdays and less than criticaldays
return warning
if /mnt/folder/file has been written to more than criticaldays
return critical
if previousoperations are done
unmount
if unmount is unsuccessful
return unknown
finish

Could someone tell me the basics of the shell script?

Thank you.

riahc3 50 Â Team Colleague

Where is the section to post code snippets?

riahc3 50 Â Team Colleague

I see...not exactly what I was looking for but...

riahc3 50 Â Team Colleague

I want to write out a DXF file with line arc and maybe spline.

My issue is documentation; While I have looked at AutoCAD's site I feel that there isnt enough to say "here is a BMP of a circle. Lets take it and convert it using this code". Its too garbled up and doesnt make things clear.

Could someone lend a hand on finding a good and easy way on how to do this?

riahc3 50 Â Team Colleague

Helps 0 with modifying the code I have

riahc3 50 Â Team Colleague

None of these links really help out with the code.

riahc3 50 Â Team Colleague

(Ubuntu Server)

I have a folder full of files in pairs (one is a log, another is a DB backup) They are basically create/modified at the same time.

I need a shell script that detects if the folder has more than 28 or 30 files (always will be a pair), it deletes the oldest two.

What is the quickest way to do this?

riahc3 50 Â Team Colleague

Im doing some work with C# and AD and Im missing something right now that I cant seem to see.

I want to get a description of a security group in Active Directory and use that in a tooltip.

I have all the security groups but Im not sure how to get that description.

Here is the code for security groups (and additional non working code for trying to get the description field)

    /* ABOVE THIS THERE IS A LOT MORE CODE BUT THIS IS THE PART THAT LOADS THE GROUPS FROM AD AND ALSO PUTS IT IN A COMBOBOX */
            //Groups:
            // create your domain context
            PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "domain.com");

            // define a "query-by-example" principal - here, we search for a GroupPrincipal 
            GroupPrincipal qbeGroup = new GroupPrincipal(ctx);

            // create your principal searcher passing in the QBE principal    
            PrincipalSearcher srch = new PrincipalSearcher(qbeGroup);

            // find all matches
            foreach (var found in srch.FindAll())
            {
                if (found.DistinguishedName.Contains("OU=DOMAIN,DC=domain,DC=com"))
                {
                    Globals.groups.Add(found.SamAccountName);
                    if (!Globals.groups.Contains("excludedgroup1") && !Globals.groups.Contains("excludedgroup2"))
                    {
                        Globals.tooltipforgroups.Add(found.Description);
                    }

                }
                // do whatever here - "found" is of type "Principal" - it could be user, group, computer.....          
            }

            var array = Globals.groups.Distinct().ToArray();

            foreach (string x in array)
            {
                if (x != "excludedgroup1" && x != "excludedgroup2")
                {
                    comboBoxDepart.Items.Add(x);

                }

            }

Im obviously missing something very obvious.

riahc3 50 Â Team Colleague

Trying to get the last row inserted from a Excel sheet. The sheet is called clientes.

I have

id, name, description

Since ID is auto incremental, I can sort by ID:

My idea is:

oledbcmd = "Select top (1) * From [CLIENTES$] ORDER BY id desc";

but it does not work. Any tips?

riahc3 50 Â Team Colleague

Sadly, I cannot edit but I want to make clear that

oledbcmd = "Select * From [CLIENTES$]";

Works. It isnt a connection issue or anything else (the connection code is already implemented but posting a huge chunk of code makes no sense when just one line is the culprit.

riahc3 50 Â Team Colleague

I have the following:

string oledbcmd = "";
        string constr =
            @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Excel.xls;@Extended Properties='Excel 8.0;HDR=Yes;";

            oledbcmd = "Select top (1) * From [CLIENTES$] ORDER BY id desc";

        OleDbCommand oconn = new OleDbCommand(oledbcmd, con);
        OleDbDataAdapter sda = new OleDbDataAdapter(oconn);

        DataTable data = new DataTable();
        sda.Fill(data);

It fails. What is wrong with that query? I want to get the last row that was inserted.

riahc3 50 Â Team Colleague

I see most PowerShell questions being asked in Shell Scripting and its not really a scripting language per say as it is much deeper than that.

I porpose it gets its own section...

riahc3 50 Â Team Colleague

I'm looking for the best way to back cold backups of the email on my client's PC.

Starting off with PowerShell, I would run this:

Get-ChildItem -Path 'C:\' -Filter '*.pst' -Recurse -ErrorAction SilentlyContinue |
  Select-Object -Expand Directory -Unique |
  Select-Object -Expand FullName

To search where the email file is. I would have to search for Thunderbird as well.

This would run each time the user shuts down the PC. It would look if the email file and the backup copy have a 48 hour time difference and would do it.

The issue with this method is that it has to go thru the ENTIRE C: drive in order to find it which is VERY slow from tests I've done.

By default, I can go to the default Outlook folder using the username variable but what if the user decides for some odd reason to put it somewhere else?

The reason we backup is because clients use POP3 to make "backups" of whatever is on the mail server and not fill up the email server. I've attempted to move serveral to IMAP but they refuse because they would rather store emails from years ago on their PCs. Also IMAP have issues making folders for some odd reason.

I hope someone could lend a hand

riahc3 50 Â Team Colleague

I have a mobile VPN client that I want to backup to. The problem is that it does not have a static IP to due it being L2TP/IPSec. Thats the bad news. The good news is that there wont be too many VPN clients (at most 10 if that) so Ill be to search for it easy.

Basically, I should go thru a list of IPs from 192.168.250.0 to 192.168.250.10 and check if the IP is up and running (ping). Once I check it is up and running, I should check for a path //192.168.250.1/PATH and just to be 100% sure its the correct place, Ill serach for a single text file with a single name such as "IAMTHECORRECTVPNBACKUPSERVER.txt" once that is done, I start a robocopy there....

I have the robocopy implemented in PowerShell now I need to implement the pinging and searching the correct IP. How could I do this?

riahc3 50 Â Team Colleague

Like I said I dont want to backup the FULL database each time over and over again.

riahc3 50 Â Team Colleague

Here is one link for your help http://blog.mwpreston.net/2011/11/24/moving-your-veeam-backup-replication-database/

MySQL, not MS SQL Server.

riahc3 50 Â Team Colleague

If the main plays as master then it's ok, just open 3306 at let the slaves connect to it, you do not need to open ports on slaves because they act as clients. Otherwise you could setup a SSH tunnel:

The main site would be the master, yes. On the main site I can open all the ports I want. The any other site I cannot under any way, shape, or form open any ports. At most 1, if that. I do not have access to the other sites and it is not my ownership.

riahc3 50 Â Team Colleague

Would replication require opening ports on the site's side? If so, I cannot open ports on the site's side. Only on the main side.

riahc3 50 Â Team Colleague

I have several databases located over the world, this all have the same structure, with the same tables and triggers. For clarification purposes:

Site 1: database_1 (with all its tables same as other sites)

Site 2: database_1 (with all its tables same as other sites)

Site 3: database_1 (with all its tables same as other sites)

Now in my main site I would have something like this:

Site main:
database_1_site_1 (with all its tables same as other sites)
database_1_site_2 (with all its tables same as other sites)
database_1_site_3 (with all its tables same as other sites)

Now, obviously, these databases will get bigger and bigger so I don't want to backup everything over and over again as its in GBs and it will take a long time. I would just need to backup what has changed.

How can I set this up?

riahc3 50 Â Team Colleague

The device would be a basic Synology NAS; Apache, PHP, etc.... Just to note some of the technologies that would be avaliable.

riahc3 50 Â Team Colleague

If it helps the web service and the database will be on the same device.

riahc3 50 Â Team Colleague

For example, lets make a simple web service app that I put two numbers, adds it up and it gives me the result of the sum :)

What is the best way to implement this step-by-step? Because Im seeing a connector is impossible.

riahc3 50 Â Team Colleague

What's your language choice for the SOAP server? Would make finding a possible tutorial easier.

http://msdn.microsoft.com/en-us/library/ms862153.aspx

Personally, I perfer C#. Realistically, I want the easiest one.

riahc3 50 Â Team Colleague

The dotConnect seems to work (because it accepts the connection) but it has some stupid license issues that dont allow me to use it.

So right now we are with SOAP (which Im trying to implement but I dont see a good way how or at least Im not understand how to do it, any tutoral?) or the ADOCE DLL that was mentioned but I havent been able to find the DLLs.

riahc3 50 Â Team Colleague
riahc3 50 Â Team Colleague

The web service route has been discarded.

That "ADOCE DLL" seems intresting. I just need the files.

riahc3 50 Â Team Colleague

Im trying to download it but it gives me a .exe which I do not trust.

Any place to directly download those .dll?

riahc3 50 Â Team Colleague

a

What IDE is that, Visual Studio? Talking to a REST service requires not much more than a (Http)WebRequest.

We are talking about a embedded industrial application. Nothing on a PDA, POS, smartphone, etc :)

VS does not do embedded devices anymore I believe

riahc3 50 Â Team Colleague

That's why I suggested a REST server at first, the implementation and usage is much simpler.

The thing is that the IDE I use for developing a embedded app on Windows CE does comment about using SOAP but it comments nothing about REST so Im not completely sure it is compatible

riahc3 50 Â Team Colleague

Yes, that works too.

So basically I would build a "SOAP server" and then my application running in Windows Embedded Compact 7 would call it and it would get data?

Is this the idea?

I looked up how to make a SOAP server and its kind of....confusing..

riahc3 50 Â Team Colleague

The MySQL server runs on a Synology NAS which I BELIEVE also has the ability to run as a web server.

How do you find how exactly I would set up a REST server? I heard of JSON but IM not sure if its related or not.

What about SOAP? Would this work?

riahc3 50 Â Team Colleague

Haven't been able to find any yet. I think your best bet is to create a webservice as intermediairy.

This actually could be a intresting solution.

I would run this web service on a Windows Embedded Compact 7 running on a ARM processor though so Im not completely sure its possible BUT I would be willing to give it a chance.

What steps do you suggest I do?

riahc3 50 Â Team Colleague

I need a connector to connect from a application running on Windows CE machine to a MySQL Server. Is there anything like this for both ARM and x86?

Thank you

riahc3 50 Â Team Colleague

But, I don't know how you're going to query this - from a form?

Drop down box to make sure that a idiot doesnt insert "hi" or anything. Depending on the date and the hh:mm:ss inserted, I also get the miliseconds to make sure that there is valid entries.

Your table is a bit messy with all the timestamp stuff. Retrieving maxes between two datetimes should be straightforward:

Seeing as I dont use Time_Stamp_Full, Ill problably remove that column. It was just for testing purposes.

Now just gotta figure out a way to make sure I get a even ammount of start rows and end rows but I think that will be pretty simple (at least I hope).

Im gonna try implementing this...thank you for your help.

riahc3 50 Â Team Colleague

The "simpler query" never gave me results as I imagine it goes thru EVERYTHING. While the one where I filter by date and time does take a while (a minute) but gives me the results.

Or do you mean something else?

BTW, I hate SQL/DBs...

riahc3 50 Â Team Colleague

Could you explain the query? I know it first does a first query getting the maxcycle between two dates. But then Im not completely sure the grouping...

riahc3 50 Â Team Colleague
    select mytable.* from mytable
    inner join (select *, max(cycle) as maxcycle from mytable WHERE ('2014-04-24 09:09:37' < Time_Stamp 
    OR ('2014-04-24 09:09:37' = Time_Stamp AND  765 <= Time_Stamp_ms)) 
    AND ('2014-04-24 09:10:38' > Time_Stamp 
    OR ('2014-04-24 09:10:38' = Time_Stamp AND Time_Stamp_ms <= 5))
    group by cycle_id ) as grouped
    on mytable.cycle_id = grouped.cycle_id
    and mytable.cycle = grouped.maxcycle

Hmm this looks intresting....This gives me

    '2014-04-24 09:09:57', '685', '5555', '4444', '3333', '2222', '1111', '123', '250', 'name', '1398323397.6850', '1'
'2014-04-24 09:10:17', '685', '5554', '4443', '3332', '2221', '1110', '123', '250', 'name', '1398323417.6850', '2'
'2014-04-24 09:10:37', '685', '5555', '4444', '3333', '2222', '1111', '123', '250', 'name', '1398323437.6850', '3'
'2014-04-24 09:10:38', '5', '5554', '4443', '3332', '2221', '1110', '123', '4', 'name', '1398323438.0050', '4'

Which is indeed technically correct. Even though I know that "1" is the start of each cycle, would this work as well:

    select mytable.* from mytable
    inner join (select *, min(cycle) as mincycle from mytable WHERE ('2014-04-24 09:09:37' < Time_Stamp 
    OR ('2014-04-24 09:09:37' = Time_Stamp AND  765 <= Time_Stamp_ms)) 
    AND ('2014-04-24 09:10:38' > Time_Stamp 
    OR ('2014-04-24 09:10:38' = Time_Stamp AND Time_Stamp_ms <= 5))
    group by cycle_id ) as grouped
    on mytable.cycle_id = grouped.cycle_id
    and mytable.cycle = grouped.mincycle

???

'2014-04-24 09:09:37', '765', '5555', '4444', '3333', '2222', '1111', '123', '1', 'name', '1398323377.7650', '1'
'2014-04-24 09:09:57', '765', '5554', '4443', '3332', '2221', '1110', '123', '1', 'name', '1398323397.7650', '2'
'2014-04-24 09:10:17', '765', '5555', '4444', '3333', '2222', '1111', '123', '1', 'name', '1398323417.7650', '3'
'2014-04-24 09:10:37', '765', '5554', '4443', '3332', '2221', '1110', '123', '1', …
riahc3 50 Â Team Colleague

This query seems to be better:

select mytable.* from mytable
    inner join (select *, max(cycle) as maxcycle from mytable
    group by cycle_id) as grouped
    on mytable.cycle_id = grouped.cycle_id
    and mytable.cycle = grouped.maxcycle
    WHERE ('2014-04-24 09:09:37' < Time_Stamp 
    OR ('2014-04-24 09:09:37' = Time_Stamp AND  765 <= Time_Stamp_ms)) 
    AND ('2014-04-24 09:10:38' > Time_Stamp 
    OR ('2014-04-24 09:10:38' = Time_Stamp AND Time_Stamp_ms <= 5))

After 76 seconds it gives me a error saying: "Error Code: 1052. Column 'Time_Stamp' in where clause is ambiguous"

riahc3 50 Â Team Colleague

UPDATE: http://www.screencast.com/t/uoIMkRWgAX0q
SELECT: http://www.screencast.com/t/LbrMHsPLY3
Join and Group will take a long time :(
You didn't say how often you are thinking of running this query.

Basically, someone will select a start time/date and a end time/date. A query will be run between those two dates and it will show in one list box when a cycle started (1) and when it ended (the next 1 but the row before it) in another list box. This this I can also calculate the duration of the cycle which is VERY important.

riahc3 50 Â Team Colleague

This query never finished:

SELECT times.* FROM times 
    INNER JOIN (SELECT *, MAX(cycle) AS maxcycle FROM times 
    GROUP BY cycle_id) AS grouped 
    ON times.cycle_id = grouped.cycle_id 
       AND times.cycle = grouped.maxcycle

Started at 1300 and it was still running at 1700

riahc3 50 Â Team Colleague

That query never finished BTW.

Just in case the table isnt clear:

a1152f33adec633e5dcda2747cd62937

I insert cycle each time one until it reaches n (n right now is 250) and cycle_id thruout that is the same number. Once it reaches 250, and then starts at one again, cycle_id is +1

cycle will NEVER jump numbers like your table. It will ALWAYS been 1,2,3,4 etc. I just do not know when it ends and starts at 1. I only know it always starts at 1

I hope this clears some things up.

riahc3 50 Â Team Colleague

Lets see how long this one takes....

riahc3 50 Â Team Colleague

Done. Took 37 minutes :P

Trying now:

1.SELECT times.* FROM times 
2.    INNER JOIN (SELECT *, MAX(cycle) AS maxcycle FROM times 
3.    GROUP BY cycle_id) AS grouped 
4.    ON times.cycle_id = grouped.cycle_id 
5.        AND times.cycle = grouped.maxcycle
riahc3 50 Â Team Colleague

Didnt see that SQL sorry...

Running it now. Its gonna take a while to update 5 million records.

Option 1 is not possible.
Option 2 is possible but using a BIGINT to list all the records in a incremental mannner...Im not a fan. Also, wouldnt this pose a small problem if I delete a record?
Option 3 is IMO the one I most like. I think I perfer to go down that route as at the end of the day, I think it is VERY likely that the final production table will have a format exactly like this.

So lets go with option 3. Its fill up that column as we speak so....Lets see how long it takes to update all 3 million plus of those records.

riahc3 50 Â Team Colleague

Well, how do I currently fill up "cycle_id" with 1,1,1,1,1,1,1,1,1;2,2,2,2,2,2,2,2,2,2,2,2;3,3,3,3;4,4,4,4,4

In my current table data?

Also by a autoincremental, do you mean that each time I enter a new row, I increment a AI column? I guess I COULD use a BIGINT to do this....I dont ever thing Ill reach 9 223 372 036 854 775 807 rows. How do I fill it up for my current data?

BTW, I just want to explore all options right now and see which is easiest (also returns a answer quickly so we can implement them all)

The selecting of previous values does not include the last value in the table

Not sure what you ment by that.

Thank you for all your help. I would need to know how to currently fill up cycle_id with 1,1,1,1,1,1,1,1,1;2,2,2,2,2,2,2,2,2,2,2,2;3,3,3,3;4,4,4,4,4 to test it out.

riahc3 50 Â Team Colleague

I suggested an 'id' PK column at the start and for me, that would be the easiest option. WHat I fail to understand is why you're giving the set the same cycle_id - when adding to the db, you'd have to run a query to check the max value of cycle_id before inserting. I suggest just an autoincrement field long as it is sequential - no missing values, this should work...

I might not understand you correctly.....

In the case Im purposing I have two columns: "cycle" and "cycle_id". "cycle" is going to increment each time I take a sample (every 20 ms) of a complete cycle. "cycle_id" just makes sure those samples are of the same cycle.

Just add a PK int field called id to the table. I've called the datatable 'times' - the rest of the terms are just aliases and names for derived tables

Right now, just to clarify, I have 3 PKs: "Time_Stamp" which is a DATETIME, "Time_Stamp_ms" which is a INT, and "Time_Stamp_full" which is a DECIMAL.

Memory: some info here - http://www.mysqlperformanceblog.com/2007/11/01/innodb-performance-optimization-basics/
But that's just a Google search - you can do that yourself.

Im doing this off a simple NAS such as a Synology.

I dont think maybe Im describing the problem correctly because I think Im overcomplicating the problem.

Is there a way to find a 1 in the cycle column and just get the row before it? Yes, I know they …

riahc3 50 Â Team Colleague

Joins create temp tables, so I'm assuming that you need to supply more memory to their creation.

My queries run OK on phpMyAdmin and SQLyog, so perhaps you should think about getting a better GUI. Or are you talking about something else?

How can I supply more memory?

I have the following:

'innodb_additional_mem_pool_size', '1048576'
'innodb_buffer_pool_size', '268435456'
'innodb_log_buffer_size', '1048576'
'innodb_log_file_size', '5242880'

Its not a GUI based program. Something else.

Another option would be this:

    Time_Stamp              Time_Stamp_ms   d1      d2      d3      d4      d5      d6      cycle   name    cycle_id

    2014-04-24 09:09:37         765         5555    4444    3333    2222    1111    123     1       name        1
    2014-04-24 09:09:37         845         5555    4444    3333    2222    1111    123     2       name        1
    2014-04-24 09:09:37         925         5555    4444    3333    2222    1111    123     3       name        1
    2014-04-24 09:09:38         5           5555    4444    3333    2222    1111    123     4       name        1
    2014-04-24 09:09:38         85          5555    4444    3333    2222    1111    123     5       name        1
    2014-04-24 09:09:38         165         5555    4444    3333    2222    1111    123     6       name        1
    2014-04-24 09:09:38         245         5555    4444    3333    2222    1111    123     7       name        1
    2014-04-24 09:09:38         325         5555    4444    3333    2222    1111    123     8       name        1
    2014-04-24 09:09:38         405         5555    4444    3333    2222    1111    123     9       name        1
    2014-04-24 09:09:38         485         5555    4444    3333    2222    1111    123     10      name        1
    2014-04-24 09:09:38         565         5555    4444    3333    2222    1111    123     11      name        1
    2014-04-24 09:09:38         645         5555    4444    3333    2222    1111    123     12      name        1
    2014-04-24 09:09:38         725         5555    4444    3333    2222    1111    123     13      name        1
    2014-04-24 09:09:38         805 …