Page 1 of 1 1
Topic Options
#31269 - 2002-10-23 05:17 PM Problem with shell redirection
Mark Taylor Offline
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 Offline
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 ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#31271 - 2002-10-23 05:47 PM Re: Problem with shell redirection
Mark Taylor Offline
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
#31272 - 2002-10-23 06:26 PM Re: Problem with shell redirection
Waltz Offline
Seasoned Scripter

Registered: 2002-08-01
Posts: 485
Loc: Waterloo, Ontario, Canada
Mark...
What OS?
What Task Scheduler?
_________________________
We all live in a Yellow Subroutine...

Top
#31273 - 2002-10-23 06:31 PM Re: Problem with shell redirection
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
In your script you reference what I assume is a mapped drive (F:) but I don't see you mapping it.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#31274 - 2002-10-23 06:46 PM Re: Problem with shell redirection
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
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 ]
_________________________
There are two types of vessels, submarines and targets.

Top
#31275 - 2002-10-23 07:05 PM Re: Problem with shell redirection
Mark Taylor Offline
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 Offline
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 ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#31277 - 2002-10-23 07:23 PM Re: Problem with shell redirection
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I tested Howard's version as a Scheduled Task and it works like a charm.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#31278 - 2002-10-23 07:44 PM Re: Problem with shell redirection
Mark Taylor Offline
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 Offline
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 ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#31280 - 2002-10-23 07:53 PM Re: Problem with shell redirection
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Yes, Win2k, SP3, KiX 4.02 in %windir%, Uptime.exe in "C:\Program Files\Resource Pro Kit", using a domain admin account.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#31281 - 2002-10-23 07:58 PM Re: Problem with shell redirection
Mark Taylor Offline
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
#31282 - 2002-10-23 08:56 PM Re: Problem with shell redirection
Waltz Offline
Seasoned Scripter

Registered: 2002-08-01
Posts: 485
Loc: Waterloo, Ontario, Canada
Well, Mark, now there's no doubt that you were going batty... [Roll Eyes]
_________________________
We all live in a Yellow Subroutine...

Top
#31283 - 2002-10-23 08:59 PM Re: Problem with shell redirection
Mark Taylor Offline
Fresh Scripter

Registered: 2002-01-13
Posts: 6
Loc: UK
[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!
_________________________
Mark Taylor. Chorus IT.

Top
#31284 - 2002-10-23 09:20 PM Re: Problem with shell redirection
Waltz Offline
Seasoned Scripter

Registered: 2002-08-01
Posts: 485
Loc: Waterloo, Ontario, Canada
[Wink] I think our pal Einstein said it all...
quote:
Insanity: doing the same thing over and over again and expecting different results.
_________________________
We all live in a Yellow Subroutine...

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 248 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.068 seconds in which 0.024 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org