Need help with UNIX script variables

Posted on 2008-02-04
Medium Priority
Last Modified: 2012-05-05
I have a UNIX shell script,  with these two vairables

They represent two email adresses; I want to send an email form my script using the two variables. This is my code.

echo "${WARNING_MSG} ${RESULT_MSG}" | mailx -s "$SCRIPT error on $SERVER_NAME" "${CONTROL_TEXT_1} ,  ${IT_LIST}"

I can't get it to send to either of the email adresses. Can someone tell me if my coding (using the quotes) is correct? Remeber.. this is sendign email adresses and I want to send to two persons
Question by:joekeri
LVL 48

Expert Comment

ID: 20817981
You quotes are correct.

See what happens when you add the -v flag to mailx.  This will output debug output.

Author Comment

ID: 20818148
Can i use -v along with the -s   at the same time?
LVL 48

Accepted Solution

Tintin earned 150 total points
ID: 20818171
Yes, just do

echo "${WARNING_MSG} ${RESULT_MSG}" | mailx -vs "$SCRIPT error on $SERVER_NAME" "${CONTROL_TEXT_1} ,  ${IT_LIST}"
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.


Expert Comment

ID: 20821720
here is "mailing" script I wrote 4 years ago:

although it is perl and not shell, I can tell you that for perl you can put "- , @" in the subject
for shell I know that "," is forbidden in the subject (or more problematic)


#!/usr/local/bin/perltk -w
print "\n\n### Script by Tal Mashraky - $PROJECT Project ###\n\n";
$dul_str = "ls -lR /dumps/$ENV{'HOST'}/*/* | sort -k 5 -nr | grep trn";
@dul = qx ( $dul_str ); # | sort -k 5 -r | grep trn");
$loc_str = "\du -sk /local_project/*/*";
@loc = qx ( $loc_str ); # | sort -k 5 -r | grep trn");
$dusk_str = "\du -sk /dumps/$ENV{'HOST'}/*/* | sort -nr";
@dusk = qx ( $dusk_str );
@du = sprintf ("command: \du -sk : units are [Kbytes] \n%s\n@dusk\n","#"x30);
print @du;
print "\n\n@dul\n\n";
$mail_list = "";
$mail = "all";
my @params = @ARGV;
foreach $param (@params) {
    if($param eq "-no_mail") {
        $mail = "only_user";
foreach $line (@dul) {
    $line =~ /.*\s+(\w+)\s*ftp/;
    if ($mail_list =~ /$1/) {
    } else {
        #$mail[$1] = $1;
        $mail_list .= $1.",";
foreach $line (@dusk) {
    $line =~ /^\s*(\d+).*\/(\w+)$/ && $1>=1000;
    ($size , $name)  = ($1 , $2);
    if ($line =~ /^\s*(\d+).*ncsim.*\.(\w+)\.\d+[A-Z][a-z]{2}/) {
        # dollar 1 override
    unless ($mail_list =~ /$2/ || $size<1000) {
        $mail_list .= $2.",";
    print "dollar 1 = $size \n";
$mail_list .= "talm";
print "mail_list= $mail_list\n\n";
if ($mail eq "only_user") {
    $mail_list = "$ENV{'USER'}";
    print "FIXED mail_list= $mail_list\n\n";
$mail_str = "\du -sk /dumps/$ENV{'HOST'}/*/* | sort -nr | mail -s \"clear dumps on /dumps/$ENV{'HOST'}/* - by scr
ipt\" $mail_list";
print "$mail_str\n";
system ($mail_str);

Open in new window

LVL 17

Expert Comment

by:Hanno P.S.
ID: 20823807
Don't use
  mailx -s "$SCRIPT error on $SERVER_NAME" "${CONTROL_TEXT_1} ,  ${IT_LIST}"
rather than
  mailx -s "$SCRIPT error on $SERVER_NAME" "${CONTROL_TEXT_1}" ,"${IT_LIST}"
LVL 17

Expert Comment

by:Hanno P.S.
ID: 20824027
... and what was your problem?

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question