LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-13-2007, 01:37 PM   #1
Snouffelaire
LQ Newbie
 
Registered: Mar 2007
Location: France
Distribution: Ubuntu 9.04
Posts: 15

Rep: Reputation: 0
[Solved]how to set a var that is what was last written in the shell


Hello there !

Ok, so here's the thing. I've wrote a script to send sms using gammu. The problem is that sometimes if my cell has no network, it will give me an error. In that case I would like my script to try and send the message again.

Here is the last thing my script does :

echo "$message" | gammu --sendsms TEXT $number

after what, two possibilities :
->gammu says "waiting for network answer..OK, message reference=237"
->gammu says something like "waiting for network answer... error, message reference=-1"

An easy way for me to test if the sms was sent would be to be able to assign to a var this sentence and then for example test its length or the last two characters.
So, does anyone know how to do that ?

Thanks and please be specific as it's my first script .

Last edited by Snouffelaire; 03-13-2007 at 02:26 PM.
 
Old 03-13-2007, 01:45 PM   #2
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
Code:
message=`echo "$message" | gammu --sendsms TEXT $number`
Those are accent marks, not single quotes around the string. However, an easier way is probably to check the return code:

Code:
echo "$message" | gammu --sendsms TEXT $number
RC=$?
if [ "$RC" != "0" ]
then
   echo "Error: $RC from gammu"
fi
 
Old 03-13-2007, 02:25 PM   #3
Snouffelaire
LQ Newbie
 
Registered: Mar 2007
Location: France
Distribution: Ubuntu 9.04
Posts: 15

Original Poster
Rep: Reputation: 0
Thank you for such a rapid answer ! it works fine
 
  


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
/var/log/messages no longer being written to Mehuge Fedora 8 02-04-2008 10:58 PM
how to set permissions on /var/www? AVD_ZM Linux - Newbie 1 03-04-2007 11:27 AM
reading file written by shell using C kapil_dev Programming 9 09-10-2005 12:11 AM
How do you set a shell script var with a literal '*'? BrianK Programming 3 06-22-2004 02:11 PM
is it safe to set /var to chmod 777 carlosruiz Linux - Security 4 12-31-2003 04:00 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:54 AM.

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
Open Source Consulting | Domain Registration