#31269 - 2002-10-23 05:17 PM
Problem with shell redirection
|
Mark Taylor
Fresh Scripter
Registered: 2002-01-13
Posts: 6
Loc: UK
|
Hi,
Well this one has me stumped! Despite searching this board and experimenting left, right and centre.
I have small piece of code which is supposed to run the MS UpTime utility and redirect the output to a txt file.
The code works fine when I run from a command prompt. However when I schedule the script through task scheduler (running as admin) the output file still appears, but contains the script execution line rather than the Output of the uptime utility.
Anyone have ideas why it might do that?
Any help much appreciated!
code:
; *** Quarterly script to run "Uptime" comand ***
; * If month <10 add leading zero for neatness *
$mn=@monthno $lmn=len($mn)
If $lmn=1 $mn="0"+@monthno EndIf
; * Define Output file (Using redirection) *
$fl="F:\Reports\TCN2002"+$mn+"UptimeReport.txt"
; * Define Command using Resource Kit Uptime Command *
$cm="cmd /c uptime /s /d:"+(@monthno-1)+"/01/"+@year+" \\server01 >"+$fl
; * Execute Command *
shell $cm
Many thanks,
_________________________
Mark Taylor.
Chorus IT.
|
Top
|
|
|
|
#31270 - 2002-10-23 05:25 PM
Re: Problem with shell redirection
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
break on $fl="c:\data\scripts\UptimeReport.txt" $cm='uptime /s /d:'+(@monthno-1)+'/01/'+@year+' \\@wksta >'+$fl ? $cm shell "%comspec% /c $cm" quote: Uptime Report for: \\BULLOCKHA
Current OS: Microsoft Windows 2000, Service Pack 3, (Build 2195), Uniprocessor Free.
System Events as of 10/23/2002 11:28:14 AM:
Current system uptime: 0 day(s), 3 hour(s), 59 minute(s), 25 second(s)
-------------------------------------------------------------------------------
Since 9/1/2002: (Last 52 Days)
Total Reboots: 82 Mean Time Between Reboots: 0.64 days Total Bluescreens: 0
-------------------------------------------------------------------------------
Since 10/17/2002: (Last 52 Days)
System Availability: 98.6391% Total Uptime: 5d 19h:4m:55s Total Downtime: 0d 17h:8m:23s Total Reboots: 13 Mean Time Between Reboots: 4.04 days Total Bluescreens: 0
Notes: 10/17/2002 Is the earliest date in the event log where sufficient information is recorded to calculate availability.
[ 23. October 2002, 17:26: Message edited by: Howard Bullock ]
|
Top
|
|
|
|
#31271 - 2002-10-23 05:47 PM
Re: Problem with shell redirection
|
Mark Taylor
Fresh Scripter
Registered: 2002-01-13
Posts: 6
Loc: UK
|
Hi Howard,
Thanks for the quick reply.
Didnt make any difference Im afraid, from a command prompt the old and amneded versions work fine.
However from a scheduled task the output file contains only one line:
C:\KixScripts>wkix32 c:\kixscripts\uptime.kix
Instead of the UpTime output.
Any ideas?
_________________________
Mark Taylor.
Chorus IT.
|
Top
|
|
|
|
#31275 - 2002-10-23 07:05 PM
Re: Problem with shell redirection
|
Mark Taylor
Fresh Scripter
Registered: 2002-01-13
Posts: 6
Loc: UK
|
Hi...
OS is Win2k SP3, F is not a mapped drive, its a seperate RAID drive.
The task is running as an administrator and executes the command "kix32 c:\kixscripts\uptime.kix". I've also tried wkix32 as well.
Any other info I can provide that might help?
Thanks,
_________________________
Mark Taylor.
Chorus IT.
|
Top
|
|
|
|
#31276 - 2002-10-23 07:10 PM
Re: Problem with shell redirection
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Maybe you might want to try using WSHPIPE and WriteLog2() to generate your file. See http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic;f=1;t=006044 for sample code.
{edit} I once had a problem with redirection from a scheduled task. I think it dealt with a space or maybe the lack of a space between the last command line parameter and the ">" symbol. You my want to attempt your code again without the space that preceeds the ">". [ 23. October 2002, 19:24: Message edited by: Howard Bullock ]
|
Top
|
|
|
|
#31278 - 2002-10-23 07:44 PM
Re: Problem with shell redirection
|
Mark Taylor
Fresh Scripter
Registered: 2002-01-13
Posts: 6
Loc: UK
|
Hi...
Thanks Howard... I tried taking the space out... the script still worked from the command line but is still producing the wrong output when scheduled.
LLigetfa,
Are you trying that on Win2k SP3?
Many thanks,
_________________________
Mark Taylor.
Chorus IT.
|
Top
|
|
|
|
#31279 - 2002-10-23 07:47 PM
Re: Problem with shell redirection
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Mark, you can save yourself a lot of aggravation and time if you explore the WSHPIPE() and Writelog2() UDF solution mentioned above. This removes the need to use redirection at all.
It even provides you an opportunity to edit/format the output you store in the file. [ 23. October 2002, 19:47: Message edited by: Howard Bullock ]
|
Top
|
|
|
|
#31281 - 2002-10-23 07:58 PM
Re: Problem with shell redirection
|
Mark Taylor
Fresh Scripter
Registered: 2002-01-13
Posts: 6
Loc: UK
|
Hi,
Well its working... but the fix was bizarre in the extreme...
The directory where my script is stored also had a batch file in which contained "wkix32 c:\kixscripts\uptime.kix".
I stopped using it almost as soon as I created the task as I realised I might as well call the KIX script directly.
Whilst experimenting just now I changed my task execution line from wkix32 to kix32. Then noticed that my broken output file still contained "wkix32 ... etc".
At that point I realised the BAT file might be playing a part and deleted it... hey presto.. with no other changes than deleting the BAT file it now works...
VERY strange...
But thanks for all of your help... much appreciated!
_________________________
Mark Taylor.
Chorus IT.
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 248 anonymous users online.
|
|
|