LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > SUSE / openSUSE
User Name
Password
SUSE / openSUSE This Forum is for the discussion of Suse Linux.

Notices


Reply
  Search this Thread
Old 09-15-2015, 02:58 AM   #1
spande
LQ Newbie
 
Registered: Jul 2015
Posts: 6

Rep: Reputation: Disabled
want to use “diff” command on latest 2 files and then send that output on mail


Hello All,

On suse linux, I am having below files in one same folder and from that all files I want to use diff command on latest 2 files and want to save output of diff command in one separate file and then want to send that file through mail as attachment. I want to do this on weekly basis.
Can you please help me on this.
Thanks in advance.. :-)

-rw-r--r--. 1 root root 4.2K Aug 27 00:22 10.10.10.10_2015_08_27.cfg
-rw-r--r--. 1 root root 124 Sep 3 00:23 10.10.10.10_2015_09_03.cfg
-rw-r--r--. 1 root root 124 Sep 4 00:00 10.10.10.10_2015_09_04.cfg
-rw-r--r--. 1 root root 124 Sep 5 00:00 10.10.10.10_2015_09_05.cfg
-rw-r--r--. 1 root root 124 Sep 6 00:00 10.10.10.10_2015_09_06.cfg
-rw-r--r--. 1 root root 124 Sep 7 00:00 10.10.10.10_2015_09_07.cfg
-rw-r--r--. 1 root root 124 Sep 8 00:00 10.10.10.10_2015_09_08.cfg
-rw-r--r--. 1 root root 124 Sep 9 00:00 10.10.10.10_2015_09_09.cfg
-rw-r--r--. 1 root root 124 Sep 15 01:47 10.10.10.10_2015_09_11.cfg

Last edited by spande; 09-15-2015 at 04:29 AM.
 
Old 09-16-2015, 06:45 AM   #2
cliffordw
Member
 
Registered: Jan 2012
Location: South Africa
Posts: 509

Rep: Reputation: 203Reputation: 203Reputation: 203
Hi,

Something along these lines should do the trick:

Code:
#!/bin/bash
cd /some/directory/containing/the/files || exit 1
typeset -a files
files=(`ls -1t`)
last=${files[0]}
prev=${files[1]}
if [ -z "$prev" ]
then
  echo "not enough files"
  exit 1
fi
echo $prev $last > separate_file.diff
mail -s "difference" spande@example.com < separate_file.diff
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Formatting output of diff command rafiki8 Linux - Newbie 5 03-21-2012 05:59 PM
[SOLVED] how to send the output of send command to a file auma78 Linux - Newbie 2 01-23-2011 12:06 AM
Debian etch - Unable to send mail from command line or from php mail command lqforumuser Linux - Newbie 1 03-01-2009 06:56 AM
can mail command be used to send mail onto global mail servers like yahoo etc dale_chip Linux - Newbie 4 08-12-2008 08:33 AM
command line email client to send mail to remote mail server dhanju Linux - Software 1 03-07-2008 06:37 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > SUSE / openSUSE

All times are GMT -5. The time now is 08:36 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration