Autoit

Autoit

Παρασκευή 24 Φεβρουαρίου 2012

Gmail Checker using Linux Bash

What do you usually do when you want to check your mail ? Propably the answer is "I open a browser and navigate to gmail". Well this is what i usually do also, but sometimes i want to check my mail with another way. So i wrote a Bash Shell script that does exactly that, checks my gmail acount and outputs the results on the screen. The way the script works is similar with another script i made the "Gmail Commander".
I know that Gmail Checker is a very simple script and not so usefull but it can be downloaded from here:
Enjoy

Aaaaaaaaaaaa, not to forget "Coding can be fun when you do it your own"

Δευτέρα 20 Φεβρουαρίου 2012

Gmail Commander using Linux Bash

Have you ever been in a situation where you are away from your home or office Linux computer
and you want a simple information from it, you just want to execute one line of code in command line and get the return? Well if you have, you know that in order to do so there should be a port forwarding enabled in your router, an ssh server running in your Linux computer and an ssh client (ex. putty.exe) installed in the computer you are temporarly at. With "Gmail Commander" you don't have to go through all that trouble, you simple send a mail in your gmail acount with the code you want to be executed and in a few moments you get another mail with the return of that command. How cool is that.
"Gmail commander" is a simple bash shell script that can run in every machine that has Linux and a network connection. Unfortunately in order for the script to run correctly you should set up your computer to be able to send mails from the command line, but don't worry i'll post another script that does exactly this.
"Gmail commander" monitors your mail inbox using this web page "https://mail.google.com/mail/feed/atom"
(This is a web page that shows only your unread mails. It shows only the subject, author and time of a mail)
When "Gmail commander" spots that there is mail in which the subject begins with "remote_command", then checks if the author of that mail is your self (this is done for security reasons), after all that, executes the command that is in the subject and mails back the reurn.
The mails subject should be in the form "remote_command:actual command" (without the quotes)
For example if you want to view the files in your Desktop you simply send a mail with a subject :
remote_command:ls /home/user/Desktop/
You can download the install_ssmtp.sh and gmail_commander.sh from here
untar in a folder and execute install_ssmtp.sh, then execute gmail_commander.sh
Enjoy and allways remember "Coding can be fun when you do it your own"

Κυριακή 19 Φεβρουαρίου 2012

Power Server using Linux Bash

We all have heard of various types of servers (mail server, DHCP server etc...), but what is a "Power Server"? Well the answer is simple. Power server is a script that checks the power (AC 230V) on our home or office and shuts down network computers when there is a power failure. Of course someone could say "isn't that feature allready embedded on a simple-local UPS ?"
Well ... Of course it is, but think all the trouble to set it correctly.
First you have to connect the UPS with each PC usually with a USB cable, then you must install the UPS software on every PC, after that you have to configure that software on every single computer on the network and last but not least, every now and then you must check that the software is running correctly and it has not been disabled by the PC's user because he or SHE didn't know what that tray icon is for.
All you need to run the "Power server" is a cheap laptop which is running a version of linux with "bash shell" and has a network connection (practicaly every laptop of the last 5 years). All the computers and network switches must be powered from UPS. The laptop that serves as the "Power server" must NOT be powered from UPS.

The way the script works is simple:
-------------------------------------------------------------------------------------------------
First check if the AC adapter is off-line
__if so wait for 30 sec and check again (in order to avoid action in a brief loss of power)
____if power is down after second check then
______send the shutdown command to the network computers
______log the power loss and
______store that the computers have been shutdown
____if power is on-line the second check then
______log it as a brief lose of power
If the ac-adapter is on-line then
__if the computers have been previously shutdown then
____wake the computers that must be allways on-line (NAS, server etc...)
____log that the power is on-line again and
____store that the computers have not been previously shutdown
__if the computets have not been previously shutdown
____display an "everythink is OK" message
-------------------------------------------------------------------------------------------------
Of course you can add some extra features like sending you an email on power fail and thinks like that.

You can Download the code from here:
-untar the file, make the necessary changes to the file remote_server.sh according your network using vi or nano and then execute the file remote_server.sh

I am sure that there are better and more sophisticated ways of doing all this power management but i had a good time exploring bash shell coding.
Always remember "Coding can be fun when you do it your own."