Script that performs action when receiving an SMS.

My case is the following: -I have a Linux system where I have an smsd installed (SmsTools3)

-This system works through a GSM module in which I can send and receive text messages.

-Text messages arrive in a certain folder ( / var / spool / sms / incoming )

-I need a script that does different things in response to an incoming SMS to the "Incoming" directory.

The idea is that each time an SMS arrives, the system analyzes the folder where these messages are received, choose the most RECENT message and execute an action on the system. What I have at the moment is this:

-------------------------------------------------- -------------------------------------------------- --------------------------------------------------

<#! / bin / bash
  #Declaration 



DIRECTORY = / var / spool / sms / incoming 

PATRON = 'Reset'
 

# Search 

ls -lt $ DIRECTORY && grep -iqrl $ PATRON $ DIRECTORY / * 



if [$? -eq 0]; then 

PLACE = $ (grep -irl $ PATRON $ DIRECTORY / *) 

echo "The pattern $ PATRON was located at $ PLACE." 

else 

echo "The pattern $ PATRON was not found in the files present within $ DIRECTORY." 

fi>

-------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -
ANSWER:

root @ AcerNitro5: / home / halley # ./script3.sh
 total 8 -rw-r - r-- 1 root root 54 Mar 1 11:07 test2 -rw-r - r-- 1 root root 74 Mar 1 10:18 test1 

The Reset pattern was located in / var / spool / sms / incoming / test 2 / and var / spool / sms / incoming / test2 .
-------------------------------------------------- -------------------------------------------------- --------------------------------------------------

  • I still have a lot to complete ... I'm a little lost on how to make the script select the text file (SMS incoming incoming) more RECENT where there is a pattern "Reset" and then run a reboot to the system.

Welcome to the forum.

A few comments first:

  • Please use code tags to improve readability and understandability of your code and data.
  • exercise utmost care when composing your spec: a leading (or missing) slash can make a huge difference in the functioning (or mal-) of your script (here: /var vs var )
  • WAY too many spaces. Your code given above will not run. NO spaces around = and / , and following $ . Too few around [ and ] .

When reading your request, my first thought was: a system like that should have hooks (or so) to trigger actions on events like incoming mail. Et voila, from the project homepage:

Did you consider that functionality, which is to be preferred over repeatedly listing directory contents?

No, do not consider it because I am a beginner in these subjects. I regret violations of the rules, but if I made myself understood, I would like to know how to do what you tell me.

I'm afraid I can't give you more than general hints as I don't know the product. I found the "trigger external program" feature mentioned by just glancing at their web page. How about working from the ground up - read the product's man page, web site, look into the samples given, and try setting up a test system, managing / modifying the configuration until satisfied?