Sponsored Content
Top Forums UNIX for Dummies Questions & Answers direct output to a file then email it Post 302146464 by Smiling Dragon on Tuesday 20th of November 2007 06:02:54 PM
Old 11-20-2007
You can stream the whole thing directly into an email if you play about with sockets (which I'm cr@p at in shell so I won't try and show you how), but otherwise you can go with your idea of using a temporary file like so:
Code:
#!/bin/ksh
sendmail="/usr/lib/sendmail"
recipient="recipient@there.com"
sender="me@here.com"
tempfile="/tmp/mailthingy.$$"
print "To: $recipient" > $tempfile
print "From: $sender" >> $tempfile
print "Subject: some stuff\n" >> $tempfile
print "AL" >> $tempfile
print "AM" >> $tempfile
print "AN" >> $tempfile
print "RL\n" >> $tempfile

nawk '/PROD/ {print $3, $2}' /home/user/switch_listtest | sort -k1,2 >> $tempfile
print "End of Report" >> $tempfile
if cat $tempfile | $sendmail $recipient
then
    print "Ok"
    rm -f $tempfile
    exit 0
else
    print "Barf!"
    print "Tried to send the message contained in the following file to $recipient but failed:"
    print "$tempfile"
    exit 1
fi

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to direct awk output to expr?

Is there any way to combine the following two statements into one? I can't figure out how to get expr to take input from the output of the awk call - I've tried piping the output of the awk call into the expr call, and tried using a 'Here' document, nothing seems to work. export CNT=`wc -l... (4 Replies)
Discussion started by: jvander
4 Replies

2. Shell Programming and Scripting

Direct the output of a script to a log file

Hi, I have a script to compare 2 files. file1=$1 file2=$2 num_of_records_file1=`awk ' END { print NR } ' $file1` num_of_records_file2=`awk ' END { print NR } ' $file2` i=1 while do sed -n "$i"p $file1 > file1_temp sed -n "$i"p $file2 > file2_temp diff file1_temp... (5 Replies)
Discussion started by: autosys_nm
5 Replies

3. Shell Programming and Scripting

how to direct scp output to a file in bash shell or script

I can run this from the command line: scp -i identfile /path/file_to_send remotelogin@remotebox:/path_to_put_it/file_to_send and I get: file_to_send 100% |***************************************************************************| 0 00:00 but if I do: scp -i identfile... (6 Replies)
Discussion started by: NewSolarisAdmin
6 Replies

4. Shell Programming and Scripting

Shell script to email based on flat file output

Hi All, I am a newbee in unix but still have written a shell script which should trigger a mail based on certain conditions but the problem is that my file is not being read. Below is the code please advise. I do not know where is it failing. Note $ and the no followed with it is the no of... (1 Reply)
Discussion started by: apoorva
1 Replies

5. Solaris

Outbound email re-direct using Sendmail

I need to reconfigure Sendmail to strip the SMTP email addresses from all email and replace them with a single address used for testing purposes. I have a vended application hosted on Solaris 10 servers. I have access to support the application framework (IBM WebShere Application Server 6.1),... (1 Reply)
Discussion started by: dunkar70
1 Replies

6. Shell Programming and Scripting

Manipulating sed Direct Input to Direct Output

Hi guys, been scratching round the forums and my mountain of resources. Maybe I havn't read deep enough My question is not how sed edits a stream and outputs it to a file, rather something like this below: I have a .txt with some text in it :rolleyes: abc:123:xyz 123:abc:987... (7 Replies)
Discussion started by: the0nion
7 Replies

7. UNIX for Dummies Questions & Answers

Output of ssh command from localhost - direct to local file.

Hi, i'm trying to gather details from remote hosts and want them to be written to my local linux machine from where i'm using SSH. My command looks some thing like this ssh -q remotehost 'bash -s' <command.txt where command.txt is a file in my local machine containing ps -ef |grep httpd |... (1 Reply)
Discussion started by: poga
1 Replies

8. Shell Programming and Scripting

Disk Space Script to direct output

Hi, I am working on Sun Solaris 5.10 and want to direct the output from a disk space check script to an output file; #!/bin/bash CURRENT=$(df -k /log/logs | grep /log/logs | awk '{ print $5}' | sed 's/%//g') THRESHOLD=30 if ; then echo "Remaining free space is low" > output.txt else... (10 Replies)
Discussion started by: SSKAAB
10 Replies

9. UNIX for Dummies Questions & Answers

Cronjob output to file AND to email (as attachment)

I have a shell script that runs on our webserver logs, and grabs various useful data and then outputs this data to a .csv file. What I want to do now is schedule a cronjob to run this script for me each week at a designated time, AND email the .csv file that is created as an attachment to... (1 Reply)
Discussion started by: xdawg
1 Replies

10. Shell Programming and Scripting

For loop in bash - Direct output to two files

Hello all, i have a code in which when doing a for loop, i need to direct the output to two files, one just a single output, the other to always append (historical reasons). So far i managed to do the following, which is working, but am still considering it as "dirty". ... (4 Replies)
Discussion started by: nms
4 Replies
Test::TempDir(3pm)					User Contributed Perl Documentation					Test::TempDir(3pm)

NAME
Test::TempDir - Temporary files support for testing. SYNOPSIS
use Test::TempDir; my $test_tempdir = temp_root(); my ( $fh, $file ) = tempfile(); my $directory_scratch_obj = scratch(); DESCRIPTION
Test::TempDir provides temporary directory creation with testing in mind. The differences between using this and using File::Temp are: o If "t/tmp" is available (writable, creatable, etc) it's preferred over $ENV{TMPDIR} etc. Otherwise a temporary directory will be used. This is "temp_root" o Lockfiles are used on "t/tmp", to prevent race conditions when running under a parallel test harness. o The "temp_root" is cleaned at the end of a test run, but not if tests failed. o "temp_root" is emptied at the begining of a test run unconditionally. o The default policy is not to clean the individual "tempfiles" and "tempdirs" within "temp_root", in order to aid in debugging of failed tests. EXPORTS
temp_root The root of the temporary stuff. tempfile tempdir Wrappers for the File::Temp functions of the same name. The default options are changed to use "temp_root" for "DIR" and disable "CLEANUP", but these are overridable. scrach Loads Directory::Scratch and instantiates a new one, with the same default options as "tempfile" and "tempdir". SEE ALSO
File::Temp, Directory::Scratch, Path::Class VERSION CONTROL
This module is maintained using Git. You can get the latest version from <git://github.com/nothingmuch/test-tempdir.git>. AUTHOR
Yuval Kogman <nothingmuch@woobling.org> COPYRIGHT
Copyright (c) 2008 Yuval Kogman. All rights reserved This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.10.0 2009-08-11 Test::TempDir(3pm)
All times are GMT -4. The time now is 08:42 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy