capser
capser

Reputation: 2635

Echo out a variable like cat in a string

I have a sql statement that results in a little table of values. I have to look at it every day can compare it to yesterdays. I am sick of doing this.

/big/database/v10.2.0.2.0-32bit/bin/sqlplus -S casper/secret@wowmomdb2 @/home/casper/installed.sql

So I made a little script.

#!/bin/bash
set -x
dayofweek=$(/bin/date +%w)
today=$(/bin/date +%Y%m%d)
if [ $dayofweek == 1 ] ; then
   yesterday=$(/bin/date -d "3 days ago" +%Y%m%d)
   else
   yesterday=$(/bin/date -d "1 day ago" +%Y%m%d)
fi

invoke="/big/database/v10.2.0.2.0-32bit/bin/sqlplus -S "
login="casper/secret@wowmomdb2 "
filter="@/home/casper/installed.sql"
installed="/home/casper/_symbols"

table="$invoke $login $filter"
$table > $installed.$today

echo "Installed Today --------
$installed.$today

Installed Yesterday --------
$installed.$yesterday "  | mail -s "diff exchange installed" casper@big_bank.com

#/big/database/v10.2.0.2.0-32bit/bin/sqlplus -S casper/secret@wowmomdb2 @/home/casper/installed.sql  > /tmp/check_c4_exchange.$today

problem is this is want i get mailed to me.

Installed Today--------
/home/casper/_symbols.20141104
Installed Yesterday----
/home/casper/_symbols.20141105

What i want is todays and yesterdays little table printed out and emailed to me so I can look at it in the morning. I want the tables catted out. _ but i don't want to use all kinds of echos - like you know echo out each line. ~

Upvotes: 1

Views: 73

Answers (2)

John1024
John1024

Reputation: 113834

The problem is that $installed.$today is the name of a file. You want the contents of the file. Try:

echo "Installed Today --------
$(cat $installed.$today)

Installed Yesterday --------
$(cat $installed.$yesterday) " 

More Efficient Alternative

If you are using bash, then it is not necessary to use cat:

echo "Installed Today --------
$(<$installed.$today)

Installed Yesterday --------
$(<$installed.$yesterday) " 

This approach avoids the need to spawn subshells in which to run cat, making it more efficient.

Upvotes: 1

John Zwinck
John Zwinck

Reputation: 249123

You can attach files by using mutt instead of mail (other programs may be available on your system too):

echo "..." | mutt -s "diff exchange installed" \
  -a $installed.$today -a $installed.$yesterday casper@big_bank.com

Upvotes: 0

Related Questions