LINUX.ORG.RU

Сообщения optik77

 

Some manipulations with files and folders. (loop, find, create and rm)

Форум — Development

Hello!

I need to realize such task.

1. In my user's home dir I have folder1;
2. In folder1 I have some (various count) subfolders with random names;
3. In these subfolders I have one file anyname.pdf (various name in each subfolder) and file content.txt (constant name in each subfolder)
## If in subfolder more than one .pdf or more than one .txt file, I must miss this subfolder (move it to Folder3 - it's one of the folders of my user's home dir) ;

So,
4. I must to scan every subfolders in folder1,
enter in each one;
5. If this subfolder has more than one .pdf file or more than one .txt file, I must go to next subfolder (with moving this subfolder to Folder3);
6. In «good» subfolders I must take file content.txt;
7. It has such structure:

dfdf{some trash}wqwq
begin_of_useful_info
info info ... info
end_of_useful_info
dfdf{some trash}wqwq

8. In this file content.txt I must find and cut only «useful_info» (between begin_of_useful_info and end_of_useful_info,including it):

begin_of_useful_info
info info ... info
end_of_useful_info

( begin_of_useful_info and end_of_useful_info is key-words on each content.txt, it must be cutted too)

9. this info I must put in new .txt file with name as .pdf file in this subfolder!

Example:
In folder1/4323353/ I have files GHTY34.pdf and content.txt. So, after operation I must get a file GHTY34.txt with useful_info)

10. delete parsed file content.txt
(so, now I have again two files in subfolder somename.pdf and somename.txt)

