this is just a pointer: whichever way you do it, keeping files in the same directory means the time consumed by the filter will increase as files increase thus making the process slower and slower by every new file
On 16 June 2012 23:38, Odhiambo Washington <odhiambo@gmail.com> wrote:
On Sat, Jun 16, 2012 at 1:38 PM, Thuo Wilson <lixton@gmail.com> wrote:On 16 June 2012 13:28, Odhiambo Washington <odhiambo@gmail.com> wrote:
On Sat, Jun 16, 2012 at 12:57 PM, Thuo Wilson <lixton@gmail.com> wrote:
I have a bash scripting question that has really bothered me;First i want to list files in a directory with a command - no probSecond - i want to get the name of the file - no problemThird i want to read the content of the file - no problemFourth i want to extract some information , column and rows from the file - no problemMy Idea:>My idea is to receive sms and forward to an email - working file but only one at a time! #script 1
>second is whenever a reply is sent from the email address "x" with subject "$CELLPHONE $MESSAGE" the script is called by clone to send the sms to user $cellphone - working file but only one at a time! #script 2
Problem:The directory contains multiple files with dynamic names (generated by system) some properties being date,time and cellphone numberThe problem is i don't know how to read multiple files name, read content to a file for processing at a go and output the results into another file using bash.No 2 - i want the filename of the other files....in the same directory and each file to be called one at a time.take examplecd /tmp-rw-r--r-- 1 root root 0 Jun 16 12:42 a.2012.1242pm
-rw-r--r-- 1 root root 0 Jun 16 12:42 b.2012.1243pm
-rw-r--r-- 1 root root 0 Jun 16 12:42 c.2012.1244pm
-rw-r--r-- 1 root root 0 Jun 16 12:42 d.2012.1245pm
-rw-r--r-- 1 root root 0 Jun 16 12:42 e.2012.1246pm
bear in mind the files are generated randomly and have no control over that :)- so to speak for question purposes
I have the below script to read one line at a time and move what is read to another folder - not good practice. I would want to retain the file in same folder but my bash script should know that the file is read!How do i perfect this: This reads a file at a time and sends an email but if multiple are received at a go - all the rest iregardless are moved to the tmp2 folder.#!/bin/bashcd /tmp^^^^^^^^^^^^^^^^^^^^^^^^ Replace this line.mv /tmp/$f /tmp2/
You could perfect that by appending a timestamp to /tmp2/$f so that there is no name clash the next day :-)
Hi Wash,
That could only deal with only one issue. Any files that comes later that when the dir files are listed.mv /tmp/$f* /tmp2
done
Why do use the asterisk in there? $f* ?
Looking at example above... if multiple files are listed, only one file (1st one is read) and the rest "only content is read using "cat"In all those files, how many matches do you get when parsing for the content you want?
For instance:
find . -type f -exec grep -li 'SOME_STRING' {} \;
If only 1 file matches, then you can use substitution to get the file, perhaps:
for f in ` find . -type f -exec grep -li 'SOME_STRING' {} \;`; do
cat $f ....This will output content of the file :(What MTA do you use BTW? Postfix?Wilson
doneNow for reading an email reply file from above:Well this will send BUT only one at a time and if multiple emails are received at a go - all the others are deleted!How do i perfect this....
#!/bin/bashfor i in 30 (corresponds to a linux user email box line 30 where subject is)
do
awk -v a=$i 'NR==a {print $0}' /var/spool/mail/root > testfile2
cat /dev/null > /var/spool/mail/root
echo `cat /root/testfile2` | /usr/bin/gammu --sendsms TEXT `awk '{print $2}' testfile2`
Use the same idea as above. Appending a timestamp will make files unique.
Well if i want the SMS sent, i must read the conntent. timestamp may not help if i can be able to read all the files and perse the output to diffrent files or even one for sms delivery :)
I am not sure I understand you, and as such I may come out as more misleading :)
- i can use postfix/sendmail.
I think I have somewhere a script that can help you in this endeavor, but I only used it with Exim.may i look into the script, may be it has what i want...
--
Best regards,
Odhiambo WASHINGTON,
Nairobi,KE
+254733744121/+254722743223
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
I can't hear you -- I'm using the scrambler.
_______________________________________________
Skunkworks mailing list
Skunkworks@lists.my.co.ke
------------
List info, subscribe/unsubscribe
http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks
------------
Skunkworks Rules
http://my.co.ke/phpbb/viewtopic.php?f=24&t=94
------------
Other services @ http://my.co.ke
_______________________________________________
Skunkworks mailing list
Skunkworks@lists.my.co.ke
------------
List info, subscribe/unsubscribe
http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks
------------
Skunkworks Rules
http://my.co.ke/phpbb/viewtopic.php?f=24&t=94
------------
Other services @ http://my.co.ke