Mark Taylor
(Fresh Scripter)
2002-10-23 05:17 PM
Problem with shell redirection

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,


Howard Bullock
(KiX Supporter)
2002-10-23 05:25 PM
Re: Problem with shell redirection

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 ]


Mark Taylor
(Fresh Scripter)
2002-10-23 05:47 PM
Re: Problem with shell redirection

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?


Waltz
(Seasoned Scripter)
2002-10-23 06:26 PM
Re: Problem with shell redirection

Mark...
What OS?
What Task Scheduler?


Les
(KiX Master)
2002-10-23 06:31 PM
Re: Problem with shell redirection

In your script you reference what I assume is a mapped drive (F:) but I don't see you mapping it.

Sealeopard
(KiX Master)
2002-10-23 06:46 PM
Re: Problem with shell redirection

Mapped drives are only available to a user account in the Task Scheduler if that user account established the mapping. Mappings created by other users are not available. You might be better off using UNC names.

[ 23. October 2002, 18:46: Message edited by: sealeopard ]


Mark Taylor
(Fresh Scripter)
2002-10-23 07:05 PM
Re: Problem with shell redirection

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,


Howard Bullock
(KiX Supporter)
2002-10-23 07:10 PM
Re: Problem with shell redirection

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 ]


Les
(KiX Master)
2002-10-23 07:23 PM
Re: Problem with shell redirection

I tested Howard's version as a Scheduled Task and it works like a charm.

Mark Taylor
(Fresh Scripter)
2002-10-23 07:44 PM
Re: Problem with shell redirection

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,


Howard Bullock
(KiX Supporter)
2002-10-23 07:47 PM
Re: Problem with shell redirection

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 ]


Les
(KiX Master)
2002-10-23 07:53 PM
Re: Problem with shell redirection

Yes, Win2k, SP3, KiX 4.02 in %windir%, Uptime.exe in "C:\Program Files\Resource Pro Kit", using a domain admin account.

Mark Taylor
(Fresh Scripter)
2002-10-23 07:58 PM
Re: Problem with shell redirection

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!


Waltz
(Seasoned Scripter)
2002-10-23 08:56 PM
Re: Problem with shell redirection

Well, Mark, now there's no doubt that you were going batty... [Roll Eyes]

Mark Taylor
(Fresh Scripter)
2002-10-23 08:59 PM
Re: Problem with shell redirection

[Big Grin] Tell me about it!

Now if I can just fix the nightmare that is "Win XP Service Pack 1"... I stand just a small chance of getting back my sanity...

Perhaps...

Thanks!


Waltz
(Seasoned Scripter)
2002-10-23 09:20 PM
Re: Problem with shell redirection

[Wink] I think our pal Einstein said it all...
quote:
Insanity: doing the same thing over and over again and expecting different results.