inicio mail me! sindicaci;ón

Advanced Bash Scripting Guide

This guide really is a complete resource for understanding bash syntax; very easy to get around and understand.

http://tldp.org/LDP/abs/html/index.html

Sending Mail From Bash Scripts with an Attachment

Here is a great little tut on getting started in Bash. I’d recommend it to anyone trying to hack their way into a shell script.

Here is a quick script for sending an email:

#!/bin/bash
 
# Subject of email
SUBJECT="Test email with attachment from a bash script"
 
# Where to send it
TO_ADDRESS="your@email.com"
 
# Where the attachment is
ATTACHMENT_FILE="/tmp/attachment.txt"
 
# For fun, let's put something into the attachment
echo "This goes into the file."  >  $ATTACHMENT_FILE
echo "This appends to the file." >> $ATTACHMENT_FILE
 
# send the message
/bin/mail -s "$SUBJECT" "$TO_ADDRESS" < $ATTACHMENT_FILE

How to Run a Cygwin Command From Windows Scheduler (Scheduled Tasks)

After repeated problems setting up crond to run in cygwin (it just doesn’t like the user accounts, no matter how enthusiastically I argue that I’m me), I spent some time figuring out how to run a Cygwin command as a scheduled task from Windows.

Based on this mail archive post, I created the following cygrun.bat file:

    @echo off
    rem set HOME=c:\
    if "%DEF_PATH%"=="" set DEF_PATH=%PATH%
    set PATH=c:\cygwin\bin;%DEF_PATH%
    set myargs=%*
    if "%myargs%" == "" goto noarg
    rem echo %myargs%
    bash --rcfile "%HOME%/.bashrc" -i -c "%myargs%"
    c:
    rem pause
    sleep 1
    goto exit
    :noarg
 
    rxvt -e /usr/bin/bash --login -i
 
    :exit
    exit

Then I tested the script from the command line as follows, until I had the syntax just so:

c:
cd \cygwin
cygrun.bat cygwin_script arg1 arg2

Once I was able to run it happily, I added the scheduled task as follows:

    Run: C:\WINDOWS\system32\CMD.EXE /x /c start "Some title" /min
c:\cygwin\cygrun.bat cygwin_script arg1 arg2
    Start In: c:\cygwin     &lt;-- must be a real disk drive and path
    Run as: domain\username

Unfortunately, I was never able to figure out how to redirect stdout and stderr. I tried plenty of variations on “>> /some/path/to/log.txt 2>&1″ with no joy. Instead, I just changed all the commands in the script and added that line on to each echo statement. Sad, but functional.