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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
12-13-2009, 07:21 AM
|
#1
|
LQ Newbie
Registered: Dec 2009
Posts: 5
Rep:
|
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.!!!
|
|
|
12-13-2009, 08:17 AM
|
#2
|
Bash Guru
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852
|
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.
|
|
|
12-13-2009, 08:30 AM
|
#3
|
LQ Newbie
Registered: Dec 2009
Posts: 5
Original Poster
Rep:
|
Quote:
Originally Posted by David the H.
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
|
|
|
12-13-2009, 01:40 PM
|
#4
|
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
|
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.
|
12-13-2009, 05:06 PM
|
#5
|
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.x
Posts: 18,434
|
|
|
|
All times are GMT -5. The time now is 12:32 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|