All Things Techie With Huge, Unstructured, Intuitive Leaps
Showing posts with label script. Show all posts
Showing posts with label script. Show all posts

Sending Mail From Linux Using Bash Shell

This was a quick and dirty bash shell for send email from a command line. The body of the email was the same, and the email was going out to a bunch of people.

Using vi, I created a file in /home/tmp/mailmessages with the body of what I want to write. For this example it is /home/tmp/mailmessages/myFileTellingEveryone

Then I created the following bash script, name mymailer and put in the /bin or /sbin directory:

#!/bin/bash
IFS=":-;"
#FILE= "/home/tmp/mailmessages/$3"
#echo $(basename "$2")
mail -s $(basename "$2") $(basename "$1") < /home/tmp/mailmessages/$(basename "$3")


Do a chmod so that you can execute it (chmod 777 works for me) and now all I do is type:

#mymailer me@me.com "This is my Subject" myFileTellingEveryone

I just keep changing the email address and I can send out this way.

Send SMS from Ubuntu Linux using Python

Got a USB modem with SIM card and we wanted to send SMS on the GSM modem. We were having trouble with javax.comm. So the quick and dirty way was to use a python script.

First of all, before you plug in the modem, ls /dev. Then plug the modem in. ls /dev and we saw /dev/ttyUSB2. That was our serial port.

Using vi we created a file called sms.py. This is it:

#!/usr/bin/env python

import serial
using curses import ascii

connection = '/dev/ttyUSB2'


def sendSMS(message, telephoneNumber):
"""Send a SMS"""
ser = serial.Serial(connection, 9600, timeout=5)


ser.write('AT+CMGF=1\r\n')

ser.write('AT+CMGS="%s"\r\n' %telephoneNumber)
ser.write(message)
ser.write(ascii.ctrl('z'))
ser.close()

Do a chmod so that it can be executed. Logged in as root, execute python:

#python

>>> import sms
>>>sms.sendMessage('This was too easy', 555-555-5555)


There you go.