
I have a bash scripting question that has really bothered me; First i want to list files in a directory with a command - no prob Second - i want to get the name of the file - no problem Third i want to read the content of the file - no problem Fourth i want to extract some information , column and rows from the file - no problem My 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 number The 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 example cd /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/bash cd /tmp for f in "`ls`"; do cat $f | mail -s "$f" lixton (ati) gmail.com mv /tmp/* /tmp2 done *Now 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/bash for 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` Would possibly have VIRTUAL users where each has a mailbox qmail format. Help.... Wilson.