loops - I'm trying to create a paging system.This is not the complete code. Getting "path doesn't exist " when running the code -
i'm new powershell, idea on why i'm getting error?
yesterday_date = (get-date).adddays(-1).tostring("yyymmdd")
$jsb={ $file = 'c:\users\d1\documents\batch\path\$yesterday_date1\page.log' get-content $file -wait | foreach-object -begin { $counter = 1 $lines = @(get-content $file).count } -process { if ($counter++ -gt $lines) { write-host $_ } } }
start-job $jsb -name dum
do{ receive-job -name dum | out-file c:\users\path\pager.txt -append }while(1)
some syntax errors.
1st: missing $
variable yesterday_date. in addition, referring later variable $yesterday_date1
, not $yesterday_date
. use set-psdebug -strict
catch such errors. correct form is
$yesterday_date = (get-date).adddays(-1).tostring("yyymmdd")
2nd: single quote doesn't evaluate variables in strings. double quotes do. consider:
$file = 'c:\users\d1\documents\batch\path\$yesterday_date\page.log' $file # output c:\users\d1\documents\batch\path\$yesterday_date1page.log $file2 = "c:\users\d1\documents\batch\path\$yesterday_date1\page.log" $file2 # output c:\users\d1\documents\batch\path\20130520\page.log
edit:
to address question in comment, problem jobs need special parameter processing. use -arg
pass date variable parameter. so,
$yesterday_date = (get-date).adddays(-1).tostring("yyymmdd") $jsb={ param($date) $file = "c:\users\d1\documents\batch\path\$date\page.log" write-host $file } start-job $jsb -name dummy -arg $yesterday_date wait-job -name dummy receive-job -name dummy # output c:\users\d1\documents\batch\path\20130521\page.log
Comments
Post a Comment