LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Home Forums HCL Reviews Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-04-2017, 11:05 AM   #1
TBotNik
Member
 
Registered: May 2016
Posts: 179

Rep: Reputation: Disabled
EMail Bash Script


All,

Not sure where this post should go, so putting it here. We'll see where the
admins move it to. There should be a BASH subforum under software,
but don't see it.

Anyway have this script for processing emails from Thunderbird to strip off
all the email address from all mails in the system.

Posted the script at:

https://pastebin.com/0abiVEF6

Everything runs great to the point of executing lines 123 & 128.

Line 128 is more problematic as this line always contains blanks and special
characters. Need help getting these 2 line to properly interpret and run.

Thanks!

TBNK
 
Old 05-04-2017, 12:38 PM   #2
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 7,220
Blog Entries: 4

Rep: Reputation: 1746Reputation: 1746Reputation: 1746Reputation: 1746Reputation: 1746Reputation: 1746Reputation: 1746Reputation: 1746Reputation: 1746Reputation: 1746Reputation: 1746
$(grp_srch
there's no closing bracket, and grp_srch is not a command or function.
 
Old 05-04-2017, 02:08 PM   #3
TBotNik
Member
 
Registered: May 2016
Posts: 179

Original Poster
Rep: Reputation: Disabled
Corrected

Quote:
Originally Posted by ondoho View Post
$(grp_srch
there's no closing bracket, and grp_srch is not a command or function.
ondoho,

Thnx, but already saw and fixed that. Now finding the "for" loops not processing at all. Added "echos" there and nothing is showing and target file is blank!

See latest code in the PB!

Cheers!

TBNK

Last edited by TBotNik; 05-04-2017 at 02:11 PM.
 
Old 05-05-2017, 01:00 AM   #4
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 7,220
Blog Entries: 4

Rep: Reputation: 1746Reputation: 1746Reputation: 1746Reputation: 1746Reputation: 1746Reputation: 1746Reputation: 1746Reputation: 1746Reputation: 1746Reputation: 1746Reputation: 1746
$(command) allows one to use output from a command in your script.
however, as i already pointed out, grp_srch is not a command in your script. it's just a string variable.
 
Old 05-05-2017, 01:48 AM   #5
TBotNik
Member
 
Registered: May 2016
Posts: 179

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by ondoho View Post
$(command) allows one to use output from a command in your script.
however, as i already pointed out, grp_srch is not a command in your script. it's just a string variable.
ondoho,

Since I defined/assigned the "grep" command to grp_srch on line 108, not sure what you are trying to say here.

Please elaborate!

Cheers!

TBNK
 
Old 05-05-2017, 01:52 AM   #6
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 7,220
Blog Entries: 4

Rep: Reputation: 1746Reputation: 1746Reputation: 1746Reputation: 1746Reputation: 1746Reputation: 1746Reputation: 1746Reputation: 1746Reputation: 1746Reputation: 1746Reputation: 1746
i see.
try removing the double quotes.
 
Old 05-05-2017, 11:19 AM   #7
TBotNik
Member
 
Registered: May 2016
Posts: 179

Original Poster
Rep: Reputation: Disabled
loop not working

All,

Right now none of the processing loops (#115, #123) are working. Used the same syntax in the functions and they worked there. What am I doing wrong here?

Do I need to "RETURN" the array from the functions to have it seen? Notice the arrays to be processed are from the nested functions and I know BASH handles those with special case but not sure on the syntax for that.

Cheers!

TBNK

Last edited by TBotNik; 05-05-2017 at 11:24 AM.
 
Old 05-05-2017, 11:51 AM   #8
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 7,220
Blog Entries: 4

Rep: Reputation: 1746Reputation: 1746Reputation: 1746Reputation: 1746Reputation: 1746Reputation: 1746Reputation: 1746Reputation: 1746Reputation: 1746Reputation: 1746Reputation: 1746
you didn't remove any double quotes? or at least i don't see it in your pastebin.
try removing the double quotes on lines 118 and 126.
and lose the semicolons, you don't need them at the end of the line.

i think you're going to have to start posting more information. "Doesn't work" is not enough.
 
Old 05-07-2017, 10:44 PM   #9
TBotNik
Member
 
Registered: May 2016
Posts: 179

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by ondoho View Post
you didn't remove any double quotes? or at least i don't see it in your pastebin.
try removing the double quotes on lines 118 and 126.
and lose the semicolons, you don't need them at the end of the line.

i think you're going to have to start posting more information. "Doesn't work" is not enough.
ondoho,

If you have thunderbird installed you can run the code and you'll see it gives:
Code:
bash "/Scripts/TBird&Email/all-TBemails.sh"
Processing LF_Ray!
Processing IM_Ray!
Therefore since the echos inside the loop never show you know those loops are not working.
 
Old 05-10-2017, 11:55 PM   #10
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,417

Rep: Reputation: 2398Reputation: 2398Reputation: 2398Reputation: 2398Reputation: 2398Reputation: 2398Reputation: 2398Reputation: 2398Reputation: 2398Reputation: 2398Reputation: 2398
Here are a couple of useful debugging tricks:

1. start adding echo "<some msg here>" at strategic points to see where your code is and also you can echo (ie print) var names + values.

2. Edit top of program
Code:
#!/bin/bash
set -vx
The latter shows you exactly what the parser is doing
 
Old 05-13-2017, 09:11 AM   #11
TBotNik
Member
 
Registered: May 2016
Posts: 179

Original Poster
Rep: Reputation: Disabled
Updated Code

All,

Updated my code. Still posted at:

pastebin.com/0abiVEF6

Set my "HERE" line @ line 116, because that is where I need help, lines 115-122.

line 117 is working correctly as I pipe this to an output file and get 905 lines-2 for the "Processing" echo statements, shows 903 files, which is correct. Yes that is how many email directories I have in my thunderbird. Your count may vary.

The problem lies in line 119 & 120 as though the assign to array looks right the echo on 120 is blank. Therefore when processing gets to line 143, since the array is blank, nothing happens.

If I can get the array to correctly assign, then this process will work.

Thanks in advance for your help!

Cheers!

TBNK
 
Old 05-13-2017, 09:15 AM   #12
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 10,034

Rep: Reputation: 2952Reputation: 2952Reputation: 2952Reputation: 2952Reputation: 2952Reputation: 2952Reputation: 2952Reputation: 2952Reputation: 2952Reputation: 2952Reputation: 2952
have you tried shellcheck.net to test your script?
There are errors in it....

Last edited by pan64; 05-13-2017 at 09:17 AM.
 
Old 05-13-2017, 10:00 AM   #13
TBotNik
Member
 
Registered: May 2016
Posts: 179

Original Poster
Rep: Reputation: Disabled
Updated Code

All,

Ok have the array assign working. Uncomment line #119 and pipe to output file and you will see the right arrays assigns.

Moved my "HERE" line to #141 as line #142 where the array is to be processed is still showing the array blank. I know there is a different syntax for extracting variables from nested functions in BASH and assume this is what I still have to master here.

All help appreciated!

Cheers!

TBNK
 
Old 05-13-2017, 11:22 AM   #14
TBotNik
Member
 
Registered: May 2016
Posts: 179

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
have you tried shellcheck.net to test your script?
There are errors in it....
pan64,
Shellcheck.net is junk as if I follow what it says the whole thing quits working.

EX:
It says var-$(cmd options) is not valid, but all howtos say that is the only syntax to use when assigning a cmd line cmd to a var. The HOWTOs are right, you get nothing without the surrounding ()s!

It further says get_IMdirs () { is incorrect use get_IMdirs { but that also errors on run as the get_IMdirs () { is required. You can use get_IMdirs { but then you have to use syntax "function get_IMdirs{" which it does not say, so thus the errors.

Please don't send me junk!

Last edited by TBotNik; 05-13-2017 at 11:26 AM.
 
Old 05-13-2017, 12:00 PM   #15
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 10,034

Rep: Reputation: 2952Reputation: 2952Reputation: 2952Reputation: 2952Reputation: 2952Reputation: 2952Reputation: 2952Reputation: 2952Reputation: 2952Reputation: 2952Reputation: 2952
no, shellcheck will highlight your mistakes, and you need to fix them. Keep your code clean (that means without shellcheck errors) and (re-)implement the whole logic.
This now works incidentally. And also remember, it does not work properly at this moment.
 
  


Reply

Tags
bash, scripts, syntax



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
Bash Script send one email after a loop hotdang Programming 4 03-14-2014 02:31 AM
[SOLVED] Bash script to check inodes and Email eyanu Linux - Newbie 10 09-25-2012 04:45 PM
[SOLVED] BASH email script Help cia_gov Linux - Newbie 18 12-11-2011 01:00 AM
[SOLVED] piping email to a bash script for processing mark1967 Programming 11 09-07-2011 03:02 PM
bash script to email updated ip ericnmu Linux - Networking 1 10-01-2004 11:30 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:12 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration