LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training 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-07-2017, 10:58 PM   #1
TBotNik
Member
 
Registered: May 2016
Posts: 179

Rep: Reputation: Disabled
Bash Fullpath


All,

From the directory:
Code:
/home/$user/.thunderbird/$profile/ImapMail/
I'm running the cmd:
Code:
ls -aR /home/$user/.thunderbird/$profile/ImapMail/ | grep -i $dir
In this case $dir=sent and so I get:
Code:
Sent.msf
Sent Mail
Sent Mail.msf
Sent-1
Sent-1.msf
Sent.msf
Sent Mail
Sent Mail.msf
Sent.msf
Sentry Telecom
Sentry Telecom.msf
Sentry Telecom
Sentry Telecom.msf
Sent
Sent.msf
I need to process the files that have no extensions, yes they are files, not directories. However the directory:
Code:
/home/$user/.thunderbird/$profile/ImapMail/
contains the following subdirectories:
Code:
imap.gmail.com
imap.gmail-1.com
In order to process the files I have to have the full path & filename, but all the HOWTOs I've looked at talk about "fullpath" in all other terms from what I need.

If you either know how to do this, or know the right HOWTO, please pass along the info, so I can finish my script.

Thanks!

TBNK
 
Old 05-07-2017, 11:18 PM   #2
TBotNik
Member
 
Registered: May 2016
Posts: 179

Original Poster
Rep: Reputation: Disabled
Files

All,

The files that will process from this list are:
Code:
Sent Mail
Sent-1
Sent Mail
Sentry Telecom
Sentry Telecom
Sent
But these are not dups, but in different subdirectories.

The code that will process on these will be:
Code:
grep '^\(From\|To\|Cc\|CC\Bcc\|BCC\):' $fullfilename grep -o -E '[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}' | sort -f | uniq -i >> $adr_mst;
But cannot process without the fullfilename that includes the fullpath, therefore the output file is always empty.

I have all this working in a hardcoded version, but other users will have directories unique to themselves, so attempting an autofinding version, that all TBird users can use.

Cheers!

TBNK

Last edited by TBotNik; 05-07-2017 at 11:37 PM.
 
Old 05-07-2017, 11:29 PM   #3
TBotNik
Member
 
Registered: May 2016
Posts: 179

Original Poster
Rep: Reputation: Disabled
Extension Elimination

All,

Able to eliminate the files with extensions with the following code:
Code:
		imfil=$(basename "$imdir");
		imext="${imfil##*.}";
		if [[ "$imfil" == "$imext" ]]; then
Because the file basename and the extension are the same value, when there is not file extension.

Cheers!

TBNK
 
Old 05-08-2017, 12:33 AM   #4
TBotNik
Member
 
Registered: May 2016
Posts: 179

Original Poster
Rep: Reputation: Disabled
Actual Code

All,

The actual code I'm running is a function:

Code:
get_IMdirs () {
	#############################################################################
	# Modified: 	Nyle Davis			Mod Date: 17-04-25
	# Purpose:		Get all "ImapMail" subdirectories
	# Vars:			
	#############################################################################
	declare -a im_ray=();
	declare -a im_dirs=();
	imsub=${dir%:};
	xx=0;
	SAVEIFS=$IFS;
	IFS=$(echo -en "\n\b");
	im_dirs=$(ls -R $imsub);
	for dir in ${im_dirs[@]}; do
		imdir=${dir%:};
		imfil=$(basename "$imdir");
		imext="${imfil##*.}";
		echo "P=> $imsub F=> $imfil E=> $imext";
		if [[ "$imfil" == "$imext" ]]; then
			im_ray[$xx]=${imsub}${imfil};
			echo "IR=> ${imsub}${imdir}";
			((xx=xx+1));
		fi
	done
	IFS=$SAVEIFS;
}	# end function get_IMdirs
where dir='/home/$user/.thunderbird/$profile/ImapMail/'
and has to have the ' for the special chars in the path, which becomes imsub.

Since the files being processed have no extension imfil and imext are an exact match, so processing to add to the array only happens then. However, when the array is to be processed later, that fullfilename, including the fullpath is needed or the file with never be found to process.

It was suggested I use the code:
Code:
basedir="/home/$user/.thunderbird/$profile/ImapMail/";
while IFS= read -rd '' path; do
    echo "$path";
done < <(find "$basedir" -iname "${dir}*" -type f -print0)
and while that renders the path it also floods with unwanted information that then has to go through complex filtering to get back to just what is needed.

All suggestions and HOWTOs welcome.

Cheers!

TBNK
 
Old 05-08-2017, 02:27 AM   #5
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
if there are spaces (in file/dir names) you ought to use "${var}" everywhere.
For example: imdir="${dir%:}";

