Am o problema cu un shell intr-un Linux. Spre deosebire de Marius'95 cu BSD-ul, eu chiar nu stiu ce versiune e acel Linux, dar pot spune ce vad eu pe-acolo si ce se intampla.
Deci: exista un folder pe acest server care genereaza niste loguri in fisiere text, aproape 2000 de fisiere zilnic; ceea ce vreau eu e sa iau acele fisiere pe un calculator cu Windows si sa le import intr-o baza de date. Am incercat sa le copiez cu WinSCP, din cauza ca sunt mici si multe dureaza foarte mult timp (vreo ora, parca), asa ca am gasit in documentatia WinSCP instructiuni despre cum pot scrie un script care sa arhiveze fisierele intr-un singur .tar.gz pe care sa il copiez si sa il sterg dupa aceea. Operatiunea e extrem de rapida, cateva secunde arhivarea si zeci de secunde copierea, asa ca mi se pare o idee excelenta.
Ce merge: ma pot conecta cu WinSCP si pot copia fisierele si din folderul original /var/opt/gsss/data/activityTraceLogs/LogFiles si din /tmp unde fac arhiva temporara. Pot sa ma conectez cu PuTTY si sa rulez comanda de arhivare (tar -czf /tmp/archive.tar.gz *.* ) si merge perfect.
Ce nu merge: am incercat sa fac asta ori ca script in WinSCP, ori direct dintr-un mic program C# in console mode (linie de comanda) cu WinSCP .NET assemblies pe care l-am scris doar ca sa leg toate operatiunile intr-un singur limbaj (arhivarea, poi copierea, apoi dezarhivarea, apoi importul in SQL cu BULKCOPY dar cu verificare daca fisierul a mai fost procesat vreodata ca sa nu import de 2 ori). Rezultatul e acelasi, la comanda de arhivare se inchide sesiunea de catre server si tot ce am e ceea ce scrie in loguri sau ca output pe ecran.
Log WinSCP:
Code:
. 2015-11-28 13:47:03.095 Startup conversation with host finished.
< 2015-11-28 13:47:03.095 Script: Active session: [1]xxxxxx@yyyyyyyy
> 2015-11-28 13:47:03.095 Script: cd /var/opt/gsss/data/portalActivityTraces/LogFiles
. 2015-11-28 13:47:03.095 Cached directory change via "/var/opt/gsss/data/portalActivityTraces/LogFiles" to "/var/opt/gsss/data/portalActivityTraces/LogFiles".
. 2015-11-28 13:47:03.095 Getting current directory name.
< 2015-11-28 13:47:03.095 Script: /var/opt/gsss/data/portalActivityTraces/LogFiles
> 2015-11-28 13:47:03.095 Script: call tar -czf /tmp/archive.tar.gz *.*
< 2015-11-28 13:47:03.095 Script: Searching for host...
. 2015-11-28 13:47:03.095 [Shell] Looking up host "yyyyyyyy"
. 2015-11-28 13:47:03.298 [Shell] Connecting to zzz.zzz.zzz.zzz port 22
< 2015-11-28 13:47:03.455 Script: Connecting to host...
. 2015-11-28 13:47:03.610 [Shell] Server version: SSH-2.0-OpenSSH_5.5
. 2015-11-28 13:47:03.610 [Shell] Using SSH protocol version 2
. 2015-11-28 13:47:03.610 [Shell] We claim version: SSH-2.0-WinSCP_release_5.7.6
. 2015-11-28 13:47:03.766 [Shell] Doing Diffie-Hellman group exchange
. 2015-11-28 13:47:04.095 [Shell] Doing Diffie-Hellman key exchange with hash SHA-256
. 2015-11-28 13:47:05.139 [Shell] Verifying host key rsa2 bla-bla with fingerprint ssh-rsa 2048 bla-bla
< 2015-11-28 13:47:05.139 Script: Authenticating...
. 2015-11-28 13:47:05.139 [Shell] Host key matches cached key
. 2015-11-28 13:47:05.139 [Shell] Host key fingerprint is:
. 2015-11-28 13:47:05.139 [Shell] ssh-rsa 2048 bla-bla
. 2015-11-28 13:47:05.139 [Shell] Initialised AES-256 SDCTR client->server encryption
. 2015-11-28 13:47:05.139 [Shell] Initialised HMAC-SHA1 client->server MAC algorithm
. 2015-11-28 13:47:05.139 [Shell] Initialised AES-256 SDCTR server->client encryption
. 2015-11-28 13:47:05.139 [Shell] Initialised HMAC-SHA1 server->client MAC algorithm
! 2015-11-28 13:47:05.483 [Shell] Using username "xxxxxx".
< 2015-11-28 13:47:05.483 Script: Using username "xxxxxx".
. 2015-11-28 13:47:05.655 [Shell] Attempting keyboard-interactive authentication
. 2015-11-28 13:47:05.811 [Shell] Prompt (keyboard interactive, "SSH server authentication", "Using keyboard-interactive authentication.", "Password: ")
. 2015-11-28 13:47:05.811 [Shell] Using stored password.
< 2015-11-28 13:47:05.811 Script: Authenticating with pre-entered password.
. 2015-11-28 13:47:05.968 [Shell] Prompt (keyboard interactive, "SSH server authentication", <no instructions>, <no prompt>)
. 2015-11-28 13:47:05.968 [Shell] Ignoring empty SSH server authentication request
. 2015-11-28 13:47:06.125 [Shell] Access granted
. 2015-11-28 13:47:06.125 [Shell] Opening session as main channel
. 2015-11-28 13:47:06.265 [Shell] Opened main channel
. 2015-11-28 13:47:06.606 [Shell] Started a shell/command
< 2015-11-28 13:47:06.606 Script: Authenticated.
. 2015-11-28 13:47:06.606 [Shell] --------------------------------------------------------------------------
. 2015-11-28 13:47:06.606 [Shell] Using SCP protocol.
. 2015-11-28 13:47:06.606 [Shell] Doing startup conversation with host.
< 2015-11-28 13:47:06.606 Script: Starting the session...
. 2015-11-28 13:47:06.606 [Shell] Skipping host startup message (if any).
> 2015-11-28 13:47:06.606 [Shell] echo "WinSCP: this is end-of-file:0"
< 2015-11-28 13:47:06.623 [Shell]
< 2015-11-28 13:47:06.623 [Shell] *****************************************************************************
< 2015-11-28 13:47:06.623 [Shell] * This is a private computer/communication system. Access to it for any *
< 2015-11-28 13:47:06.623 [Shell] * reason must be specifically authorized. If you are not authorized, your *
< 2015-11-28 13:47:06.623 [Shell] * continued access and further inquiry may expose you to criminal and/or *
< 2015-11-28 13:47:06.623 [Shell] * civil proceedings. System personnel will/may monitor this system for *
< 2015-11-28 13:47:06.623 [Shell] * unauthorized activity, misuse, and to evaluate system performance. *
< 2015-11-28 13:47:06.623 [Shell] * Anyone using this system expressly consents to such monitoring *
< 2015-11-28 13:47:06.623 [Shell] * Software must not be installed on this computer/communication system *
< 2015-11-28 13:47:06.623 [Shell] * without a purchased and documented license approved by the Company's *
< 2015-11-28 13:47:06.623 [Shell] * licensing process. Failure to comply could expose you and/or the Company *
< 2015-11-28 13:47:06.623 [Shell] * to legal proceedings *
< 2015-11-28 13:47:06.623 [Shell] *****************************************************************************
< 2015-11-28 13:47:06.685 [Shell] Last login time was Nov 28 06:44 !!!
< 2015-11-28 13:47:06.935 [Shell] WinSCP: this is end-of-file:0
. 2015-11-28 13:47:06.935 [Shell] Detecting variable containing return code of last command.
. 2015-11-28 13:47:06.935 [Shell] Trying "$status".
> 2015-11-28 13:47:06.935 [Shell] echo "$status" ; echo "WinSCP: this is end-of-file:0"
! 2015-11-28 13:47:07.075 [Shell] -bash: line 2: status: unbound variable
< 2015-11-28 13:47:07.075 [Shell] logout
. 2015-11-28 13:47:07.091 [Shell] Server sent command exit status 1
. 2015-11-28 13:47:07.091 [Shell] Disconnected: All channels closed
< 2015-11-28 13:47:07.091 Script: Connection has been unexpectedly closed. Server sent command exit status 1.
< 2015-11-28 13:47:07.091 Script: Error detecting variable containing return code of last command.
. 2015-11-28 13:47:07.091 Script: Failed
. 2015-11-28 13:47:07.091 Script: Exit code: 1
. 2015-11-28 13:47:07.091 Closing connection.
. 2015-11-28 13:47:07.091 Sending special code: 12
. 2015-11-28 13:47:07.091 Sent EOF message
Output pe ecran din C#: e similar cu ce spune WinSCP, dar mult mai slab ca explicatii, e doar pentru confirmarea ca pare sa fie aceeasi problema.
Code:
Error: WinSCP.SessionRemoteException: Connection has been unexpectedly closed. Server sent command exit status 1. ---> WinSCP.SessionRemoteException: Error detecting variable containing return code of last command.
--- End of inner exception stack trace ---
at WinSCP.OperationResultBase.Check()
at LogsImport.Program.DownloadFiles(String localPath)
Scriptul in WinSCP; repet, rulate manual toate comenzile merg, mai putin acel "call tar .." pe care il rulez in PuTTY si merge.
Code:
option batch abort
option confirm off
open xxxxxx:pppppppp@yyyyyy
cd /var/opt/gsss/data/portalActivityTraces/LogFiles
call tar -czf /tmp/archive.tar.gz *.*
lpwd
get -delete /tmp/archive.tar.gz
exit