Mail Robot and Cron Task List

Mail robot task list:

1. Create new user. Choose appropriate name, because this will be name of our robot. In this example, we choose "robot".

2. Check, if it is possible to send an email to this user. Send a mail from another computer, login as the new user and try to read this. You can use the "mail" command line command to read its mail. If not working, solve problem first (apt-get and the package name; typical SMTP program for Linux is "sendmail", but Debian use the "postfix" package).

apt-get install postfix

3. Create any filter-type command for working with mail (executable file). The mail will be redirected to this command. The following example is written in the bash:

#!/bin/bash
grep "From:" >>/home/robot/list.txt

The "grep" program is typical filter; it reads standard input, and passes to standard output only files, where is the word, given as a parameter. This example will collect the From: lines from all of the mails, so they can later be processed as one text file. For us, this can proof, that this works. The >> sign will append filtered lines to an end of a file; if the file does not exist, it will be created.

Note, that this file should have the executable flag, and should be readable and executable as our new user ("robot"). Alternatively, you can create this file as a C (C++) program, or write a script in the php (executing php command with a script name as a parameter, for example "php myScript.php").

4. Create .forward file. Leading dot in the name means, that this file will be hidden for the ls command without special parameter. Midnight commander will display this in the list as bold and using some bright color.

New file can be created in the Midnight commander ( mc ) by pressing Shift+F4. Editor behavior will depend on the chosen editor.

Please, note, that all files, which the robot should use, should have the appropriate privileges. The best way is to use the chown command and set the owner of the files to be our new user ("robot").

Execution of a program to process the mail in the .forward file is declared by the pipe ( | , vertical line) sign - you should include whole path to file; if you name the program "test1", the line in the .forward file will look like:

|/home/robot/test1

If you need to pass any parameter (not our case), the whole line should be closed in double quotation.

5. Check, if this works. Imagine another variant.


Switching on/off the LED by computer:

You need an LED on the parallel port and the parashell program installed. The parashell program has to be configured to be executed with the root privileges. Whole this task is dangerous for your computer, correct solution is to create one-purpose program in C to do the output to the parallel port.

The task is to create script to switch off/on the light by 1. mail, 2. cron

Cron task

Do something regularly. Either add a new line to some file, or switch on the LED in the odd minutes and off in the even, or send an email in the desired time..


Send an email by the mail command

1) prepare whole e-mail as a text file, for example mail.txt:

Subject: test mail

Some reasonable text here
[blank line]

2) execute

# mail -s "(your subject)" address@where.to.sent.com < mail.txt

The mail command is intended to be used from console, so you just write the command and the destination address, and then type the whole message, finishing with the Ctrl+D as a stop.

(on the pure versions of the Linux, for example Slackware, the "sendmail" command should be used:

sendmail -v robot@computername.fsid.cvut.cz < mail.txt

)


On-line literature:

Basic bash programming for beginners.

Linux mail user howto.

.forward. On this page, there are more manuals.

.forward again.

Scripts in php (oficial manual).

Another: scripts in php.

Another SMTP program: Postfix

Sending a mail link...)