11. then I must copy files .pdf and new .txt with similar names somewhere, for example in folder2 (my user's home dir) and delete analized subfolder.
12. Go to next subfolder.

That's all
Thanks!

optik77
()

Сохранение почтовых вложений(fetchmail + procmail + uudeview)

Форум — General

добрый день!

я пытаюсь сохранить вложения из входящих почтовых сообщений в каталоги.
я опрашиваю 2 почтовых ящика.
user1@host_address
user2@host_address

я использую следующую конфигурация .fetchmailrc:

poll «user2@host_address»,
protocol imap,
user «user1»,
password «1»

poll «user2@host_address»,
protocol imap,
user «user2»,
password «1»

mda '/usr/bin/procmail -d %T'

Когда я тестирую работу и посылаю сообщение от пользователя user3 сначала для user1 потом для user2, fetchmail берёт и сохраняет вложение, адресованное только для user2. Хотя статус с непрочитанного (unseen) на прочитанное (seen) меняется у обоих пользователей.

Лог команды fetchmail:

dima@myserver:~> fetchmail -k -v
fetchmail: 6.2.5 querying host_address (protocol IMAP) at Tue 29 Mar 2011 02:46:05 PM MSD: poll started
fetchmail: IMAP< * OK GroupWise IMAP4rev1 Server Ready
fetchmail: IMAP> A0001 CAPABILITY
fetchmail: IMAP< * CAPABILITY IMAP4rev1 AUTH=XGWTRUSTEDAPP XGWEXTENSIONS
fetchmail: IMAP< A0001 OK CAPABILITY completed
fetchmail: IMAP> A0002 LOGIN «user1» *
fetchmail: IMAP< A0002 OK LOGIN completed
fetchmail: IMAP> A0003 SELECT «INBOX»
fetchmail: IMAP< * 260 EXISTS
fetchmail: IMAP< * 1 RECENT
fetchmail: IMAP< * OK [UNSEEN 260]
fetchmail: IMAP< * OK [UIDVALIDITY 1301053702]
fetchmail: IMAP< * OK [UIDNEXT 545]
fetchmail: IMAP< * FLAGS (Answered Flagged Deleted Draft Seen)
fetchmail: IMAP< * OK [PERMANENTFLAGS (Answered Flagged Deleted Draft Seen *)]
fetchmail: IMAP< A0003 OK [READ-WRITE] SELECT completed
fetchmail: IMAP> A0004 SEARCH UNSEEN NOT DELETED
fetchmail: IMAP< * SEARCH 260
fetchmail: IMAP< A0004 OK SEARCH completed
260 messages (259 seen) for user1 at host_address.
skipping message user1@host_address:1 not flushed
      { ... etc ... }
skipping message user1@host_address:258 not flushed
skipping message user1@host_address:259 not flushed
fetchmail: IMAP> A0005 FETCH 260 RFC822.SIZE
fetchmail: IMAP< * 260 FETCH (RFC822.SIZE 23853)
fetchmail: IMAP< A0005 OK FETCH completed
fetchmail: IMAP> A0006 FETCH 260 RFC822.HEADER
fetchmail: IMAP< * 260 FETCH (RFC822.HEADER {367}
reading message user1@host_address:260 of 260 (367 header octets)
fetchmail: SMTP< 220 myserver.msd.local ESMTP Postfix
fetchmail: SMTP> EHLO localhost
fetchmail: SMTP< 250-myserver.msd.local
fetchmail: SMTP< 250-PIPELINING
fetchmail: SMTP< 250-SIZE 10240000
fetchmail: SMTP< 250-VRFY
fetchmail: SMTP< 250-ETRN
fetchmail: SMTP< 250 8BITMIME
fetchmail: SMTP> MAIL FROM:<user3@firma.ru> SIZE=23853
fetchmail: SMTP< 250 Ok
fetchmail: SMTP> RCPT TO:<door@localhost>
fetchmail: SMTP< 250 Ok
fetchmail: SMTP> DATA
fetchmail: SMTP< 354 End data with <CR><LF>.<CR><LF>
#
fetchmail: IMAP< )
fetchmail: IMAP< A0006 OK FETCH completed
fetchmail: IMAP> A0007 FETCH 260 BODY.PEEK[TEXT]
fetchmail: IMAP< * 260 FETCH (BODY[TEXT] {23486}
(23486 body octets) **************************************************************************************************
*******************************************************************************************************
****************************************************************************************************************
fetchmail: IMAP< )
fetchmail: IMAP< A0007 OK FETCH completed
fetchmail: SMTP>. (EOM)
fetchmail: SMTP< 250 Ok: queued as 89C27A4B4A
not flushed
fetchmail: IMAP> A0008 STORE 260 +FLAGS (Seen)
fetchmail: IMAP< * 260 FETCH (FLAGS (Seen Recent))
fetchmail: IMAP< A0008 OK STORE completed
fetchmail: IMAP> A0009 LOGOUT
fetchmail: IMAP< * BYE IMAP4rev1 Server Disconnect
fetchmail: IMAP< A0009 OK LOGOUT completed
fetchmail: 6.2.5 querying host_address (protocol IMAP) at Tue 29 Mar 2011 02:46:05 PM MSD: poll completed
fetchmail: 6.2.5 querying host_address (protocol IMAP) at Tue 29 Mar 2011 02:46:05 PM MSD: poll started
fetchmail: IMAP< * OK GroupWise IMAP4rev1 Server Ready
fetchmail: IMAP> A0001 CAPABILITY
fetchmail: IMAP< * CAPABILITY IMAP4rev1 AUTH=XGWTRUSTEDAPP XGWEXTENSIONS
fetchmail: IMAP< A0001 OK CAPABILITY completed
fetchmail: IMAP> A0002 LOGIN «user2» *
fetchmail: IMAP< A0002 OK LOGIN completed
fetchmail: IMAP> A0003 SELECT «INBOX»
fetchmail: IMAP< * 1 EXISTS
fetchmail: IMAP< * 1 RECENT
fetchmail: IMAP< * OK [UNSEEN 1]
fetchmail: IMAP< * OK [UIDVALIDITY 1300281146]
fetchmail: IMAP< * OK [UIDNEXT 74]
fetchmail: IMAP< * FLAGS (Answered Flagged Deleted Draft Seen)
fetchmail: IMAP< * OK [PERMANENTFLAGS (Answered Flagged Deleted Draft Seen *)]
fetchmail: IMAP< A0003 OK [READ-WRITE] SELECT completed
fetchmail: IMAP> A0004 SEARCH UNSEEN NOT DELETED
fetchmail: IMAP< * SEARCH 1
fetchmail: IMAP< A0004 OK SEARCH completed
1 message for user2 at host_address.
fetchmail: IMAP> A0005 FETCH 1 RFC822.SIZE
fetchmail: IMAP< * 1 FETCH (RFC822.SIZE 23806)
fetchmail: IMAP< A0005 OK FETCH completed
fetchmail: IMAP> A0006 FETCH 1 RFC822.HEADER
fetchmail: IMAP< * 1 FETCH (RFC822.HEADER {320}
reading message user2@host_address:1 of 1 (320 header octets)
#
fetchmail: IMAP< )
fetchmail: IMAP< A0006 OK FETCH completed
fetchmail: IMAP> A0007 FETCH 1 BODY.PEEK[TEXT]
fetchmail: IMAP< * 1 FETCH (BODY[TEXT] {23486}
(23486 body octets) ************************************************************************************************
************************************************************************************************************
*************************************************************************************************************
fetchmail: IMAP< )
fetchmail: IMAP< A0007 OK FETCH completed
Loaded from /tmp/uuqLClgs: '111' (UNKNOWN): test1.xls part 1 Base64
not flushed
fetchmail: IMAP> A0008 STORE 1 +FLAGS (Seen)
fetchmail: IMAP< * 1 FETCH (FLAGS (Seen Recent))
fetchmail: IMAP< A0008 OK STORE completed
fetchmail: IMAP> A0009 LOGOUT
fetchmail: IMAP< * BYE IMAP4rev1 Server Disconnect
fetchmail: IMAP< A0009 OK LOGOUT completed
fetchmail: 6.2.5 querying host_address (protocol IMAP) at Tue 29 Mar 2011 02:46:06 PM MSD: poll completed
fetchmail: SMTP> QUIT
fetchmail: SMTP< 221 Bye
fetchmail: normal termination, status 0

В чём может быть проблема?
Особо меня настораживает почему в первом случае появляется блок команд SMTP после сообщения:

fetchmail: IMAP< * 260 FETCH (RFC822.HEADER {367}
reading message user1@host_address:260 of 260 (367 header octets)
fetchmail: SMTP< 220 myserver.msd.local ESMTP Postfix
fetchmail: SMTP> EHLO localhost
...

как будто он пытается что то куда то переслать. Но зачем? если я просто от user3 последовательно одинаково слал сообщения для user1 и user2.

и еще особенность, что если по очереди убрать настройки для user1 или user2 и оставлять по одному пользователю, то всё работает...

optik77
()

RSS подписка на новые темы