the line imsub=${dir%:}; is unclear, dir is not (yet) initialized or ???
imfil=$(basename "$imdir"); can be written as: imfil="${imdir##*/}"
for dir in ${im_dirs[@]}; do should be written as for dir in "${im_dirs[@]}"; do, but while is much better.
Quote:
while that renders the path it also floods with unwanted information that then has to go through complex filtering to get back to just what is needed.
would be nice to explain what is the problem exactly...
 
Old 05-11-2017, 01:13 PM   #6
TBotNik
Member
 
Registered: May 2016
Posts: 179

Original Poster
Rep: Reputation: Disabled
Modified

All,

OK modified my code to:

Code:
get_IMdirs () {
	#############################################################################
	# Modified: 	Nyle Davis			Mod Date: 17-04-25
	# Purpose:		Get all "ImapMail" subdirectories
	# Vars:			
	#############################################################################
	declare -a im_ray=();
	declare -a im_dirs=();
	imsub=${dir%:};
	xx=0;
	SAVEIFS=$IFS;
	IFS=$(echo -en "\n\b");
	im_dirs=$(ls -R $imsub);
	for dir in ${im_dirs[@]}; do
		imdir=${dir%:};
		while IFS= read -rd '' path; do
			SAVEIFS=$IFS;
			IFS=$(echo -en "\n\b");
			imfil=$(basename "$imdir");
			imext="${imfil##*.}";
			IFS=$SAVEIFS;
			if [[ "$imfil" == "$imext" ]]; then
				basfil=$(basename "$path");
				basext="${basfil##*.}";
				if [[ "$basfil" == "$basext" ]]; then
				  	echo "IF=> $imfil P=> $path";
					im_ray[$xx]=$path;
					((xx=xx+1));
				fi
			fi
		done < <(find "$imsub" -iname "${imdir}*" -type f -print0)
	done
	IFS=$SAVEIFS;
}	# end function get_IMdirs
Appears to be correct, but still testing.

Cheers!

TBNK
 
Old 05-11-2017, 01:18 PM   #7
TBotNik
Member
 
Registered: May 2016
Posts: 179

Original Poster
Rep: Reputation: Disabled
All,

Still getting lots of error messages and array appears blank, but not sure I'm doing the assign correctly.

Cheers!

TBNK
 
Old 05-12-2017, 02:22 AM   #8
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
you did not tell us anything about those error messages, so cannot help you to fix them.
from the other hand you can insert set -xv at the beginning of the function to see what's happening. Also you may try to use shellcheck to catch problems.
www.shellcheck.net
 
Old 05-12-2017, 11:37 PM   #9
TBotNik
Member
 
Registered: May 2016
Posts: 179

Original Poster
Rep: Reputation: Disabled
All,

OK, keep getting errors from the find command of:
Quote:
find: warning: Unix filenames usually don't contain slashes (though pathnames do). That means that '-iname `/home/$user/.thunderbird/$profile/ImapMail/imap.gmail.com/filename.ext*'' will probably evaluate to false all the time on this system. You might find the '-wholename' test more useful, or perhaps '-samefile'. Alternatively, if you are using GNU grep, you could use 'find ... -print0 | grep -FzZ `/home/$user/.thunderbird/$profile/ImapMail/imap.gmail.com/filename.ext*''.
So I added the grep -FzZ and nothing improved.

I can't tell if my processing is right with so many errors as this loop over 14,000 times.

Cheers!

TBNK
 
Old 05-13-2017, 12:53 AM   #10
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
Quote:
find: warning: Unix filenames usually don't contain slashes (though pathnames do). That means that '-iname ...' will probably evaluate to false all the time on this system.
interesting!
i never thought about that.
 
  


Reply

Tags
bash, directories, files, script



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
[SOLVED] Bash Script - Reading User Input while Processing output from Command within Bash cleeky Linux - General 5 05-27-2014 03:57 PM
[SOLVED] Converting Script from Linux (GNU) Bash 4 to Solaris Bash 2.05 - Any cheat sheet? oly_r Solaris / OpenSolaris 6 05-03-2013 09:25 AM
Bash problem : -bash: [: /bin/bash: unary operator expected J.A.X Linux - Software 1 09-22-2011 06:52 AM
[SOLVED] Need to output md5 or sha1 along with fullpath and filesize hanker Linux - Newbie 9 08-28-2010 04:27 AM
why did bash 2.05b install delete /bin/bash & "/bin/sh -> bash"? johnpipe Linux - Software 2 06-06-2004 07:42 PM

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

All times are GMT -5. The time now is 07:10 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