LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-13-2009, 08:21 AM   #1
masood24
LQ Newbie
 
Registered: Dec 2009
Posts: 5

Rep: Reputation: 0
shell script to search all the files starting with name failed.* and send via email


hello guys,
I am new to linux i want to write a script,
what i want is that script should search for all the files that are starting with a neme of failed.xyz
And if found something then that file should be sent to me via email, and if nothing is found delete the rest of the files,

The files that are created are with following name format failed_abc.txt.2009-11-28-17-3 and so on,

I will appreciate your help,

I saw lots of scripts but i am unable to understand even if i search some of the functions from google,

Please suggest some simple book or any tutorial of simple batch programming or the functions that are mostly used to check like character streams or do different things

Thanks in advanc.!!!
 
Old 12-13-2009, 09:17 AM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian + kde 4 / 5
Posts: 6,837

Rep: Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981
This isn't the place for teaching the basics of bash scripting. I suggest you spend a few hours working through the linuxcommand.org tutorial, which should be enough to get you started.

I also think you have to be a bit more specific in your requirements. Would you only search the current working directory, a specified directory, or the whole system, for example? Also, what do you want to do with the matching files after you've mailed out (copies of) them? Can those deleted too, or are they to be left alone, stored in a different directory, or what? It's little things like these that can affect the exact format of the scripting commands used.

But in general, this is rather easy task. It would generally take just a simple "for" loop to iterate through all the files in the input and run the necessary commands on what it finds, and perhaps an "if" statement to test each file separately, depending on your exact requirements.
 
Old 12-13-2009, 09:30 AM   #3
masood24
LQ Newbie
 
Registered: Dec 2009
Posts: 5

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by David the H. View Post
This isn't the place for teaching the basics of bash scripting. I suggest you spend a few hours working through the linuxcommand.org tutorial, which should be enough to get you started.

I also think you have to be a bit more specific in your requirements. Would you only search the current working directory, a specified directory, or the whole system, for example? Also, what do you want to do with the matching files after you've mailed out (copies of) them? Can those deleted too, or are they to be left alone, stored in a different directory, or what? It's little things like these that can affect the exact format of the scripting commands used.

But in general, this is rather easy task. It would generally take just a simple "for" loop to iterate through all the files in the input and run the necessary commands on what it finds, and perhaps an "if" statement to test each file separately, depending on your exact requirements.


Hello,

Yes Brother first of all thanks for your time and suggestions,
Yes exactly it will take a simple loop and a condition to check,

1)i just need to run the script and check those files from a specific directory lets suppose from a directory called "abxdirectory", only from one directory in which they are stored,

2). If any thing is found in the file(usualy csv file is formed)do following task:

b) IF something found in one or more files Attacht a copy of all those files and via email. and delete the rest of the files which are empty

3) Delete all the files if all are empty.


Rgards,
Masood
 
Old 12-13-2009, 02:40 PM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
You could break the task down into smaller pieces and figure out how to do them from the command line then stitch the bits together in a script.

First off, how do you send mail from the command line? Some ideas here.

Then how can you mail yourself? Do you mean yourself on the Internet or yourself on the local computer? If "on the Internet" then you will need something running on the computer that can send mails to a mail server on the Internet (a thread in itself!).

Once you can mail yourself from the command line, how can you attach a file? Some ideas here.

Then, how do you find any files you might want to mail? Some ideas here.

Divide and rule! Never bite off more than you can chew!
 
1 members found this post helpful.
Old 12-13-2009, 06:06 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,417

Rep: Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397
You may find these tutorials useful
http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
send email to server to start shell script bic Red Hat 5 12-04-2009 10:06 AM
How to search for missing files and pass their names on to another shell script djslothario Linux - Newbie 3 08-07-2009 01:59 AM
Having a problem getting my shell script to send an email after each row. mgsmith7475 Linux - Newbie 3 04-27-2009 09:28 PM
write a shell script to send email yenonn Programming 4 02-11-2005 11:06 PM
send email through shell mikeshn Linux - General 10 01-01-2004 03:35 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:36 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration