tag:blogger.com,1999:blog-88607238335516832532024-03-08T16:23:25.558-08:00QatQat blogQuesto e' il blog di QatQat, l'originale QatQat. QaTQat e' un alias che utilizzo dal lontano 2000 sul web e che ora, sui social networks, sui servizi di webmail, in genere dappertutto su internet e' utilizzato da altri abusivamente. ci tengo a precisare che QatQat non vuol dire assolutamente niente e quindi non capisco perche' la gente si registri con uno pseudonimo del genere. bah....Unknownnoreply@blogger.comBlogger5125tag:blogger.com,1999:blog-8860723833551683253.post-33989469496594590152015-01-13T04:17:00.003-08:002015-01-14T08:54:02.475-08:00Generate .NET POCO classes from MySQL queryLately I have been playing a lot with ORMs and Micro-ORMs. Most solutions out there offer a template to create your POCO classes from tables but I did not want to bother with any of them and neither I wanted classes for all tables in my database.<br />
<br />
So I came up with a simple solution, based on a straight SQL query, that writes tedious code for you.<br />
<br />
<b><span style="color: orange;">(Classes are generated in C#)</span></b><br />
<br />
<br />
<br />
<span style="color: cyan;">SELECT CONCAT('public ',</span><br />
<span style="color: cyan;">CASE</span><br />
<span style="color: cyan;"> WHEN DATA_TYPE = 'int' AND IS_NULLABLE = 'NO' THEN 'int'</span><br />
<span style="color: cyan;"> WHEN DATA_TYPE = 'smallint' AND IS_NULLABLE = 'NO' THEN 'short'</span><br />
<span style="color: cyan;"> WHEN DATA_TYPE = 'tinyint' AND IS_NULLABLE = 'NO' THEN 'short'</span><br />
<span style="color: cyan;"> WHEN DATA_TYPE = 'bigint' AND IS_NULLABLE = 'YES' THEN 'long'</span><br />
<span style="color: cyan;"> WHEN DATA_TYPE = 'int' AND IS_NULLABLE = 'YES' THEN 'int?'</span><br />
<span style="color: cyan;"> WHEN DATA_TYPE = 'smallint' AND IS_NULLABLE = 'YES' THEN 'short?'</span><br />
<span style="color: cyan;"> WHEN DATA_TYPE = 'tinyint' AND IS_NULLABLE = 'YES' THEN 'short?'</span><br />
<span style="color: cyan;"> WHEN DATA_TYPE = 'bigint' AND IS_NULLABLE = 'YES' THEN 'long?'</span><br />
<span style="color: cyan;"> WHEN DATA_TYPE = 'varchar' THEN 'string'</span><br />
<span style="color: cyan;"> WHEN DATA_TYPE = 'date' THEN 'DateTime'</span><br />
<span style="color: cyan;"> WHEN DATA_TYPE = 'datetime' THEN 'DateTime'</span><br />
<span style="color: cyan;"> WHEN DATA_TYPE = 'decimal' THEN 'decimal' </span><br />
<span style="color: cyan;"> WHEN DATA_TYPE = 'char' THEN 'string' </span><br />
<span style="color: cyan;"> END,</span><br />
<span style="color: cyan;"> ' ', COLUMN_NAME, ' { get; set; }') AS result </span><br />
<span style="color: cyan;"> FROM COLUMNS WHERE table_schema LIKE 'your_database_name' AND table_name LIKE 'your_table_name'</span><br />
<br />
<br />
<br />
Simply replace <span style="color: orange;">your_database_name</span> and <span style="color: orange;">your_table_name <span style="color: black;">with appropriate names.</span></span><br />
<br />
<span style="color: orange;"><span style="color: black;">QatQat </span></span><br />
<span style="color: orange;"><br /></span>
<span style="color: orange;"><br /></span>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8860723833551683253.post-9502078285914778032011-04-06T05:38:00.000-07:002011-04-06T05:38:20.293-07:00TAMING RSYNCWhen it comes to keeping directories in sync there are many tools out there but I feel that the good old rsync still does a very good job. Moreover, rsync jobs are easy to automate with standard unix tools (cron).<br />
<br />
<br />
For this article we will use a user's home and sync its content to another directory.<br />
So /home/qatqat (my home dir, you will obviously use yours) will be mirrored to /storage/qatqat_home_bak<br />
<br />
Now the basics:<br />
a quick look at rsyn's man page shows:<br />
<br />
<blockquote><span class="Apple-style-span" style="color: red;"> rsync [OPTION...] SRC... [USER@]HOST:DEST</span></blockquote><span class="Apple-style-span" style="color: red;"><br />
</span><br />
mmmh....cryptic! Well, not actually.<br />
let's apply it to our test scenario<br />
<br />
<i>execute all in one line</i><br />
<blockquote><span class="Apple-style-span" style="color: red;">rsync -vraWogp --delete /home/qatqat /storage/qatqat_home_bak</span></blockquote><span class="Apple-style-span" style="color: red;"><br />
</span><br />
Almost clear. let's go through the options:<br />
<br />
-v verbose, detailed output<br />
-r recursive, go and sync recursively into subdirectories (fundamental for a good backup)<br />
-a archive, it means many of the other options together so it is probably redunant<br />
-W whole files, no incremental check, writes more, but compares less<br />
-o preserve owner<br />
-g preserve group<br />
-p preserve permissions<br />
--delete , deletes files in destination directory that are no longer present in source directory<br />
<br />
Now it all starts to make sense. the command will copy the content of /home/qatqat to /storage/qatqat_home_bak keeping all files' settings the same (which is good) and, if I delete something in /home/qatqat, it will do some cleaning into /storage/qatqat_home_bak (which is also good) when run again. The command outputs many lines to screen, that's why we want to catch them and save them to a synchrony log.<br />
<br />
<i>execute all in one line</i><br />
<blockquote><span class="Apple-style-span" style="color: red;">rsync -vraWogp --delete /home/qatqat /storage/qatqat_home_bak > /storage/qatqat_backup_results.txt</span></blockquote><span class="Apple-style-span" style="color: red;"><br />
</span><br />
Now we have a (very) detailed log of all files that have been synchronised.<br />
Now if you use a browser (I am pretty sure you do) you will notice in the qatqat_backup_results.txt file that many thousands of lines refer to your internet cache being synchronised too. Personally I don't like that so here is a way to exclude some directories from the synchony process.<br />
<br />
Create a new file:<br />
<br />
<blockquote><span class="Apple-style-span" style="color: red;">touch /storage/rsync_excluded_dirs</span></blockquote>add all dirs to exclude to it<br />
<blockquote><span class="Apple-style-span" style="color: red;">echo "/home/qatqat/.mozilla/firefox/" >> /storage/rsync_excluded_dirs</span></blockquote><blockquote><span class="Apple-style-span" style="color: red;">echo "home/qatqat/any_other_dir_to_esclude" >> /storage/</span><span class="Apple-style-span" style="color: red;">rsync_excluded_dirs</span></blockquote><br />
Now we tell rsync to read the file when synchronising:<br />
<br />
<i>execute all in one line</i><br />
<i><br />
</i><br />
<blockquote><i><span class="Apple-style-span" style="color: red; font-style: normal;">rsync -vraWogp --delete </span></i><span class="Apple-style-span" style="color: red;">--exclude-from=/storage/rsync_excluded_dirs</span><i><span class="Apple-style-span" style="color: red; font-style: normal;"> /home/qatqat /storage/qatqat_home_bak > /storage/qatqat_backup_results.txt</span></i></blockquote><br />
Pretty nifty now.<br />
Now, what's left is to execute the synchrony periodically, so we need to create a bash script.<br />
A sample script is available here, edit it as you please.<br />
<br />
<a href="https://docs.google.com/leaf?id=0B81iA14IMXcQOThiNDk5ZDctYTI2ZC00MTk5LTg2YzQtYzVlZDk3Zjc4MWZm&hl=en&authkey=CPvatcMM">qatqat_home_backup.sh.gz</a><br />
<br />
<br />
now add the relevant line to /etc/crontab<br />
<br />
<i>execute all in one line</i><br />
<blockquote><span class="Apple-style-span" style="color: red;">echo "30 20 * * 1,3,5 root /storage/qatqat_home_backup.sh > /dev/null 2>&1" >> /etc/crontab</span></blockquote><br />
The line above executes the script every mon, wed, fri at 20:30 PM. Google CRONTAB SYNTAX if you are not familiar with cron.<br />
<br />
That's it for now.<br />
<br />
Comments are welcome,<br />
<br />
Ciao<br />
QatQat<br />
<span class="Apple-style-span" style="color: red;"><br />
</span><br />
<span class="Apple-style-span" style="color: red;"><br />
</span><br />
<span class="Apple-style-span" style="color: red;"><br />
</span><br />
<br />
<div><br />
</div><br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
QatQatUnknownnoreply@blogger.com1tag:blogger.com,1999:blog-8860723833551683253.post-59596058756685432282010-11-14T08:58:00.000-08:002010-11-14T09:06:33.508-08:00A BASH SCRIPT TO MANAGE DYNAMIC DNSHave you ever wanted to host a site on your home linux box or simply reach your home PC from outside? If yes, you have come to the right place.<br />
<br />
For this you will need an account and a DNS from one of the many services that offer dynamic DNS update. The most popular is DynDNS where you can get a free sub-domain on one of their registered domains. If you instead want to have a more professional solution I normally recommend eNom, where you will have to register your own domain.<br />
In this article I will cover both the above mentioned services (and others) but nothing stops you from using the same technique on virtually every dynamic DNS service.<br />
<br />
Before we start make sure that you have "curl" installed on your linux box; if not:<br />
<br />
<span style="color: #cc0000;">apt-get install curl</span> (for all debian based linux distributions)<br />
<span style="color: #cc0000;">yum install curl</span> (for all redhat based linux distributions)<br />
<br />
For all other distributions you can find it at http://curl.haxx.se/download/curl-7.21.2.tar.gz<br />
<br />
Let's prepare all files we will need. As root create a directory called /etc/dynip_scripts, move into it and create the following files:<br />
<span style="color: #cc0000;">touch cur_addr</span> (it will be used to store our current address)<br />
<span style="color: #cc0000;">touch update_dns</span> (our bash script)<br />
<span style="color: #cc0000;">touch log_new_dns</span> (a log for all new addresses)<br />
<span style="color: #cc0000;">touch log_unchanged_dns</span> (a log for all unchanged DNS)<br />
<br />
Now we get to the scripting side of our solution.<br />
Updating your DNS takes 2 steps: finding your current address and pushing it to a dynamic DNS service.<br />
<br />
Step 1) we need to find out our IP address. we have several ways to accomplish this task but I will focus on two most generic cases: linux handles your DSL connection or you have a router to connect to the Internet. <br />
If linux is handling the connection, there should be an interface created to access the Internet (something like ppp0).<br />
In this case "ifconfig" command will return your current address. Unfortunately ifconfig returns a plethora of useful information, totally unnecessary though for us at present.<br />
We need to filter the output in order to get the current ip address.<br />
Bash has all the instruments need:<br />
<br />
<span style="color: #cc0000;">ifconfig ppp0 | grep -i "addr:" | cut -f2 -d: | cut -f1 -d " "</span><br />
<br />
The above command returns your IP address stripped of all other information<br />
<br />
If instead a router is handling your connection you need to rely on external services to get the IP address. DynDNS hosts a basic public page to identify your address.<br />
<br />
<span style="color: #cc0000;">curl --silent http://checkip.dyndns.org | cut -f6 -d " " | cut -f1 -d "<"</span><br />
<br />
If that doesn't work you can use a service I am hosting on my web server.<br />
<span style="color: #cc0000;">curl --silent http://www.intellisan.eu/get_ip.php?auth=210873 | grep IPAddress | cut -f2 -d:</span><br />
<br />
<br />
Step 2) communicating your address to a DynDNS or eNom. Both services support updating your address through the querystring.<br />
Once obtained a valid account and a DNS, whether a subdomain from DynDNS or your own registered domain from eNom, here are examples of working querystrings.<br />
<br />
- DynDNS (I registered a subdomain of their homelinux.org domain called "qatqat", but you obviously will register your own). I will be therefore updating qatqat.homelinux.org, which you will replace with yours:<br />
<br />
<span style="color: #cc0000;">curl -u your_username:your_password "http://members.dyndns.org/nic/update?hostname=qatqat.homelinux.org&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG&myip=your_ip_address"</span><br />
<br />
If you are using eNom instead here is the querystring:<br />
<span style="color: #cc0000;">curl "https://reseller.enom.com/interface.asp?command=setdnshost&hostname=your_hostname&zone=your_domain&domainpassword=your_password&address=your_ip_address"<br />
</span><br />
<br />
Now let's put all of this in our bash script update_dns. Edit it with your favorite text editor and copy the text below in it. In the script I have also included some more nifty features such as obtaining your address from a NETGEAR router, updating a no-ip or everyDNS dynamic domain address, or sending an alert email after the DNS is updated.<br />
<br />
<br />
<span style="color: #cc0000;">#!/bin/bash<br />
<br />
<i>#get the address stored in the cur_addr file</i><br />
export CUR_IPADDR=$(cat /home/antonio/cur_addr)<br />
<br />
<i>#obtain IP address, uncomment all options that you will be using</i><br />
export DYNIP_ADDR=$(curl --silent http://checkip.dyndns.org | cut -f6 -d " " | cut -f1 -d "<") <i>#intellisan.eu server</i><br />
#export DYNIP_ADDR=$(curl --silent http://www.intellisan.eu/get_ip.php?auth=210873 | grep IPAddress | cut -f2 -d:)<br />
<br />
<i>#GET ADDRESS FROM NETGEAR ROUTERS (tested with DG834 or other similar firmware)</i><br />
#export DYNIP_ADDR=$(curl --silent -u admin:your_router_password http://192.168.1.1/setup.cgi?next_file=s_status.htm | grep -A1 -m1 "IP Address" | grep -v "IP Address" | cut -d ">" -f2 | cut -d "<" -f1) <i>#obtain your IP address from ifconfig command - it only works if linux is handling your internet connection directly</i><br />
#export DYNIP_ADDR=$(ifconfig ppp0 | grep -i "addr:" | cut -f2 -d: | cut -f1 -d " ")<br />
<br />
<br />
<i>#now we compare the current address with the one stored in the cur_addr file</i><br />
if [ "$CUR_IPADDR" = "$DYNIP_ADDR" ]; then<br />
<br />
<i>#if the address has not changed we simply log it</i><br />
echo "$(date) - unchanged address " >> /home/antonio/log_unchanged_dns<br />
<br />
else<br />
<br />
<i>#if the address has changed instead we log it and carry on with the rest</i><br />
<br />
<i>we update the cur_addr file</i><br />
echo "$DYNIP_ADDR" > /home/antonio/cur_addr<br />
<br />
<i>#we log an entry in the log_new_dns file</i><br />
echo "$(date) - New IP $DYNIP_ADDR" >> /home/antonio/log_new_dns<br />
<br />
<br />
<i>#now we update our dynamic address on DynDNS</i><br />
curl -u your_username:your_password "http://members.dyndns.org/nic/update?hostname=your_subdomain.homelinux.org&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG&myip="$DYNIP_ADDR<br />
<br />
<i>#uncomment the line below if instead you are using eNom</i><br />
#curl "https://reseller.enom.com/interface.asp?command=setdnshost&hostname=your_hostname&zone=your_domain&domainpassword=your_password&address="$DYNIP_ADDR<br />
<br />
<br />
<i>#here are strings for more services<br />
#everydns.net</i><br />
#curl --silent -u your_username:your_password "http://dyn.everydns.net?ver=0.1&domain=your_domain&ip="$DYNIP_ADDR<br />
<br />
<i>#no-ip</i><br />
#curl --silent "http://your_username:your_password@dynupdate.no-ip.com/nic/update?hostname=yourhostname.domain&myip="$DYNIP_ADDR<br />
<br />
<br />
<i>#now our final touch. we send an email to inform you of the new address</i><br />
echo "YOUR PUBLIC IP ADDRESS HAS CHANGED TO $DYNIP_ADDR ON $(date)" | mail -s "a service message from my server" your@yourdomain.com<br />
<br />
</span><br />
<br />
<br />
<br />
Now, all is left to do is to make the update_dns script executable and hidden to normal users and then create an entry in /etc/crontavb that will execute it every 20 minutes.<br />
<br />
Always as root execute the commands below:<br />
<br />
<span style="color: #cc0000;">chmod 700 /etc/dynip_scripts/update_dns<br />
<br />
echo "10,30,50 * * * * root /etc/dynip_scripts/update_dns > /dev/null 2>&1" >> /etc/crontab</span><br />
<br />
This is it really.<br />
<br />
<br />
Feel free to use and modify this script as you please, comments and suggestions are anyway appreciated.<br />
This script can be adjusted to work with basically all dynamic DNS services by simply adding lines with the curl command for the appropriate querystring. <br />
I just did not have the time to discover many other services' querystrings so if you happen to find them out kindly post a comment here.<br />
<br />
Cheers,<br />
<br />
QatQatUnknownnoreply@blogger.com0tag:blogger.com,1999:blog-8860723833551683253.post-31708572511673127152010-10-16T05:22:00.000-07:002010-11-18T08:28:43.084-08:00HOW TO INSTALL VMWARE SERVER 2.0.2 ON FEDORA 13<span style="color: #cc0000;">(UPDATED ON on 2010-11-14: This procedure also works with kernel 2.6.34.7-61)</span> <br />
<br />
<br />
<br />
Hi there,<br />
<br />
Having upgraded my F12 box to the latest release I soon found out, like you if you are reading this, that VMWare Server couldn't compile the necessary kernel modules as expected when running /usr/bin/vmware-config.pl<br />
<br />
After reading a few posts on the net, none of which was a direct solution to my problem, I solved the issue by putting together hints from different blogs.<br />
<br />
Here is what I have done, but first of all my setup:<br />
<br />
Fedora 13<br />
Kernel 2.6.34.7-56.fc13.x86_64 (64Bit kernel but this should also work on a 32bit)<br />
VMware-server-2.0.2-203138.x86_64<br />
<span style="color: #cc0000;"><br />
</span><br />
<br />
In order for everything to work well you will need the ".tar.gz" version of vmware-server from <a class="linkification-ext" href="http://www.vmware.com/" title="Linkification: http://www.vmware.com">www.vmware.com</a> (the patch will not work with the .rpm version)<br />
<br />
The correct file to download is:<br />
<br />
VMware-server-2.0.2-203138.x86_64.tar.gz<br />
<br />
You now need to get the patch written by Radu Cotescu (special thanks to Radu for this nice piece of work)<br />
<a href="http://codebin.cotescu.com/vmware/vmware-server-2.0.x-kernel-2.6.3x-install.sh">http://codebin.cotescu.com/vmware/vmware-server-2.0.x-kernel-2.6.3x-install.sh</a><br />
<br />
unzip+untar the script, if needed, than make it executable and run it as root<br />
<br />
<span style="color: #cc0000;"><br />
chmod +x vmware-server-2.0.x-kernel-2.6.3x-install.sh<br />
<br />
./vmware-server-2.0.x-kernel-2.6.3x-install.sh [PATH_TO_VMWARE_ARCHIVE.tar.gz]<br />
</span><br />
<br />
Follow the instructions on screen and you will get stuck when the script invokes vmware-config.pl. for you.<br />
<br />
To solve this issue you will need to manually edit the file vmware-config.pl. <br />
<br />
Open the vmware-config.pl file in any editor (as long as you do this as root) then search for :<br />
<br />
if (-e $answer . ‘/linux/utsrelease.h’) {<br />
$uts_headers .= “#include <linux utsrelease.h="">\n”;<br />
<br />
and replace with:<br />
<br />
if (-e $answer . ‘/generated/utsrelease.h’) {<br />
$uts_headers .= “#include <./generated/utsrelease.h> \n”;<br />
<br />
<br />
At this point, run the /usr/bin/vmware-config.pl file and the kernel modules will compile without issues.<br />
<br />
I hope this helps you.<br />
<br />
QatQat</linux>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8860723833551683253.post-46995749089595568202010-01-19T06:07:00.000-08:002010-10-18T00:00:35.099-07:00LA UBUNTIZZAZIONE DI LINUXla ubuntizzazione di linux ci sta rendendo sempre piu' simili agli utenti Microsoft. Canonical diventa sempre piu' simile a Microsoft. Tra le varie dispute apprendo che la nuova release di Ubuntu non include' "The Gimp" come software di manipolazione immagini perche' ritenuto troppo difficile e perche' (testuali parole del comunicato stampa) "la schermata iniziale non e' accattivante abbastanza".<br />
<br />
Di questo passo, invece di elevare il livello medio di conoscenze IT si raggiungerà un triste livellamento verso il basso, proprio dove Microsoft regna sovrana.<br />
<br />
Sotto un video di Fedora 13, una distribuzione molto piu' in sintonia con lo spirito iniziale di Linux e, sopratutto, che non usa alcun software proprietario.<br />
<br />
<object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/NPaTXYwu5Ag?fs=1&hl=en_US"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/NPaTXYwu5Ag?fs=1&hl=en_US" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object><br />
<br />
<br />
<object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/PoaSR5XDcqk?fs=1&hl=en_US"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/PoaSR5XDcqk?fs=1&hl=en_US" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object>Unknownnoreply@blogger.com0