0

I've written a simple shell script.

count=`mailq -v`
var=$(mailq -v)
echo "$var" > /home/xxxxxx/textis.txt

It works fine and outputs the result of mailq to the txt file no problem. However when I add one line and change it to

count=`mailq -v`
var=$(mailq -v)
echo "$var" > /home/xxxxxx/textis.txt
(cat mailtext; uuencode /home/xxxxxx/textis.txt /home/xxxxxx/textis.txt) |
    mail -s "Mail Queue alert" xxxxxx.orr@gmail.com

Which just adds the mailing line it now doesn't update the file.

I'm really new at shell scripts and have been trying to figure this out for a day now so any help would be great

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
user1616338
  • 557
  • 1
  • 8
  • 24
  • I've tested both versions of this script and both seem to work for me (once I made minor changes to suit my system). Could you clarify that it is `textis.txt` that is not updated in the second version of the script? Parenthetically, I note that the first line of either script has no purpose because `count` is not subsequently used. That is the only thing I can see wrong with the script, though. – Simon Dec 31 '16 at 23:19
  • If, as a test, you replace `mailq -v` with `date` (the output of which is guaranteed to change every second), does `textis.txt` still not change as a result of the second script? – Simon Dec 31 '16 at 23:21
  • The `uuencode` command doesn't modify the file it is processing. It isn't the best choice of encoding (Base-64 is better). – Jonathan Leffler Dec 31 '16 at 23:30
  • 2
    Why do you have both ```count=`mailq -v` ``` and `var=$(mailq -v)`? Why the two notations, and why capture the same information twice? Use the `$(…)` notation and not the older back-quotes notation. – Jonathan Leffler Dec 31 '16 at 23:31
  • I think you're using `uuencode` wrong. It's `uuencode [in] out`. The way you're invoking it, it's not going to write anything to the `|mail` process. I think maybe you mean `uuencode – Waxrat Dec 31 '16 at 23:34
  • 1
    @Waxrat: at least on macOS Sierra, `uuencode` always unconditionally writes to standard output. It takes two names as you suggest, but the `out` name is the name used in the `begin` line. For example, running `uuencode fa37.sh function-array.sh` generates output starting `begin 644 function-array.sh`, reading the input from `fa37.sh`. When the `in` file isn't specified, the input comes from standard input (`uuencode < fa37.sh function-array.sh` also generates output on standard output that starts `begin 644 function-array.sh`). – Jonathan Leffler Dec 31 '16 at 23:38
  • @Jonathan Leffler: You're right. I stand corrected. – Waxrat Dec 31 '16 at 23:42
  • 1
    thanks for the replies. textis.txt is used to store the output of the mail queue command and it's missing from the second part cause i can't copy and paste :( I used uuencode because it was the only way i could find to get the attachment to be readable when it was sent. I'm wondering if thereis something wrong with my serve config since Simon can get it to work and i should be able to pass the text file without the encode? – user1616338 Jan 01 '17 at 10:30

0 Answers0