How to bash or shell after running the command "echo df | gnokii --sendsms 73459045567" to check the sending of SMS? I mean to write the result of the execution into a variable and then see if the keyword is there: "succeeded". Since it shows the text in the terminal: "Send succeeded!". I tried to write to a variable, but for some reason it returns void anyway.
2 answers
It is difficult to say what exactly you had a mistake.
- I did not understand what
my
, but I hadn’t written on a bash for a long time, maybe something new had been introduced there. - At assignment, variables are specified without a dollar sign.
- There are no spaces around
=
when assigning. - gnokii throws everything out of error in stdout, but in stderr, this should be taken into account and redirected.
- Further generally some PHP went. It feels like I did not understand what you need.
However, this code works for me:
msg="Yo nigga wazzup?" phone="79001234567" result=$(echo $msg | gnokii --sendsms $phone 2>&1) if [[ $result == *"succeeded"* ]]; then echo "Успешная отправка" else echo -e "Ошибка отправки на номер $phone \n" fi
- maybe there is something new introduced - not entered. this is the author of the question tried to invent a new language "perl-i-sh". - aleksandr barakin
|
my $result = `echo $msg | gnokii --sendsms $phone`; if ($result=~/succeeded/){ print "успешная отправка" }else{ print "Ошибка отправки на номер ".$phone."\n"; }
But for some reason, in my $ result variable, the void is anyway.
|