Hi all is there a way we can show progress bar for 10 minutes with statistics of percentage completed how much time remaining for 10 Minutes? using Write-Progress.
If I understand the question correctly the goal is to show some additional
information in the progress messages. This can be done for example by using the
Activity parameter. The script below only shows the idea (for 1 minute, for a
shorter test). It should be modified in order to reflect actually needed format
of the message and information to be shown.
$time = 60 # seconds, use you actual time in here
foreach($i in (1..$time)) {
$percentage = $i / $time
$remaining = New-TimeSpan -Seconds ($time - $i)
$message = "{0:p0} complete, remaining time {1}" -f $percentage, $remaining
Write-Progress -Activity $message -PercentComplete ($percentage * 100)
Start-Sleep 1
}
The progress looks like this:
57 % complete, remaining time 00:00:26
Processing
[oooooooooooooooooooooooooooooooooooooooooooooooooooooo
Related
I wish to calculate runtime of my program which approximates PI using Monte Carlo Method. I have written a unix shell script which feeds the program No of points, N = 10^{k} , for K = 1,2, ...7.
Now I wish to find the execution time for Each N in Unix program time. My unix shell script looks as follows:
#!/bin/bash
k=1
N=10
while [[ k -le 7 ]]
do
echo "$k N" | ./pi $N
((k = k + 1))
((N = N * 10))
done
Now when I type: $ time ./pi.sh , it returns me the total execution time
10 3.6 0.1459155902616465
100 3.08 0.01960555055392467
1000 3.104 0.01196611328551369
10000 3.1284 0.004199352062629202
100000 3.1432 0.0005116342528909465
1000000 3.139704 0.0006011771092076384
10000000 3.141432 5.113762588206346e-05
real 0m0.583s
user 0m0.560s
sys 0m0.012s
I was wondering if I have to write a bash script to get execution time for Each N input or I have to do something in my code.
By writing $ time ./pi.sh you are measuring time needed to execute pi.sh, which has a loop in it. So you measure total time for all iterations. If you want to measure every iteration independently, you have to put time in invocation of the iteration:
echo "$k N" | time ./pi $N
Please help to understand. I find the simple of script in off site about update RRDTool base.
But for me need to create one rrd base to all servers. Please help to understand what way the best and just give some point how to do this.
Send data from all servers to rrdtool base and update it? or try to get all data from server where rrdtool and update in local level?
#!/bin/sh
a=0
while [ "$a" == 0 ]; do
snmpwalk -c public 192.168.1.250 hrSWRunPerfMem > snmp_reply
total_mem=`awk 'BEGIN {tot_mem=0}
{ if ($NF == "KBytes")
{tot_mem=tot_mem+$(NF-1)}
}
END {print tot_mem}' snmp_reply`
# I can use N as a replacement for the current time
rrdtool update target.rrd N:$total_mem
# sleep until the next 300 seconds are full
perl -e 'sleep 300 - time % 300'
done # end of while loop
I want to generate fake values in RRD DB for a period of 1 month and with 5 seconds as a frequency for data collection. Is there any tool which would fill RRD DB with fake data for given time duration.
I Googled a lot but did not find any such tool.
Please help.
I would recommend the following one liner:
perl -e 'my $start = time - 30 * 24 * 3600; print join " ","update","my.rrd",(map { ($start+$_*5).":".rand} 0..(30*24*3600/5))' | rrdtool -
this assumes you have an rrd file called my.rrd and that is contains just one data source expecting GAUGE type data.
I have created the following script that returns the percentage of free space , the total space etc. of every disk for the remote servers the problem is that i want an extra column "warning" that prints No or Yes if the free space is bellow 10% i tried if statement but with no success. Please for your help.
Get-WmiObject Win32_LogicalDisk -filter "DriveType=3" -computer (Get-Content .\servers.txt) | Select SystemName,DeviceID,VolumeName,#{Name="Size(GB)";
Expression={"{0:N1}" -f($_.size/1gb)}},#{Name="FreeSpace(GB)";
Expression={"{0:N1}" -f($_.freespace/1gb)}},#{Name=" % Free(GB)";
Expression={"{0:N1}" -f(($_.freespace/$_.size)*100 )}},#{Name=" Warning";
Expression={????????}} |Format-Table -AutoSize |Out-File disk_monitor.txt
You can try something like
#{Name="Warning";Expression={ if((100 / $_.Size * $_.FreeSpace) -lt 10) { "Yes" } else { "No" }} };
This will calculate what percentage of disk space is available (100 / Size * FreeSpace) and if it's less than 10 (as in, percent), will return "Yes" or otherwise "No".
I need to pull a particular number from the output of this command:
Get-EventLog "application" | Where-Object {$_.EventID -eq 6006}
Sample output is:
Index Time EntryType Source InstanceID Message
----- ---- --------- ------ ---------- -------
18297 May 15 18:49 Warning Wlclntfy 2147489654 The winlogon notification subscriber <Profiles> took 60 second(s) to handle the notification event (Logon).
11788 Jan 31 08:11 Warning Wlclntfy 2147489654 The winlogon notification subscriber <Profiles> took 68 second(s) to handle the notification event (Logon).
5794 Oct 16 09:41 Warning Wlclntfy 2147489654 The winlogon notification subscriber <Sens> took 225 second(s) to handle the notification event (Logoff).
5596 Oct 11 08:03 Warning Wlclntfy 2147489654 The winlogon notification subscriber <Profiles> took 69 second(s) to handle the notification event (Logon).
2719 Aug 30 07:50 Warning Wlclntfy 2147489654 The winlogon notification subscriber <Profiles> took 65 second(s) to handle the notification event (Logon).
What I actually need to do is pull the number of seconds reported by the <Profiles> events, and pull out the largest one. I've gotten as far as figuring out (?<=<Profiles> took )(\d+) will work to pull just the numbers I need, but I'm not sure how to proceed to actually extract them. I've tried piping it to Select-String -pattern, but that just returns nothing at all.
You want the $matches builtin variable. $matches[0] is the text that matched the regexp, and $matches[1] .. $matches[n] are the matched parenthetical expressions (if there were any).
Sadly I don't have any EventID=6006 on my machine so I'm doing this without testing, but this should select the last item from the sorted list of seconds:
Get-EventLog "application" |
Where-Object {$_.EventID -eq 6006} |
Where-Object { $_.Message -match "<Profiles> took (\d*) second" } |
foreach { [int]$matches[1] } |
sort |
select -last 1
You can get the value(s) without regex. Take a look at the ReplacementStrings property of the event. It contains an array that holds the replacement strings stored in the event entry.
PS> $event.ReplacementStrings
Profiles
71
Logon
Based on that you could use array indexing to get the values you're after.
Get-EventLog application |
Where-Object {$_.EventID -eq 6006 -and $_.ReplacementStrings -eq 'Profiles'} |
Foreach-Object { $_.ReplacementStrings[1] }