{"id":9083,"date":"2012-02-20T10:56:08","date_gmt":"2012-02-20T09:56:08","guid":{"rendered":"https:\/\/www.dreamsworld.it\/emanuele\/?p=9083"},"modified":"2016-05-18T09:38:16","modified_gmt":"2016-05-18T07:38:16","slug":"debug-di-uno-script-batch-quando-usato-nel-task-scheduler","status":"publish","type":"post","link":"https:\/\/www.dreamsworld.it\/emanuele\/2012-02-20\/debug-di-uno-script-batch-quando-usato-nel-task-scheduler\/","title":{"rendered":"Debug di uno script batch quando usato nel task scheduler."},"content":{"rendered":"<p>Problema: ho creato <strong>un file batch<\/strong> che ogni tot ore svuota delle cartelle su un <strong>drive di rete mappato<\/strong> sotto Windows 2003 Server. Se mandato in run manualmente lo script <strong>esegue il compito<\/strong> in maniera egregia, se invece lo si avvia tramite task scheduler qualcosa fallisce.<\/p>\n<p>Il <strong>log dello scheduler<\/strong> non \u00e8 sufficiente a risolvere il mistero (<em>il batch viene lanciato correttamente quindi il file \u00e8 accessibile e l&#8217;utente di riferimento ha tutti i diritti per eseguirlo<\/em>) ma l&#8217;azione non viene compiuta (<em>le cartelle rimangono piene<\/em>).<\/p>\n<p>Come uscire dal problema?<\/p>\n<p>Create un <strong>ulteriore file batch<\/strong> (<em>debug.bat<\/em>) da avviare tramite schedulazione e scrivete al suo interno queste istruzioni:<\/p>\n<pre lang=\"bash\">echo [%date% - %time%] Log start > C:\\log.txt\r\nCALL \"C:\\my_real_script.bat\" >> C:\\log.txt 2>&1<\/pre>\n<p>Sostituite <em>my_real_script.bat<\/em> con lo script che non vi funziona ed <strong>eseguite<\/strong> tramite schedulazione <em>debug.bat<\/em><\/p>\n<p>In <em>log.txt<\/em> avrete sia l&#8217;elenco delle azioni eseguite (<em>lette in my_real_script.bat<\/em>) che le <strong>eventuali risposte di errore<\/strong> da parte del sistema operativo. Il trucco sta in quel <em>2&gt;&amp;1<\/em> che <strong>redireziona l&#8217;output<\/strong> sul file.<\/p>\n<p>E adesso, se volete sapere perch\u00e9 il mio script non andava, la risposta \u00e8 semplice: <strong>Windows non ha accesso ai drive mappati<\/strong> quando esegue un&#8217;azione chiamata dallo scheduler (<em>vi ricordo che lo script funziona benone se lanciato manualmente<\/em>) e risponde con &#8220;<em>The system cannot find the path specified.&#8221;<\/em> in quanto il mapping dei drive viene effettuato solo per l&#8217;utente corrente.<br \/>\nPer <strong>risolvere<\/strong> il mio problema, nello script batch, ho dovuto usare la <a title=\"Wikipedia - Path (computing) - Uniform Naming Convention (inglese)\" href=\"https:\/\/en.wikipedia.org\/wiki\/Path_%28computing%29#Uniform_Naming_Convention\" target=\"_blank\">path UNC<\/a> del tipo <em>\\\\ip-address\\folder_name<\/em>.<\/p>\n<p><strong>Emanuele<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Problema: ho creato un file batch che ogni tot ore svuota delle cartelle su un drive di rete mappato sotto Windows 2003 Server. Se mandato in run manualmente lo script esegue il compito in maniera egregia, se invece lo si &hellip; <a href=\"https:\/\/www.dreamsworld.it\/emanuele\/2012-02-20\/debug-di-uno-script-batch-quando-usato-nel-task-scheduler\/\">Leggi ancora &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":4,"activitypub_interaction_policy_quote":"anyone","activitypub_status":"","footnotes":""},"categories":[3],"tags":[2483,758,653,640,488,2484,42,372,1151],"class_list":["post-9083","post","type-post","status-publish","format-standard","hentry","category-computer","tag-batch","tag-debug","tag-guide","tag-how-to","tag-microsoft","tag-scheduler","tag-sistemi-operativi","tag-software","tag-windows"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.dreamsworld.it\/emanuele\/wp-json\/wp\/v2\/posts\/9083","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dreamsworld.it\/emanuele\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dreamsworld.it\/emanuele\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dreamsworld.it\/emanuele\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dreamsworld.it\/emanuele\/wp-json\/wp\/v2\/comments?post=9083"}],"version-history":[{"count":0,"href":"https:\/\/www.dreamsworld.it\/emanuele\/wp-json\/wp\/v2\/posts\/9083\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.dreamsworld.it\/emanuele\/wp-json\/wp\/v2\/media?parent=9083"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dreamsworld.it\/emanuele\/wp-json\/wp\/v2\/categories?post=9083"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dreamsworld.it\/emanuele\/wp-json\/wp\/v2\/tags?post=9083"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}