LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Bash Scripting Question (https://www.linuxquestions.org/questions/programming-9/bash-scripting-question-334171/)

jsimmonds 06-16-2005 07:05 AM

Bash Scripting Question
 
Hi below is a script I made. I need to send an email automatically from within this script.


Now at the moment when it is run, mail asks for a subject then Ctrl to send, is there a way this can be done within the script.

Jeremy.

#!/bin/sh
if [ $# -ne 1 ]
then
echo "You Must Use The Correct Syntax"
echo "Syntax: test.sh username"
else
name=$1
if who | grep "$name"
then mail -s "$name has logged on" simmondj@basil.it.net
echo "email sent"
else
echo "$name is not logged on"
fi
fi

perfect_circle 06-16-2005 07:37 AM

Re: Bash Scripting Question
 
Quote:

Originally posted by jsimmonds
Hi below is a script I made. I need to send an email automatically from within this script.


Now at the moment when it is run, mail asks for a subject then Ctrl to send, is there a way this can be done within the script.

Jeremy.

#!/bin/sh
if [ $# -ne 1 ]
then
echo "You Must Use The Correct Syntax"
echo "Syntax: test.sh username"
else
name=$1
if who | grep "$name"
then mail -s "$name has logged on" simmondj@basil.it.net
echo "email sent"
else
echo "$name is not logged on"
fi
fi

I would also try something like:

Code:

then mail -s "$(echo -n "$name has logged on")" simmondj@basil.it.net
Just a wild guess. Don't know if this is going to make any difference.

jsimmonds 06-16-2005 09:07 AM

I don't think that will help my problem.

What difference will thoes alterations make???


All times are GMT -5. The time now is 06:21 AM.